0
\$\begingroup\$

What's the Goal?

Trying to get two esp32's to communicate over their UART lines using RS-232.

My initial inspiration and idea for the connections was based on https://esp32io.com/tutorials/esp32-rs232

Devices / Setups

I have two ESP 32 devices and I have connected them over their UARTs with basic dupont jumpers. Successful communication - no problem!

I have next taken the same esp32 devices and then instead I have inserted RS-422 to TTL adapters and communication continues to flow perfectly!

I've then done the same with RS-485 to TTL adapters and all is well also with communication flowing in both directions!

The Challenge

I have the same ESP32's but am now using rs232 adapters. There's no communication going whatsoever apart from what 'appears' to be line noise...garbled chars like "0xFE', etc.

Steps

I have validated and verified that the TTL to RS232 adapters actually work by connecting them with DB9 serial cables to a PC (instead of using a USB cable) and seeing the REPL on both of them with my IDE, Thonny.

Now, I then use one of the same good cables to connect the RS-232/TTL adapters and the esp32s (on GPIO 13 and 14) and connect them back to USB power. But there's still no communication.

In terms of the physical setup it looks like this:

Each esp32 connects to the RS-232 with TX->TX, RX->RX and shares GND w/the module. Each module is powered independently (also tried sharing the same rail) with 5V rails. I put 14 millamps of current to the modules - I thought maybe there was not enough current to them so I tried various values.

I believe I have enough power going to each of the max 3232 modules as it appears the data sheet says it needs somewhere between 3 to 5 volts and seems like up to 20 mA should be fine. Not really sure what to try next. Any thoughts?

Update w/TX->TX

To share an update, I set RX->RX and TX-TX from each esp32 to the RS-232 modules. That did not correct the problem. I then also removed the cable and just have a gender changer. That did not correct the problem.

enter image description here

Code Snippet

NOTE these are esp32 with PSIRAM, so since I am using usb I am rerouting the UART to UART2 to avoid GPIO pin conflicts:

(Just a simple send or receive where appropriate)

uart = machine.UART(2, baudrate=115200, tx=13, rx=14)
#Have tried all the major baud rates...

uart.write(f"{str(time.localtime())}\n")

OR

uart.readline()

Power

Why are modules powered separately, and from where? The reason I am using separate power supplies is the I measured only 1.2 V from the 5V/GND on each esp32. I thought it should give 5V but since I am also doubting everything, I wanted to ensure proper power to the modules. They are both either USB wall plugs that are connected to little USB C converter to red/black cables or wall plug w/barrel adapter/term block - again w/red/black cables plugged into the breadboard.

Everything else worked perfectly -- and honestly speaking -- there seems to be lots of different opinions on what the 5V pin is capable of.

Pic (hope it helps)

enter image description here

Final Solution

As kruemi succinctly mentioned a null modem cable was required. I thought the cable I had was that.

  • Esp32 TX (GPIOs remapped above) to TX of each module .
  • Connect each module to it's own USB 5V power supply.
  • Each module shares ground with attached esp32 only.

Final Picture

Final Picture

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Why are modules powered sepqrately, and from where? \$\endgroup\$
    – Justme
    Commented May 31 at 5:13
  • \$\begingroup\$ Troubleshooting this with an oscilloscope is easy. You just follow the signal for the Tx pin in one end and see where it gets lost along the way. Mixing up Tx and Rx is THE most common problem with UART by far. This follows Murphy's Law: one will always mix up Tx and Rx no matter how much thought you put into the schematics. Luckily it is easy enough to find the problem with your scope. \$\endgroup\$
    – Lundin
    Commented May 31 at 6:55
  • \$\begingroup\$ @Justme good question. Updated the post. \$\endgroup\$
    – jouell
    Commented May 31 at 14:21
  • \$\begingroup\$ @jouell Looks like you are just trying out random things. I should have asked this in the first place, but which exact module it is, from where you bought it (give a link), did you receive schematics or any other documentation how to use the module, or even something with pinouts with signal directions or how to power it? You can't expect to buy a random thing and connect it randomly everywhere until it either works or gets damaged or it damages something else. \$\endgroup\$
    – Justme
    Commented May 31 at 14:33
  • \$\begingroup\$ It sounds like the electronics you buy are neatly wrapped with perfect step by step instructions and schematics. Sometimes you have to experiment. Not every component ever made was perfectly labelled - sometimes they are wrong! And yes, sometimes you have to look the fool to learn! Vive learning! \$\endgroup\$
    – jouell
    Commented May 31 at 16:48

2 Answers 2

2
\$\begingroup\$

Short anwer:

Use a Null Modem Cable

Longer Anwer:

RS-232 is a point to point connection. It uses 2 lines (plus gnd). On the connector they are called TX (Transmitt) and RX (Receive). Originally, RS232 was used to connect teleprinter lines connected via modem over telephone lines (that's whay there are so many obscure additional lines in a fully fledged RS-232 vable) So what the Teleprinter sent over the Tx pin had to received by the Rx pin on the modem and vice versa. So you had a DTE (the Teleprinter) and a DCE (the modem). So by simply swapping the pins 2 and 3 (Tx and Rx) on the DCE you could use straight cables. This way it also cosed no problem if someone just daisy-chained several cables (no duble crossing)...

Now fast forward to people wanting to connect two DTE (teleprinter, computers whatever) together... You run into a problem that you now need a cable with the same connector on both ends... this can be solved by a simple gender changer (which you did). This solves the mechanical problem but still connects the two TX-Lines together (potentially working against each other but luckily, the RS-232 tranceivers are pretty robust) and the RX lines (basically leaving that line floating)...

So what you need is to connect Tx to Rx and RX to Tx on the RS-232 side. Easiest way is to use a Nullmodem Cable or a nullmodem gender changer.

\$\endgroup\$
2
\$\begingroup\$

Like mentioned in another answer, you have used a straight through cable with a gender changer, so RS232 TXD lines are shorted together and RS232 RXD lines too, so there can be no communication between modules. You need to cross over TXDs to RXDs between the DE-9 connectors.

Just having the DE-9 connectors wired incorrectly does not explain the garbled characters you are receiving, so there has to be more problems somewhere else.

You can almost never assume the pin naming which these modules use, so better double-check that MCU output goes to MAX3232 input for RS232 transmitter and MCU input comes from MAX3232 output of RS232 receiver. Best to have schematics or reverse-engineer the board connections.

Secondary problems are that you seem to have tried everything like increasing voltage to 5V, and increasing current, so it sounds like you have used a lab power supply and hit a current limit and increased it.

The problem is, each module should be powered from the respective MCU module with the respective MCU IO voltage level. It should not be powered separately, because you can't have either the MCU or MAX3232 powered and the other unpowered, as the you run into problems of back-feeding power through IO pins to the unpowered chip.

Also the ESP32 uses 3.3V IO voltage levels, and if you used 5V supply on the RS232 module, it will expect 5V from ESP32 but it might be within specs, the problem is the RS232 module outputs 5V level to ESP32 which it does not expect, and that's not good, The ESP32 input protection tries to clamp the voltage to safe limits and the MAX3232 tries to push out all the current it can to output the 5V.

Do not power the modules separately but from the same MCU module where the logic level signals go to.

Edit: Your random changes don't help getting it working. Do not power the modules from 5V unless you know there is a 3.3V regulator onboard. Do not power them separately. Power them with 3.3V from the MCU where the data connections go. Do not use the gender changer, it does not connect TXD to RXD in crossover as required from the connections, you need someting that swaps DE-9 pins 2 and 3 between modules, and pin 5 to 5 for ground.

\$\endgroup\$

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