cancel
Showing results for 
Search instead for 
Did you mean: 

TIM2 program using STM8S003F3

Ajit Thorabale
Associate II
Posted on February 19, 2017 at 03:48

Hi

I am facing problem in Timer2 programing. It does not go into the interrupt. Please find below program of Timer2 initialization. I am using STVD for programing STM8S003F3.

The Prescalar clock frequency is 16Mhz

    //Configuring TIM2 for 1 ms delay generation

    TIM2->PSCR =0x04;        //Deviding incoming clock by 16 Fck_cnt = Fck_psc/(2^PSC[3:0]);    

    TIM2->ARRH =0x03;       //ARR value with 1000

    TIM2->ARRL =0xE8;       

    TIM2->CR1 |= 0x80;      //Auto reload preload enabled

    TIM2->IER |=0x01;          //TIM2 Update Interrupt enabled

     TIM2->CR1 |= 0x01;      //ON timer

Interrupt routine as below in which PD6 is toggled on each interrrupt.

INTERRUPT_HANDLER(TIM2_UPD_OVF_BRK_IRQHandler, 13)

{

     GPIOD->ODR ^=0x40;

    TIM2->SR1 &= 0xfe; //*/

}

I am not getting what is wrong. Thanks in advance.

2 REPLIES 2
qwer.asdf
Senior
Posted on February 22, 2017 at 13:58

Have you enabled the interrupts?

Show me your interrupt table!

Ajit Thorabale
Associate II
Posted on February 23, 2017 at 01:36

Thanks qwer.asdf for reply.

I got the solution of TIM2 programing. It was not related to interrupt, the values were not moving properly to each register. Since address for TIM2 registers are product dependent.

In STM8s003f3 after CR1 register the two bytes are reserved so other TIM2 registers' address has offset of 2 bytes. After making changes to program now it is finely working.