Serial communication problems between Mega and RS485 device

I'm having trouble communicating with a stepper motor through a driver running on MCode.

I'm trying to talk to Schneider Electric's MForce Motor Driver using an Arduino Mega and a BOB-10124 TTL to RS485 converter.

The Mega's Serial1 port is working, but the data sent from the Arduino is not understood by the Driver and I'm receiving continuous gibberish data back from the Motor Drive. Any clue what's going on?

Hardware Components:
Arduino Mega
BOB-10124 TTL to RS485 converter
MForce Micro Drive Plus Motor controller
NEMA 17 Stepper Motor

#define SSerialRX        19  //Serial Receive pin
#define SSerialTX        18  //Serial Transmit pin

#define SSerialTxControl 3   //RS485 Direction control

#define RS485Transmit    HIGH
#define RS485Receive     LOW

#define Pin13LED         13
int ledPin = 5;

/*-----( Declare Variables )-----*/
char dataReceived;
char dataSend;

void setup()   /****** SETUP: RUNS ONCE ******/
{
  // Start the built-in serial port
  Serial.begin(9600);
  Serial.println("Input motor commands:");

  pinMode(Pin13LED, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(SSerialTxControl, OUTPUT);

  digitalWrite(SSerialTxControl, RS485Receive);  // Init Transceiver

  // Start the serial port, to another device
  //RS485Serial.begin(4800);   // set the data rate
  Serial1.begin(9600);
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  digitalWrite(Pin13LED, HIGH);  // Show activity
  if (Serial.available()) {
    dataSend = Serial.read();
    digitalWrite(SSerialTxControl, RS485Transmit);  // Enable RS485 Transmit
    Serial1.write(dataSend);   // Send byte to Motor Driver
//    Serial1.write('\r');
    delay(10);
    digitalWrite(SSerialTxControl, RS485Receive);  // Disable RS485 Transmit
    digitalWrite(Pin13LED, LOW);  // Show activity
  }
  if (Serial1.available()){
    digitalWrite(ledPin, HIGH);
    digitalWrite(SSerialTxControl, RS485Receive); // Ensure RS485 Receiving
    dataReceived = Serial1.read();
    delay(10);
    digitalWrite(ledPin, LOW);
    Serial.println(dataReceived);
  }
}

A few things:

  1. Leave the receiver enabled when you are not transmitting. Enable in setup, then disable it for transmit and reenable. Don't mess with it when reading data.

  2. Don't use delay when transmitting. You can use Serial1.flush() to make sure the character has been fully transmitted.

  3. Don't use delay ever. Up to 10 characters could have arrived in those 10ms of delay. After receiving 7 characters, you will have delayed 70ms. That is enough time to overflow the 64-byte input buffer, and you will start losing characters.

void loop()
{
  digitalWrite(Pin13LED, HIGH);  // Show activity
  if (Serial.available()) {
    dataSend = Serial.read();
    digitalWrite(SSerialTxControl, RS485Transmit);  // Enable RS485 Transmit

    Serial1.write(dataSend);   // Send byte to Motor Driver
//    Serial1.write('\r');
    Serial1.flush();

    digitalWrite(SSerialTxControl, RS485Receive);  // Disable RS485 Transmit
    digitalWrite(Pin13LED, LOW);  // Show activity
  }

  digitalWrite(ledPin, HIGH);
  if (Serial1.available()){
    dataReceived = Serial1.read();
    Serial.println(dataReceived);
    digitalWrite(ledPin, LOW); // Show activity (look quickly!  :-/)
  }
}