RS485 listener getting wrong bytes

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(" ");
  }
}

Any chance you've swapped the A & B lines ?

What board are you using ?

Oh yes and.

And the !RE is also pulled LOW so you RX is enabled as well ?

Are you working with the chip or a breakout module with the chip on it?

Can you show your wiring.

Which Arduino are you using?

I assume that's a typo and you meant 9600.

Thank you for responding.
I am using the Feather M4 connected to an MC34050. I have verified the RX and TX lines (although TX is always disabled)

Interfaces via MC34050 chip directly on a breadboard. Feather M4 is processor.

Schematics follow

Yes, thank you

Isn't the Feather M4 a 3.3V device with 3.3V GPIO pins?

The MC34050 is a 5V device according to the datasheet. How are you powering the MC34050? Is it from the Feather 3.3V?

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.

Clutching at straws, does the behaviour change if you change the 'if' to a 'while'?

Dave;
Thanks for the input but the output is the same. Bummer.

We swapped the MC34050 driver receiver with a MAX1487CPA+. Exact same problem.

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.

Yes, RX is low. We just recently disabled the TX


```cpp
SERCOM5->USART.CTRLB.bit.TXEN = 0x0; // disable RS485 transmitter
just because we could.  No difference.

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.

The reason it happened is the RS485's polarity on the COTS PID is backwards. I was hoping i wasn't that idiotic. What a royal pain!

Thank you everyone for the help!

You're welcome !