8 years, 9 months ago.

Wrong characters from serial

Hi, I will connect my STM32 with PC via RS-232. I have this simple code:

Serial

#include "mbed.h"
DigitalOut dir(PA_8);

Serial pc(PA_2, PA_3);

void serial_int(void)
{
    pc.putc(pc.getc());
}

int main() {
  pc.printf("Hello World !\n");
  pc.attach(&serial_int);
  dir = 0;
  while(1) { 
        wait(1);
        dir = 1;
        wait(1.0);
        dir = 0;
  }
}

Problem is that, when i put for example "a" character on PC terminal, I recive "aa" or "ay" or "aá˙" or something else. This is this same with all of the characters. First letter is ok, but it is not only one character. Do you know what could be the reason of that?

2 Answers

8 years, 9 months ago.

check if your serial port baud rate on the micro controller matches with the baud rate on the PC.

https://developer.mbed.org/handbook/SerialPC

I checked, and is this same baud rate. I checked also another baud rate (38000, 115200) and is this same problem.

posted by Paweł Jabłoński 27 Jul 2015

How about the stop bits and parity?

posted by Kevin Braun 27 Jul 2015
8 years, 9 months ago.

Is the first message 'Hello World' coming through correctly? In that case the baudrate settings and start/stop should be Ok. Always start at low baudrates like 9600. You dont set the baudrate in your code so it defaults to 9600,8,1 on the mbed side. The first character of the two you see in your pc terminal is probably the local echo of the character you type in. The second character must be what you receive back from the mbed. You said you use RS232 to the PC. How is the pc connected to the mbed. Do you have an RS232 level converter? Do you have a good common gnd between the pc and the mbed?