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.

  • 8
    \$\begingroup\$ Does your "RS232 to USB cable" work with RS232 voltage levels or "TTL" voltage levels, and is your STM32F407 board using he appropriate driver/receiver for those levels? I'm almost certain the answer to question 2 is "No", because if I interpret your scope trace through a "wrong levels & polarity" filter I see a "W" too. In all likelihood your board has no driver/receiver hardware (so uses TTL levels) and your "RS232 to USB cable" has RS232 driver/receiver hardware (so uses RS232 levels). \$\endgroup\$ – brhans Sep 20 '18 at 16:57
  • 3
    \$\begingroup\$ Trying some different characters would confirm @brhans hypothesis instantly. Sending the same character over and over again while expecting a different result is one of the definitions of insanity... \$\endgroup\$ – Dave Tweed Sep 20 '18 at 17:04
  • 3
    \$\begingroup\$ FeraTaTa - Just one point which I don't think has been mentioned so far: At first glance, your scope trace shows a signal which seems to idle at 0V (look at the 1 symbol with the yellow background on the left of the trace - that's the 0V level) and then pulses below 0V. That wouldn't be true for a logic signal straight from an STM32 and, indeed, it isn't true. Looking in the bottom left corner, you have set channel 1 to AC coupling (that's the ~ symbol you see there). The signal is really idling high and pulsing to around 0V. Use DC coupling for a sane view of that signal. \$\endgroup\$ – SamGibson Sep 20 '18 at 20:53

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.

  • 3
    \$\begingroup\$ As perhaps a better alternative, there are USB to TTL UART cables available. If the OP is using a USB adapter anyway, there's not so much point adding an extra chip for level-shifting. \$\endgroup\$ – Graham Sep 20 '18 at 21:36
  • 1
    \$\begingroup\$ RS-232 is a logic 0 =bipolar V+ which is anything >2V and a TTL equiv threshold of 1.5V typ. in CMOS like 74HCTxx with small hysteresis (50mV??) \$\endgroup\$ – Tony Stewart EE75 Sep 20 '18 at 21:49
  • 6
    \$\begingroup\$ In English, please, Tony? \$\endgroup\$ – Transistor Sep 20 '18 at 21:55
  • 3
    \$\begingroup\$ That is English to EE's, which part do you not understand? RS232 is -V on idle and >+2V on start but is negative logic to voltage (0=V+,1=V-) for data and stops on V-. I bet you did not know RS-232 threshold is 1.4~1.5V \$\endgroup\$ – Tony Stewart EE75 Sep 21 '18 at 1:07
  • 8
    \$\begingroup\$ Thanks, Tony. That's much more readable and sensible. You leave out punctuation, key words and conjuctives on too many of your quick-fire replies. I'm an old-boy like you with almost four decades of EE. My Figure 1 shows the threshold voltages for RX. See also Omega, Analog, Wikipedia and Maxim. All state ±5 V for TX and ±3 V for RX. \$\endgroup\$ – Transistor Sep 21 '18 at 1:55

Considering the short haul and low bit rate of 9600, TTL and CMOS levels work fine. The problem eloquently detailed by @Transistor is that UART data is negative logic 0~5V and RS-232 is positive logic +/-V f between +/-3 and +/-15V (?)

Therefore as *he also suggests, an inverter will work.

The problem is not a bit error rate (BER) issue or signal integrity, but inverted logic.

Also, the "grey zone" is for long-haul noise margin It is not <+/-3V for you because your cable is short. The actual logic threshold of RS-232 Rx is exactly the same as old TTL ( two Vbe drops) or 1.4V +/-20%(?) tolerance.

They call it a grey zone in order to meet all the distance and baud rate specs due to noise glitches and edge ringing.

For longer cables get any MAX232. Variations may depend on voltage speed and features.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.