Electronic – Why can’t I successfully send messages over RS232


So the past week I have been working on getting UART messages sent from a STM32F407 and reading it on my laptop through a ugreen RS232 to USB cable using termite.

I have used STMCube to generate code and add to it by reading the relevant instructions at the top of the "stm32f4xx_hal_uart.c" file (and watching plenty of videos and reading online).

I have checked the transmitted message on an oscilloscope and it matches its ASCII representation.

For example I send 'Q' which is 0101 0001, I receive 'W' which is 0101 0111. The reading on the scope shows:

enter image description here

Termite output for the same signal as displayed on the oscilloscope.
enter image description here

I have confirmed baud rates/parity/HWcontrol are matching on termite and in my code.

To receive correct character I have tried lowering and increasing baud rates.
I've tried different character sets to try to find a pattern which causes wrong characters to be displayed.
Additionally I have tried different terminal such as on Putty or Teraterm.

Best Answer

You have missed a major detail of RS232. Logic levels are as follows:

enter image description here

Figure 1. RS232 signal levels. Source: Wikimedia Commons.

  • Logic 1 = -3 to -12 V.
  • Logic 0 = +3 to +12 V.
  • Between -3 and +3 the logic level is undefined.
  • The RS232 start bit is a logic 0.

To convert from TTL (5 V) logic to RS232 a driver is required. Chips such as the MAX232 do the logic level inversion and voltage boost for you.

It is possible to "cheat" sometimes and feed a TTL signal into an RS232 input provided the logic level is inverted. The reliability of this method depends on the chip used on the RS232 input.

enter image description here

Figure 2. The transmitted waveform. On top is the bit pattern of the'Q' that you transmitted. On the bottom is how the RS232 input read it.

Note that the RS232 input is looking for a positive edge to indicate the start bit. This doesn't happen until the second bit of your data so everything thereafter is one bit to the right and inverted as the receiver sees it. As luck has it your MSB is the correct logic level for the stop bit so the receiver interpreted it as a valid frame, decoded it and displayed a 'W'.

For test purposes you can invert your TTL output. This will probably work as it is "working" at the moment.

enter image description here

Figure 3. The MAX232 chip uses capacitors in charge pump circuits to boost the 5 V supply for RS232 levels.

For reliability add a MAX232 chip to transmit and receive a proper RS232 level signal.