Skip to main content
Visitor II
September 27, 2010
Question

timer interruptions on STM8L152C6

  • September 27, 2010
  • 7 replies
  • 975 views
Posted on September 27, 2010 at 13:02

timer interruptions on STM8L152C6

    This topic has been closed for replies.

    7 replies

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:10

    The problem I am having is when running the program TIM4_CNTR, the timer counter doesnot increment.

    Does anybody know what are the settings that should be applied to overcome this issue?

    Also when TIM4 register values are set using the following syntax they do not get assigned.

    TIM4_CR1 = 0x01;    // Start the timer

    Any body having idea on how t do that?

    Thank you.

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:10

    Hi ANN,

    Perhaps you should enable the TIM4 clock through clock register.

    You should use something like this:

    CLK_PeripheralClockConfig(CLK_Peripheral_TIM4, Enable);

    You can find a set of examples in the package provided by ST. I am finding useful as start point ''STM8l15x_StdPeriph_Lib''

    http://www.st.com/mcu/familiesdocs-120.html

    good luck.

    Regards,

    MCU Lüfter

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:10

    Hi again,

    In my understang of STM8L15x devices, to use timer with interrupt you should perform the following steps:

    1- Enable peripheral (USART, SPI, Timer...) clock using clock registers PCKENR

    2- Configure the timer and enable update (overflow) interrupt

    3- enable global interrupt (enableInterrupts() <----> rim: reset interrupt mask)

    4- enable timer counter: the counter starts counting at this moment

    5- in timer IRQ, update flag should be cleared

    I think that this is what you have to do.

    If there is some missed step thanks to remember me.

    good luck.

    MCU Lüfter

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:10

    Hello Lowpowermcu,

    Enable system clock on timer using clock registers PCKENR solved out all my troubles.

    thanks a lot.

    I did 1,2 and 4 from ur list.

    Am not aware of 3 and 5 of your list.

    Especially IRQ update flag, i could not find it.

    Any way thanks for the help provided.

    :D

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:10

    Hi ANN,

    3- enable global interrupt (enableInterrupts() <----> rim: reset interrupt mask) allows the CPU to ''see'' interrupts (It manages I0 and I1 bits in condition code register).

    You can find its description in Central Processing Unit chapter of reference manual (''sim'' and ''rim'' instructions):

    http://www.st.com/stonline/products/literature/pm/13590.pdf

    Regarding step 5 you need to clear update flag means resetting the flag:

    TIM2->SR1 = 0x00; //if you are using timer2

    TIM4->SR = 0x00; //if you are using timer 4;

    More details are available in the reference manual. Go to status register description.

    Good luck.

    regards,

    MCU Lüfter

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:10

    Hello,

    In order to achieve USART transmission functionality it is asked to ''Write the data to send in the USART_DR register''

    in the STM8L15x microcontroller family reference manual.

    Eventhough i have used the following form,

    USART1_DR =0x41; // ASCII 41 = A

    In the debugging mode what i have noted is that,

    data is not written into USART1_DR.

    Also I have performed the following settings as well.

    CLK_PCKENR1 = 0x20; //Enable SYSTEM clk to USART1

    MAP_CR1 = 0x00; //USART!CK remap on PC4; USART1_TX on PC3 and USART1_RX on PC2

       

        USART1_CR1 = 0x10; //Enable USART; 8 bit data

       

        USART1_CR3 = 0x08; //1 STOP bit; USART_CK enabled;

       

        //fSYSTEM = 16MHz; baud rate = 9600bps; USART_DIV = 1667 = 0683h

        USART1_BRR2 = 0x03;

        USART1_BRR1 = 0x68;

       

        USART1_CR2 = 0xCA; //txd enable; txd interrupt enabled

    Can some body tell me are there any more register configurations to be done?

    Thank you.

       

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:10

    Hello,

    In order to achieve USART transmission functionality it is asked to ''Write the data to send in the USART_DR register''

    in the STM8L15x microcontroller family reference manual.

    Eventhough i have used the following form,

    USART1_DR =0x41; // ASCII 41 = A

    In the debugging mode what i have noted is that,

    data is not written into USART1_DR.

    Also I have performed the following settings as well.

    CLK_PCKENR1 = 0x20; //Enable SYSTEM clk to USART1

    MAP_CR1 = 0x00; //USART!CK remap on PC4; USART1_TX on PC3 and USART1_RX on PC2

       

        USART1_CR1 = 0x10; //Enable USART; 8 bit data

       

        USART1_CR3 = 0x08; //1 STOP bit; USART_CK enabled;

       

        //fSYSTEM = 16MHz; baud rate = 9600bps; USART_DIV = 1667 = 0683h

        USART1_BRR2 = 0x03;

        USART1_BRR1 = 0x68;

       

        USART1_CR2 = 0xCA; //txd enable; txd interrupt enabled

    Can some body tell me are there any more register configurations to be done?

    Thank you.