RS485 Message Handlng

Hi, I'm trying to recieve messages from a RS485 device but the messages being printed to my serial monitor isn't matching the expected response. I'm using the TinySine RS232/RS485 shield with my uno board. I'd appreciate any pointers for communicating with RS485 deivces.

Code:

#include <SoftwareSerial.h>

#define rsStatus 4
SoftwareSerial mySerial(2,3);

void setup()
{
  pinMode(rsStatus, OUTPUT);
  digitalWrite(rsStatus, LOW);
  Serial.begin(9600);
  mySerial.begin(9600);

  Serial.println("Shield is getting ready");
  mySerial.println("RS485 is getting ready to recieve messages");
  
}
void loop()
{
  digitalWrite(rsStatus, LOW);

  if(Serial.available()){
    String message = "";
    while(Serial.available()){
      unsigned char sComm = Serial.read();
      message += sComm;
    }
    unsigned char sComm = Serial.read();
    digitalWrite(rsStatus, HIGH);
    delay(10);

    //Serial.write(sComm);
//    Serial.print("Recieved from Serial: ");
//    Serial.print(message);
//    Serial.print("\n");
    
  }

  if(mySerial.available()){
    unsigned char sComm = mySerial.read();
    digitalWrite(rsStatus, HIGH);
    delay(10);

    mySerial.write(sComm);
//    Serial.print("Recieved from 485:");
//    Serial.print(" 0x");
    Serial.print(sComm, HEX);
//    Serial.print(")");
    
  }
  delay(10);
}

Hi, @cc4451
Welcome to the forum.

Thanks for using code tags. :+1:

Can you please post a link to data/specs of the TinySine?
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

What is the output format of the 485 device?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Link to TinySine: https://www.tinyosshop.com/arduino-rs232-rs485-shield
Circuit image:


Output format is Asynchronus UART with baud rate 9600

#include <SoftwareSerial.h>

#define rsStatus 4
SoftwareSerial mySerial(2, 3);

void setup()
{
  pinMode(rsStatus, OUTPUT);
  digitalWrite(rsStatus, HIGH);
  Serial.begin(9600);
  mySerial.begin(9600);

  Serial.println("Shield is getting ready");
  mySerial.println("RS485 is getting ready to recieve messages");
}

void loop(){
  digitalWrite(rsStatus, LOW);
  delay(10);
  if (mySerial.available()) {
    byte sComm = mySerial.read();
    Serial.write(sComm);
  }

  if (Serial.available()) {
    byte sComm = Serial.read();
    digitalWrite(rsStatus, HIGH);
    delay(10);
    mySerial.write(sComm);
    Serial.print(sComm, HEX);
  }
}

since the RS-485 bus is half-duplex, only one transmitter can be enabled at a time, the transmitter must be enabled before transmission and wait for the Serial.flush() command to return (indicating transmission is complete) before disabling the transmitter.

besides the TX/RX pins, the RS-485 interface should have an receive enable and transmit enable pins. they are typically opposite polarity so that they can be wired together, either enabling the transmitter or the receiver

what do you get?
what do you expect?

Furthermore it would be nice if you could link the datasheet of your motor driver so we can see what that motor is supposed to send/receive.

Furthermore:
Do you have a RS485/USB Connector available so you can do some tests without the motor driver?

The schematic for the shield linked to in post #3 has this comment:

The UART_TX_485 with the FET(Q3) will help control the direction,but it's not perfect. In this case,the RS485 bus should be pulled up with resistor.otherwise the high level bit of send byte can't be sent to the RS485 BUS.

The schematic also appears to show that the default setting is for automatic direction control of the RS485 bus. Manual control appears to involve altering a solder jumper on the shield - bottom left corner of the schematic.

at least the MAX chip does require any pull-up resistors. It's worked for
367Fig05 (1)

not clear what the connections are between the Arduino and the shield.