定时中断的时候总是每次 update 进去两次中断,下面是初始化程序
//输入时钟 = 60M/16= 3.75M
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Period = 1875-1 ; //Autoreload value (32bit)
TIM_TimeBaseStructure.TIM_Prescaler = 2-1 ; //Prescaler value (16 bit )
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
// 中断频率 1K
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_ITConfig(TIM3, TIM_IT_Update , ENABLE);
/* TIM1 enable counter */
TIM_Cmd(TIM3, ENABLE);
/* Enable the TIM3 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//这里是中断程序
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update ) != RESET) //这个标志位确实是只置位一次,但是中断确实进来了两次,其中一次改标志位没有置位如果是别的标志位导致的按理不清也会不断进来,但是恰恰就只多进来一次
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update );
CTR_LED = led_stat ;
if( led_stat>0 ) led_stat =0 ;
else led_stat = 1 ;
}
}
|