//定时1ms
void TimerInit(void)
{
//(注:总线分频器大于1时TIM3时钟为总线时钟的两倍,也就是72MHz,祥情参考STM32参考手册7.2节)
LL_TIM_InitTypeDef TIM_InitStruct = {0};
//Peripheral clock enable
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
// TIM3 interrupt Init
NVIC_SetPriority(TIM3_IRQn,NVIC_EncodePriority(NVIC_GetPriorityGrouping(),PRIORITY_DEF,PRIORITY_SUB));
NVIC_EnableIRQ(TIM3_IRQn);
TIM_InitStruct.Prescaler = 72;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct.Autoreload = 1000;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
LL_TIM_Init(TIM3, &TIM_InitStruct);
LL_TIM_EnableARRPreload(TIM3);
LL_TIM_EnableCounter(TIM3);
LL_TIM_EnableIT_UPDATE(TIM3);
}
//中断函数
void TIM3_IRQHandler(void)
{
LL_TIM_ClearFlag_UPDATE(TIM3);
//....
}
|
|