ESP32 RS232 Communication

I want to send data over RS232 to another device. I got HW-044 module which has MAX3232 for converting UART signal to sonething that RS232 devices can understand.

I have connected RX and TX to pins 16 and 17 on my ESP32. I tried using ports Serial1 and Serial2 to send data, but I get nothing on my device. I already tested this same example with Arduino Mega and it works.

Maybe there's some extra steps for ESP32 that I have to define in software in order to send data over RS232? Baudrate, stop bits, and everything else is set correctly, like i said before everything works on Arduino mega.

Also, i searched the forum before posting and I didn't find any solution

@iphatbass it will help greatly if you post the code you have tried

I wanted to, but i guess it's not important because it's the most basic code for this xD Nothing special in setup, serial1.begin, in loop serial.write to send data. It's the most barebone code just to test it. I will send you exact code tomorrow, when I'm near computer, but it won't be much larger than this. Like i said before it, it's just initializing Serial and then sending data and it already works on Arduino mega

try the following code

// ESP32  Serial1 test - for loopback test connect pins RXD1 and TXD1

#define RXD1 16 // can map Serial1 and Serial2 to many ESP32 GPIO pins
#define TXD1 17 // check pin usage https://randomnerdtutorials.com/esp32-pinout-reference-gpios/

// for RS232 shield connect
// ESP32 RXD1 to TTL/RS232 Rx
// ESP32 TXD1 to TTL/RS232 Tx
// connect GND pins together and VCC to 3.3V on ESP32 5V on UNO ect
// for loopback test connect 9-pin D_type connector pins 2 Tx to 3 Rx (pin 5 is GND)

void setup() {
  // initialize both serial ports:
  Serial.begin(115200);
  Serial1.begin(115200, SERIAL_8N1, RXD1, TXD1);
  Serial.printf("\n\nESP32 serial1  test RXD1 pin %d TXD1 pin %d\n", RXD1, TXD1);
  Serial.printf(" loopback test connect pin %d to pin %d\n", RXD1, TXD1);
  Serial.printf("RS232: ESP32 pin %d RXD1 to TTL/RS232 Rx and pin %d TXD1 to TTL/RS232 Tx\n", RXD1, TXD1);
  Serial.printf("RS232 - loopback connect 9-pin D-type pin 2 Tx to pin 3 Rx\n");
}

void loop() {
  // read from Serial1, send to Serial
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }
  // read from Serial, send to Serial1
  if (Serial.available()) {
    int inByte = Serial.read();
    //Serial.write(inByte);     // local echo if required
    Serial1.write(inByte);
  }
}

connect pin 16 to pin 17 to form a loopback - text entered on keyboard is echoed back to display
if that works connect the TTL-RS232 module
connect pins 2 and 3 of the D-type connecter to form a loopback
if it works connect to your target system

Error was on my side. I connected power of my RS232 converter module to 5V instead of 3.3V, so it was sending signals on wrong voltage. After a years of working with 5V i forgot that this little beast requires 3.3V

No it does not.
It can operate with 3.3V or 5V.
Of course 5V will damage the ESP

Those are the default pins for Serial2. It should just work. Using Serial1 probably just crashes the ESP32.

It does depend a bit on the exact module you have ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.