贴代码
10us定时
void TIM6_INIT_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
TIM_TimeBaseStructure.TIM_Period = 9;
TIM_TimeBaseStructure.TIM_Prescaler = 47;
TIM_TimeBaseStructure.TIM_ClockDivision = 1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_ClearFlag(TIM6, TIM_FLAG_Update);
// TIM_ARRPreloadConfig(TIM3, DISABLE);
TIM_Cmd(TIM6, ENABLE);
TIM_ITConfig(TIM6,TIM_IT_Update, ENABLE);
}
中断代码
void TIM6_IRQHandler(void)
{
if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM6, TIM_IT_Update); //清除更新中断标志位
}
}
注意需要在stm32f0xx.h头文件里添加 TIM6_IRQn = 17
有了就不用添加
全局搜索TIM3_IRQHandler
在startup_stm32f030.s添加
DCD TIM6_IRQHandler ; TIM6
EXPORT TIM3_IRQHandler [WEAK]
EXPORT TIM6_IRQHandler [WEAK]