AnsweredAssumed Answered

STM32F103C8T6 USART wrong data

Question asked by jamrozowicz.przemysl on Oct 23, 2016
Latest reply on Oct 23, 2016 by Clive One

Hello,
I have a problem with sending data from/to my STM32F103C8T6 using USART connection.
I'm using USB2TTL PL2303 converter.
I connected it to RX1 and TX1 on the board. I can send .hex files with STM Flash Loader Demonstrator and it works (like LED blink etc.).

This is how it looks like:
http://image.prntscr.com/image/0d03529e29c64d78b6c3fb08bbaf57f8.png

This is my code:

void startUsart(){

       RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

       RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

       RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

 

       GPIO_InitTypeDef GPIO_InitStructure;

 

       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

       GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

       GPIO_Init(GPIOA, &GPIO_InitStructure);

 

       GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

       GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

       GPIO_Init(GPIOA, &GPIO_InitStructure);

 

       USART_InitTypeDef uart;

       uart.USART_BaudRate = 115200;

       uart.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

       uart.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

       uart.USART_Parity = USART_Parity_No;

       uart.USART_StopBits = USART_StopBits_1;

       uart.USART_WordLength = USART_WordLength_8b;

       USART_Init(USART1, &uart);

       USART_Cmd(USART1, ENABLE);

}

void send_char(char c)

{

    while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

    USART_SendData(USART1, c);

}

int main(int argc, char* argv[])

{

       startUsart();

 

  while (1)

    {

         send_char('y');

         timer_sleep(2000);

         send_char('a');

         timer_sleep(2000);

    }

}

 

What I receive is:

http://image.prntscr.com/image/4c508ec85ff9476f99689ce8e1a5e062.png

I was looking for similar problem but couldn’t find any working solution.

I tried lower baudrate like 9600 but still not working.




Outcomes