RS485 read/write
Posted: Sun Oct 15, 2023 8:24 pm
I have two ESP32 development boards connected using RS485 MAX serial transceivers. Following other threads in this forum, I configured one as a sender and one as a receiver. They seem to be communicating but the data is gibberish. I'm sending ints starting at 65 which should show up as ASCII 'A', but the output on the receiver side is garbage. The RS485 transceivers are powered from VIN (5V) on the ESP32, and on the receiver side DE and RE are also connected to ground (on the sender side, they are connected to GPIO4). On both, RO connects to RX2 (pin 16) and DI connects to TX2 (pin 17).
The transceivers are connected A-A and B-B with a jumper. I removed the termination resistors on the transceivers since with the resistors in place, I wasn't seeing anything.
I've tried switching to transmitting chars, strings, etc but same results.
Here's my sender:
And here's my receiver:
The transceivers are connected A-A and B-B with a jumper. I removed the termination resistors on the transceivers since with the resistors in place, I wasn't seeing anything.
I've tried switching to transmitting chars, strings, etc but same results.
Here's my sender:
Code: Select all
#include <HardwareSerial.h>
HardwareSerial Serial485Max(2);
#define S2RX 16
#define S2TX 17
#define S2ENA 4
#define SerialDataBits 9600
void setup()
{
Serial.begin(115200);
Serial485Max.begin(SerialDataBits, SERIAL_8N1, S2RX, S2TX);
pinMode(S2ENA, OUTPUT);
delay(100);
digitalWrite(S2ENA, HIGH);
}
void loop()
{
int i;
for (i=0; i<1000; i++) {
Serial485Max.print(i);
Serial.print(i);
Serial.print('.');
delay(100);
}
}
Code: Select all
#include <HardwareSerial.h>
HardwareSerial Serial485Max(2);
#define S2RX 16
#define S2TX 17
#define S2ENA 4
#define SerialDataBits 9600
void setup()
{
Serial.begin(115200);
Serial485Max.begin(SerialDataBits, SERIAL_8N1, S2RX, -1, true);
delay(500);
Serial.println("serial ready");
}
void loop()
{
int sb;
char oc;
while (Serial485Max.available()) {
oc = Serial485Max.read();
Serial.print(oc);
Serial.print('.');
}
}