RS485 communication in between in two Arduino problem.

Hi All,

I have facing a curious problems between RS485 communication of two Arduino. To easy explain, I named two Arduino as No1 & No2 at below:

when No1 send hex “0x31” to No2, No2 received is “1”.
when No1 send hex “0x32” to No2, No2 received is “2”.

Above is fine and normal, when No1 send from 0x30 to 0x39 to No2, No2 will receive exactly same data from No1.

But when No1 try send 0x40 and forward, the data from No2 received is diffrent, for example:

when No1 send hex “0x40” to No2, No2 receive is “0”. By right should be “A”
when No1 send hex “0x41” to No2, No2 receive is “1”. By right should be “B”
when No1 send hex “0x42” to No2, No2 receive is “2”. By right should be “C”

I have attached my code at below. Hope someone can help. Thank you very much

No 1 arduino program

#include <SoftwareSerial.h>
//-----( Declare Constants and Pin Numbers )-----
#define SSerialRX       7
#define SSerialTX        6
#define SSerialTxControl 5
#define RS485Transmit  LOW
#define RS485Receive   HIGH
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX


void setup() {
  //*****************************RS485 Configuration*****************************************
  pinMode(SSerialTxControl, OUTPUT);   
  digitalWrite(SSerialTxControl, RS485Receive);  // Init Transceiver  
  RS485Serial.begin(9600);
  Serial.begin(9600);
  digitalWrite(SSerialTxControl, RS485Receive);  // Disable RS485 Transmit 
}

void loop() {


digitalWrite(SSerialTxControl, RS485Transmit);  // Enable RS485 Transmit
RS485Serial.write(64); //@         
digitalWrite(SSerialTxControl, RS485Receive);       // Disable RS485 Transmit
delay(1000);


}

No 2 arduino program

#include <SoftwareSerial.h>
//-----( Declare Constants and Pin Numbers )-----
#define SSerialRX       7
#define SSerialTX        6
#define SSerialTxControl 5
#define RS485Transmit  LOW
#define RS485Receive   HIGH
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX


void setup() {
  //*****************************RS485 Configuration*****************************************
  pinMode(SSerialTxControl, OUTPUT);   
  digitalWrite(SSerialTxControl, RS485Receive);  // Init Transceiver  
  RS485Serial.begin(9600);
  Serial.begin(9600);
  pinMode(Pin13LED, OUTPUT);
  digitalWrite(SSerialTxControl, RS485Receive);  // Disable RS485 Transmit 
}

void loop() {


if (RS485Serial.available()) 
   {
    int k= RS485Serial.read();
    Serial.print(k);
   }

}

That code would print "64" and not "@" when both are run and transmission is correct.

Post code that shows the problem!

when i write to the RS-485 interface, i call Serial.flush() to wait for all transmission to complete before disabling the TX.

your description is a bit confusing. i would only put quotes around a string, single quotes around a char, prefix hex values with 0x and just write the numeric value for integers and floats. So when you said you send 0x40 (64 or ‘@’) you expect to receive ‘@’ but are receiving ‘0’ or 0x30.

is the LSB transmitted first and the disabled transmission looking like 1s?

pylon:
That code would print “64” and not “@” when both are run and transmission is correct.

Post code that shows the problem!

Hi, 64 is DEC and is 0x40. whatever No1 sends 0x40 to No2, by right No2 will receive 0x40 or @, but the result is 0.

gcjr:
when i write to the RS-485 interface, i call Serial.flush() to wait for all transmission to complete before disabling the TX.

your description is a bit confusing. i would only put quotes around a string, single quotes around a char, prefix hex values with 0x and just write the numeric value for integers and floats. So when you said you send 0x40 (64 or ‘@’) you expect to receive ‘@’ but are receiving ‘0’ or 0x30.

is the LSB transmitted first and the disabled transmission looking like 1s?

Yes, you are right.

when No1 sends 0x40 to No2, by right No 2 will receive ox40 or @ but result is 0.
when No1 sends 0x41 to No2, by right No 2 will receive ox41 or A but result is 1.

#define RS485Transmit  LOW
#define RS485Receive   HIGH

A MAX485 transmits with a HIGH signal at DE/RE and receives with a LOW signal.

As your code doesn't do a flush before resetting that (swapped) signal, the lower nibble seems to be sent in the time frame where the driver is already activated again.