测试代码如下
#define LED_TIM TIM1
void LedTim_Init(u16 arr, u16 psc, u16 ccp1)
{
TIM_OCInitTypeDef TIM_OCInitStructure = {0};
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure = {0};
NVIC_InitTypeDef NVIC_InitStructure = {0};
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIM_TimeBaseInitStructure.TIM_Period = arr;
TIM_TimeBaseInitStructure.TIM_Prescaler = psc;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(LED_TIM, &TIM_TimeBaseInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse = ccp1;
TIM_OC2Init(LED_TIM, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(LED_TIM,TIM_OCPreload_Disable);
TIM_ARRPreloadConfig(LED_TIM, ENABLE);
//TIM_ClearITPendingBit(MAXTRIXLED_TIM, TIM_IT_Update);
TIM_ClearITPendingBit(LED_TIM, TIM_IT_CC2);
TIM_ITConfig(LED_TIM, TIM_IT_CC2, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(LED_TIM,ENABLE);
}
void TIM1_CC_IRQHandler()
{
if(TIM_GetFlagStatus(LED_TIM, TIM_FLAG_CC2) != RESET)
{
TIM_ClearFlag(LED_TIM, TIM_FLAG_CC2);
}
}
调用:LedTim_Init(1000,4800-1,800);
芯片是CH32V307VCT6,设置144M主频,打断点中断函数只进入一次,之后就无法进入中断,但是查看寄存器有变化,看中断寄存器也没看出什么错误,定时值在跑。用的是高级定时器,请问是配置错了还是什么原因呢?功能只是需要比较一致重复中断。