This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

USARt transmission problem with stm8

Hello , I'm working on the stm8l microcontroller and trying to use its USART. I am getting a very peculiar problem. No matter what value I assign to the USART_DR register , it always takes the value 0xff even if I give char value or a int value. I am reading the DR register using the debugger of STVD. Is there a way to read TDR and RDR registers separately? My code is as follows:

# include "stm8l.h"
# include "stm8s.h"
unsigned int i = 0;
unsigned int val = 0;

strlen(const char *str)
{
        const char *s;
  for (s = str; *s; ++s);
        return (s - str);
}

void clockinit(void) //16MHz internal clock enable
{
        CLK_SWR = 0x01;
        CLK_ICKR = 0x00;
        CLK_ECKR = 0x00;
        CLK_DIVR = 0x00;
        CLK_PCKENR1 = 0xFF;
        CLK_PCKENR2 = 0xFF;
}

void usartinit(void)  //usart initialisation (115200 , 8bit , no parity , 1 stop bit
{
        char X;
        PC_DDR = 0x10;
        PC_CR1 = 0x10;
        PE_DDR = 0xff;
        PE_CR1 = 0xff;
        X = USART1_SR;
        X = USART1_DR;
        USART1_CR1 = 0x00;
        USART1_CR2 = 0x0C;
        USART1_CR3 = 0x0f;
        USART1_CR4 = 0x03;
        USART1_CR5 = 0x00;
        USART1_GTR = 0x00;
        USART1_PSCR = 0x00;
        USART1_BRR2 = 0x0A;
        USART1_BRR1 = 0x08;
}

void main()
{
        char *z = "HELLO";
        clockinit();
        usartinit();
        val = strlen(z);
        for (i = 0;i<val;i++)
        {
                USART1_DR = *z;
                while (USART1_SR_TXE == 0)
                {
                        z++;
                }
        }
}