I am sending a known short stream of characters over RS485 from a host (PC) to a slave device (Love/Dwyer 32A PID). This system works correctly and i have verified the bit stream using a scope. I am using a MC34050 transceiver and have verified this works with other devices.
The protocol is 8N1 running at 9800 baud. The transceiver has the TXEN tied low (disabled) as i want it to listen only.
When i send the HEX stream 02 4C 33 32 30 30 C5 03
I get the response of 02 4C 33 32 4E 30 35 06 from the LOVE PID. This is OK.
However, on the Arduino listener i get BF B6 95 F3 . I've botched something, probably obvious.
Here is the code (stripped to almost nothing)
```cpp
#include <HardwareSerial.h>
// Define the control pin for RS485 mode
#define RS485_CONTROL_PIN 10
int counter = 0;
void setup() {
// Initialize the serial monitor
Serial.begin(115200);
delay(2000); // Necessary delay to allow Serial to stabilize
// Set up the RS485 control pin
pinMode(RS485_CONTROL_PIN, OUTPUT);
digitalWrite(RS485_CONTROL_PIN, LOW); // Always in receive mode
// Initialize the RS485 bus
Serial1.begin(9600, SERIAL_8N1); // Adjust baud rate as needed
}
void loop() {
// Listen for data on the RS485 bus
if (Serial1.available() > 0) {
// Read a byte from RS485
byte receivedByte = Serial1.read();
// Print the received byte as hexadecimal
// Serial.print("Received: 0x");
if (counter > 20) {
counter = 0;
Serial.println("");
}
counter++;
if (receivedByte < 0x10) Serial.print("0xxx"); // Add leading zero for clarity
Serial.print(receivedByte, HEX);
// Serial.print(" ");
// Serial.print( (receivedByte & 0x1F ), HEX); // check to see if there is a pattern to match the expected value using bitwise and - DOESN'T WORK
Serial.print(" ");
}
}
FYI:
When i send the following Hex string on Coolterm:
00112233445566778899AABBCCDDEEFF
The Feather M4 monitor receives:
DDBB997733113314
Notice the pattern shift and the number of bytes is reduced by half. It looks like the buffer is flipping the order and dropping half the bytes except that the end it starts going back up, so that is not the case. This is so frustrating and it has to be something stupid because i've used this config before for other talk/listen applications.
Good catch, but we figured that out and put a voltage divider (10k/30k) on the pins so the signal is peaks around 3V. Just to be safe, we swapped out the feather M4 but alas, no change.
The lines on the RS485 are not called TX & RX where you marked them.
Those are A & B aka D+ & D-
The polarity on these lines defines if the RX pin on the other side is LOW or HIGH.
Shortened response, and seemingly more 1 than 0 bits where in the original more 0 than 1 bits are present, (the bit order would obviously not the same, since the start and stop bits also get inverted, which will influence what is recognized as a byte) indicates that these lines may be swapped over, inverting the logic.
For 9600bps that should be ok, but for higher speed i recommend lower value resistors.
Regardless, Please post a complet schematic, include the power lines and the voltage divider.
Attached please find full schematics with the assumed stuff included. While we've verified the directions of match what is on the two devices on the bus, i am switching them now. YOU NAILED IT. THANK YOU!!!!
We are running 9600 baud and the digital signal edges are satisfactorily square with no steps.