測試代碼如下
#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);
? ? }
}
調(diào)用:LedTim_Init(1000,4800-1,800);
芯片是CH32V307VCT6,設(shè)置144M主頻,打斷點中斷函數(shù)只進入一次,之后就無法進入中斷,但是查看寄存器有變化,看中斷寄存器也沒看出什么錯誤,定時值在跑。用的是高級定時器,請問是配置錯了還是什么原因呢?功能只是需要比較一致重復(fù)中斷。