用
STM32F030CC
芯片做
tiM3的定时中断时,中断处理服务函数无法进去,在定时器配置上不知道有没有遗漏的地方。芯片系统时钟是48M,TIM3 500ms进一次中断,中断处理函数是对LED灯进行翻转。下面是我的TIM3初始化,和中断处理函数,大家方便的时候还望帮我看一看,打扰了
void TIM3_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, ENABLE); //tim3时钟使能,APB时钟48M
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; //分频系数为1
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数
TIM_TimeBaseInitStructure.TIM_Period = 499;
TIM_TimeBaseInitStructure.TIM_Prescaler = 47999; //定时500ms
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStructure);
TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE); //允许定时器3更新中断
TIM_Cmd(TIM3,ENABLE); //使能定时器3
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //定时器3中断
NVIC_InitStructure.NVIC_IRQChannelPriority = 0; //优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update) != RESET) //溢出中断
{
LED2_Turn();
}
TIM_ClearITPendingBit(TIM3,TIM_IT_Update); //清除中断标志位
}
应该使用:RCC_APB1PeriphClockCmd 函数。
一周热门 更多>