RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
TIM2->ARR = 1200;
TIM2->CCR1 = 6000;
TIM2->CCR2 = 6000;
TIM2->CCR3 = 6000;
TIM2->CCR4 = 6000;
TIM2->DIER = TIM_DIER_CC1IE;
TIM2->SR = 0x0000;
TIM2->CR1 = TIM_CR1_UDIS | TIM_CR1_ARPE | TIM_CR1_CEN;;
NVIC_ClearPendingIRQ(TIM2_IRQn);
NVIC_SetPriority(TIM2_IRQn,3);
NVIC_EnableIRQ(TIM2_IRQn);
中断函数
void TIM2_IRQHandler(void)
{
GPIOB->ODR ^= 1ul << 9;
TIM2->SR = 0x0000;
}
定时器配置如上,本意是4个通道比较匹配后中断,但是折腾了几天,如上的设置,仍然会中断,中断里让IO取反,用示波器看IO,会有1US的高电平,间隔50US。请大家帮帮小弟,单片机STM32F100C8T6,开发环境是MDK4.72。
此帖出自
小平头技术问答
一周热门 更多>