cancel
Showing results for 
Search instead for 
Did you mean: 

STM32W timer problem

marcobonino.919
Associate
Posted on April 02, 2013 at 11:30

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; 
TIM_DeInit(TIM2); 
TIM_TimeBaseStructInit(&timer_2); 
timer_2.TIM_CounterMode=TIM_CounterMode_Down; 
timer_2.TIM_Prescaler = 13; 
timer_2.TIM_Period=1465; 
TIM_TimeBaseInit(TIM2,&timer_2); 
TIM_ITConfig(TIM2_IT,TIM_IT_Update,ENABLE); 
TIM_Cmd(TIM2, ENABLE); 
return; 
} 
void Interrupt_Configuration() 
{ 
NVIC_InitTypeDef timer_2_irq; 
timer_2_irq.NVIC_IRQChannel=TIM2_IRQn; 
timer_2_irq.NVIC_IRQChannelCmd=ENABLE; 
NVIC_Init(&timer_2_irq); 
return; 
} 

Here the interrupt function:

void TIM2_IRQHandler () 
{ 
STM_EVAL_LEDToggle(LED1);
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 itdoesn't clear all ISR registerbits (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 () 
{ 
STM_EVAL_LEDToggle(LED1); 
TIM2_IT->ISR = 0x1f; 
}

I have 2 questions:

1)Why do I have to write1s to get0s in the register? 2) Is this the best way to do it, oram I missing something in the configuration of timer and interrupts? Thank you and regards.
1 REPLY 1
hussainahmad
Associate
Posted on February 20, 2014 at 07:21

hello every one

i m new to stm32& stm32wc-rfckit,  & need a simple possible code for led blinking.