TL;DR: Attempting to connect UART2 on ESP32-WROOM to a physical PC RS232 results in odd behavior and ESP32 crashes or errors. Suspect electrical design problems. Wondering if I need special consideration for voltages or diodes to avoid feedback to GPIO connectors on ESP side.
Hello! I'm relatively new to the community. I'm attempting to build a tool that will interact with a video conference bridge on its serial port to do room automation (mute/unmute/answer/raise_blinds/dim_lights/etc). Since the bridge interface is serial, I want to have two usable RS232 ports. One to interact with the bridge and the other to act as a console for troubleshooting and configuration.
I've purchased several ESP32-WROOM kits and have a good portion of the rest of the tool built, but I'm now struggling with getting UART2 to talk to my physical serial port on my PC so I can troubleshoot the actual bridge interactions. I've built a test sketch that just sends "Hello!" every second or so to UART2 and echoes anything it receives on UART2 back to UART0. UART0 is set for 115200 and UART2 is set to 9600. I have changed this to match and it made no difference.
Configuration:
- UART0 is 115200,8N1 on standard USB console.
- UART2 is 9600,8N1 on default GPIO 17/18 (TX2/RX2).
- Pin17/18 and ground are wired to an 8 port single row header which is then plugged into a Teansic RJ45 breakout board.
- Using Arduino IDE serial monitor to observe. Shows as COM3 on my PC.
- UART2 is connected to a StarTech USB to RJ45 adapter made specifically for Cisco consoles (ICUSBROLLOVR) it shows as COM7 and I'm just using Putty to observe.
Sketch:
#include <HardwareSerial.h>
#define RXD2 16
#define TXD2 17
#define Serial0 Serial
#define Serial2 SerialPort
HardwareSerial Serial2(2);
void setup() {
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
Serial0.begin(115200);
}
void loop() {
while (Serial2.available()) {
Serial0.printf("[%012d] In: ", esp_timer_get_time());
//Serial0.print(char(Serial2.read()));
Serial0.print(Serial2.readStringUntil('\n'));
Serial0.print("\n");
}
while (Serial0.available()) {
Serial2.printf("\n[%012d] Insert: ", esp_timer_get_time());
//Serial0.print(char(Serial2.read()));
Serial2.print(Serial0.readStringUntil('\n'));
Serial2.print("\n");
}
Serial0.printf("[%012d] Out: ", esp_timer_get_time());
Serial0.print("Hello!\n");
Serial2.print("Hello!\n");
delay(1100);
}
Behaviors:
When I connect my PC up, it receive characters but they are (consistent) garbage of about the right number of characters. It looks like:
▒::
▒[▒::
▒[▒::
▒[▒::
▒[▒::
▒
I sometimes receive phantom characters in from the PC even though I'm not sending anything.
If I loop UART2 back on itself (connect TX to RX at my serial header) I get a perfect response back out UART0 as though the input was coming from the PC.
If I send data from the PC to UART2, it results in crashes/errors similar to the following. The error implies it is rebooting, but it is not:
rst:0x7 (TG0WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
[000000011533] Out: Hello!
[000001111758] In:
[000002111056] Out: Hello!
I've observed the electrical output with an oscilloscope and it casually looked like a good RS232 signal. I went so far as to convert my character string to little endian binary and add the start and stop bits and it looks exactly like it should to me except that I am expecting that 0 and 1 should be in the range of -3 to -10 and +3 to +10 and instead the pattern appears to be about +400mV for 1 and markbits and just above zero for a 0 (relative to ground).
I have found very little to reference for RS232 to an actual PC. Almost everything appears to be logic level connections ESP32 to ESP32 or peripheral board to ESP32.
I suspect that this is a case of needing circuitry to convert the logic level voltages to external RS232 +10/-10v ranges and perhaps diodes or something to prevent phantom feedback since TX/RX have a shared ground, but I'm flying blind. I'm hoping someone here has experience with this and can point me to an answer or better reference materials.