Just looked at the STM32 General Timer tutorial, in fact, and 51 of the timer use almost. Just because the 32 clock is more complex and can manipulate more registers, it can be more complex to write.
General steps to use general timer interrupts:
1. Enable Timer clock
This needs to look at the clock tree, so that the corresponding clock will be good. I'm using TIM3 here, so I can APB1 the clock.
2. Set the frequency divider and reload value of the timer
Timer Interrupt Time: Tout = (arr+1)/[tclk/(psc+1)]
In fact, this timer interrupt time is still to be specific analysis, here is so, other places may not be, specific or refer to the "STM32 reference manual".
3. Enable Timer interrupt
4. Start Timer
5, timer interrupt initialization, set its interrupt priority, grouping and so on
6. Write Interrupt Service function
Here is the corresponding code
//Initialize TimervoidTimer_init (U16 psc,u16 arr) {RCC->apb1enr =1<<1;//Enable timer clockTIM3->PSC = PSC;//setting the Prescaler factorTim3->arr = ARR;//Setting the Reload valueTim3->dier |=1<<0;//Enable timer interruptTIM3->CR1 |=1<<0;//Start TimerMy_nvic_init (1,3, TIM3_IRQN,2);//Timer Interrupt Initialization}//Interrupt Service FunctionvoidTim3_irqhandler () {if(tim3->sr&0x0001) LED0 = ~LED0; TIM3->SR &= ~ (1<<0);//Clear Interrupt Flag}
STM32 Universal timer for LED flashing