AnsweredAssumed Answered

STM32W timer problem

Question asked by bonino.marco on Apr 2, 2013
Latest reply on Feb 20, 2014 by ahmad.hussain
Good morning,

I have a STM32W rfckit 950 REV-A.
I' m using the STM32W108xx_SimpleMAC_V2.0.1 library.

I' d like to use a timer to switch a LED with a frequency of 1 Hz.
I' m using an interrupt service routine which should start at the timer update event.
This is my configuration:




void Timer2_Configuration()
 TIM_TimeBaseInitTypeDef timer_2;    
 timer_2.TIM_Prescaler = 13;
        TIM_Cmd(TIM2, ENABLE);   
void Interrupt_Configuration()
 NVIC_InitTypeDef timer_2_irq;       

Here the interrupt function:

void TIM2_IRQHandler ()
     TIM_ClearITPendingBit(TIM2_IT,TIM_IT_Update);   // not work

I noticed that, as soon as the timer gets to 0, many of the pending interrupt register bits are set (I was expecting only the UIF).
Then, the function TIM_ClearITPendingBit doesn't work properly because it doesn't clear all ISR register bits (it clears just one at a time, while the others get set at each function call).

I found this turnaround is currently working:

void TIM2_IRQHandler ()
    TIM2_IT->ISR = 0x1f;

I have 2 questions:

1) Why do I have to write 1s to get 0s in the register?

2) Is this the best way to do it, or am I missing something in the configuration of timer and interrupts?

Thank you and regards.