TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM13,ENABLE); //TIM13时钟使能
TIM_TimeBaseStructure.TIM_Prescaler=psc; //定时器分频
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseStructure.TIM_Period=arr; //自动重装载值
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM13,&TIM_TimeBaseStructure);//初始化定时器5
TIM_ITConfig(TIM13,TIM_IT_Update,ENABLE); //允许定时器3更新中断
TIM_Cmd(TIM13, ENABLE); //使能TIM13
NVIC_InitStructure.NVIC_IRQChannel=TIM8_UP_TIM13_IRQn; //定时器3中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x01; //抢占优先级1
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x02; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
//定时器13中断服务函数
void TIM8_UP_TIM13_IRQHandler(void)
{
if(TIM_GetITStatus(TIM13,TIM_IT_Update)==SET) //溢出中断
{
// TIM_ClearITPendingBit(TIM13,TIM_IT_Update); //清除中断标志位
// GPIO_ResetBits(GPIOB,GPIO_Pin_0);
// delay_ms(10);
// GPIO_SetBits(GPIOB,GPIO_Pin_0);
// delay_ms(10);
}
}
中断一直进不去,同样的代码,配置TIM4中断都是OK的,请大佬帮忙看看 |