TIMER 3 Interrupt
Hi all,
This is a question regarding STM32F0 TIM3.
I have written this code in keil compiler
/***** main.c*****/
&sharpinclude<stm32f0xx.h>
&sharpinclude<stm32f030x8.h>void GPIO_Init(void); void TIM3_Init(void);int main()
{ GPIO_Init(); // Intializing PA5 TIM3_Init(); while(1) {}
}void GPIO_Init()
{ // Enable clock for GPIOA RCC->AHBENR |= (1<<17); //Configuration of PA5 GPIOA->MODER |= (1<<10); // PA5 as general purpose output mode GPIOA->OTYPER &= ~(1<<5); // PA5 as output push pull GPIOA->OSPEEDR |= ((1<<10)|(1<<11)); // PA5 at high speed GPIOA->PUPDR &= ~((1<<10)|(1<<11)); // PA5 as no pull-up, pull-down GPIOA->ODR = 0; // PA5 as Output Low}void TIM3_Init()
{ RCC->APB1ENR |= (1<<1); // Enable clock for TIM3 TIM3->PSC = 999; // Int clk divided by 1000(999+1) TIM3->ARR = 7999; // Counts from 0 to 7999 TIM3->DIER = 1; // Update interrupt enable __NVIC_SetPriority(TIM3_IRQn, 0); // Set TIM3 interrupt vector priority to 0 __NVIC_EnableIRQ(TIM3_IRQn); // Enable TIM3 interrupt vector TIM3->CR1 = 1; // Enable TIM3 counter }void ISR()
{ TIM3->SR = 0; GPIOA->ODR ^= (1<<5); // Toggle PA5 Output}/**** it.c*****/
void ISR(void);
void TIM3_IRQHandler(void){ ISR();}Here system clock freq and timer clock freq is 8Mhz(internal oscillator).
when I run this code I found that my led on PA5 toggles per second that should be as per code.
But there is an problem in output that when microcontroller is done reset by a reset button the PA5 Is immediately high and then toggles @ per second i.e. the tim3 generate a update interrupt when it is enabled. I want that first interrupt should come after timer completion means 1 sec. so that when I reset the microcontroller output can be at low and after 1 sec it toggles( goes high) and so on.
'My question is why microcontroller is making High to the UIF bit TIM3->SR reg. when TIM3 counting is enabled. I think it should be after timer completion'.
Waclawek.Jan
‌ELMHIRI.Syrine
‌null