我用stm32的ETR功能对外部脉冲计数,达到设定值时产生溢出中断,但只能进入中断一次,后面就无法进入,但外部脉冲数达到设定值时同样会清0.初始化如下,请有经验的朋友帮忙看一下
TIM_DeInit(TIM1);
TIM_TimeBaseStructure.TIM_Period = 500;
TIM_TimeBaseStructure.TIM_Prescaler =0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;//TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit( TIM1, &TIM_TimeBaseStructure );
TIM_ETRClockMode2Config(TIM1, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0);
TIM_SetCounter(TIM1, 0);
TIM_ClearFlag( TIM1, TIM_FLAG_Update );
TIM_ITConfig( TIM1,TIM_IT_Update,ENABLE );//TIM_ITConfig( TIM1,TIM_IT_Update|TIM_IT_CC1,ENABLE );
TIM_Cmd( TIM1,ENABLE );
void TIM1_UP_IRQHandler(void)
{
//TIM_ClearITPendingBit(TIM1, TIM_IT_Update);
TIM_ClearFlag( TIM1, TIM_FLAG_Update );
#ifdef __debug
printf("tim1 cnt:%d arr:%d\r\n",TIM1->CNT,TIM1->ARR);
#endif
} |