我用的是STM32F030C8
发现定时器进不了中断,查找原因未果,在此求教!
下面的我的代码:
定时器配置:
[mw_shl_code=c,true]void Tim3_Config(uint32_t period, uint16_t PrescalerValue)
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* TIM3 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
/* Enable the TIM3 global Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Time base configuration */
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Period = period;
TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter = period;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_ClearFlag(TIM3, TIM_FLAG_Update);
/* TIM IT enable */
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
/* TIM enable counter */
TIM_Cmd(TIM3, ENABLE);
}
[/mw_shl_code]
中断函数:
[mw_shl_code=c,true]void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update );
printf("timer interrupt!
");
}
}[/mw_shl_code]
使用的库是STM32F0xx_StdPeriph_Lib_V1.5.0
startup_stm32f030.s中关于中断的定义有
TIM3_IRQHandler,如下:
[mw_shl_code=c,true]
[/mw_shl_code]
[mw_shl_code=c,true]工程编译正常,下载正常,串口正常,但是就是进不了定时器中断(串口收不到中断中的字符串),请问问题出在哪?谢谢![/mw_shl_code]
一周热门 更多>