cancel
Showing results for 
Search instead for 
Did you mean: 

STM8L Timer Initiation problem

TXu.2
Associate

Hello,

I am new to ST processors. Here is the issue:

I am trying to setup Timer 3 for interrupt, Code:

TIM3_DeInit();

CLK_PeripheralClockConfig(CLK_PCKENR1_TIM3, ENABLE);

TIM3_TimeBaseInit(TIM3_Prescaler_64, TIM3_CounterMode_Down, 2500);

  

  TIM3_SetCounter(0);

  

  TIM3_ARRPreloadConfig(ENABLE); 

  

  

  TIM3_PrescalerConfig(TIM3_Prescaler_64,TIM3_PSCReloadMode_Update);

  

  TIM3_ITConfig(TIM3_IT_Update,ENABLE);

TIM3_Cmd(ENABLE); 

The funny thing is that the call "CLK_PeripheralClockConfig(CLK_PCKENR1_TIM3, ENABLE);" does not turn the Timer 3 gate on. As a matter of fact it turns on gate for Timer 4.

I had to use "CLK_PCKENR1_TIM2" to turn on the gate for Timer 3.

I traced to the function and fund this line inside "CLK_PeripheralClockConfig" (stm8l15x_clk.c)

" CLK->PCKENR1 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F)); "

The shift "1 <<" operation will always enable the gate for the device next in line!

That is why I have to use CLK_PCKENR1_TIM2 to turn on the gate for Timer 3. Based on this there is no way to make TImer 2 work by calling this function.

Am I right?

Thanks.

Tony

1 REPLY 1
TXu.2
Associate

Please ignore my last post.

I found the problem is that when "CLK_PeripheralClockConfig(CLK_PCKENR1_TIM3, ENABLE);" is called the "CLK_PCKENR1_TIM3" gets changed to "CLK_PCKENR1_TIM4" inside the function.

It is very strange and did "rebuild all" and problem still persists. I checked another instance of this function and no problem there.

I'll see if rewrite/retype the section helps.

Tony