void MSI_Calibration_Init()
{
/*配置TIM11,测量MSI*/
TIM_ICInitTypeDef TIM_ICInitStructure;
/* TIM11 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, ENABLE);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;//使用频道一
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;//捕捉上升沿
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;//每个边沿记一次数
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_ICInit(TIM11, &TIM_ICInitStructure);
/*Configures the TIM11 External Trigger (ETR)*/
TIM_ETRClockMode2Config(TIM11,TIM_ExtTRGPSC_OFF,TIM_ExtTRGPolarity_NonInverted,0);
/*Configures the TIM11 Remapping input Capabilities.*/
TIM_RemapConfig(TIM11,TIM11_MSI);
/* TIM enable counter */
TIM_Cmd(TIM11, ENABLE);
/* Enable the CC1 Interrupt Request */
TIM_ITConfig(TIM11, TIM_IT_CC1, ENABLE);//TIM11/TIM10只能使用TIM_IT_CC1
}
void TIM11_IRQHandler(void)
{
if (TIM_GetITStatus(TIM11, TIM_IT_CC1) != RESET)
{
/* Clear TIM11 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM11, TIM_IT_CC1);
TIM11Freq=TIM_GetCapture1(TIM11);
}
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, DISABLE);
TIM11->SR = 0x0000;
}
这样初始化以后,只能进入一次中断 并且TIMx_CCR1寄存器里面读不到数据 |