RS-485 reads Empty spaces!

Hello friends,

I'm having a trouble in connecting two arduino megas with RS-485. I've attached the code bellow. In Serial Monitor, I get printed only the "This is just in..." & empty spaces.

Master code for Arduino Mega

#define slave_1 1
#define slave_2 2
#define slave_3 3
#define slave_4 4
#define slave_5 5
#define slave_6 6
#define controlPin1 48
#define controlPin2 30

String split;

 String getValue(String data, char separator, int index)
{
  int found = 0;
  int strIndex[] = {0, -1};
  int maxIndex = data.length()-1;

  for(int i=0; i<=maxIndex && found<=index; i++){
    if(data.charAt(i)==separator || i==maxIndex){
        found++;
        strIndex[0] = strIndex[1]+1;
        strIndex[1] = (i == maxIndex) ? i+1 : i;
    }
  }
  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}


void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);

  pinMode(controlPin1, OUTPUT);
  pinMode(controlPin2, OUTPUT);
  digitalWrite(controlPin1, LOW);
  digitalWrite(controlPin2, LOW);

  Serial.println("Setup is ready!");
  Serial.println("Waiting for the communication process...");
 
}

void loop() {
  read_slave_1();
}

const byte numChars = 64;
char receivedChars[numChars];  // an array to store the received data

boolean newData = false;

void read_slave_1() {
  digitalWrite(controlPin1, HIGH);
  Serial1.write(slave_1);
  delay(10);
  digitalWrite(controlPin1, LOW);
  latchData();
  delay(100);
  printData();
}

void latchData() {
  static byte ndx = 0;
  char endMarker = '\n';
  char rc;

  while (Serial1.available() > 0 && newData == false) {
    rc = Serial1.read();

    if (rc != endMarker) {
      receivedChars[ndx] = rc;
      ndx++;
      if (ndx >= numChars) {
        ndx = numChars - 1;
      }
    }
    else {
      receivedChars[ndx] = '\0'; // terminate the string
      ndx = 0;
      newData = true;
      split=receivedChars;
    }
  }
}

void printData() {
  if (newData == true) {

 String inData[15];
 Serial.println(receivedChars);
    
//    inData[0]=getValue(split,',',0);
//    inData[1]=getValue(split,',',1);
//    inData[2]=getValue(split,',',2);
//    inData[3]=getValue(split,',',3);
//    inData[4]=getValue(split,',',4);
//    inData[5]=getValue(split,',',5);
//    inData[6]=getValue(split,',',6);
//    inData[7]=getValue(split,',',7);
//    inData[8]=getValue(split,',',8);
//    inData[9]=getValue(split,',',9);
//    inData[10]=getValue(split,',',10);
//    inData[11]=getValue(split,',',11);
//    inData[12]=getValue(split,',',12);
    
    
    Serial.println("This just in ... ");
//    Serial.println(inData[0]);
//    Serial.println(inData[1]);
//    Serial.println(inData[2]);
//    Serial.println(inData[3]);
//    Serial.println(inData[4]);
//    Serial.println(inData[5]);
//    Serial.println(inData[6]);
//    Serial.println(inData[7]);
//    Serial.println(inData[8]);
//    Serial.println(inData[9]);
//    Serial.println(inData[10]);
//    Serial.println(inData[11]);
//    Serial.println(inData[12]);
//    
    newData = false;
  }
}

Slave code for Arduino Mega

[code]
#define myID 1
#define controlPin1 48
#define controlPin2 30

int called_ID;

void setup() {
  Serial1.begin(9600);
  pinMode(controlPin1, OUTPUT);
  pinMode(controlPin2, OUTPUT);
  digitalWrite(controlPin1, LOW);
  digitalWrite(controlPin2, LOW);
}

void loop() {

  while (Serial1.available() > 0) {
    called_ID = Serial1.read();
  }
  delay(10);
  if (called_ID == myID) {
    digitalWrite(controlPin1, HIGH);
    
    Serial1.print("10");
    Serial1.print(',');
    Serial1.print("20");
    Serial1.print(',');
    Serial1.print("30");
    Serial1.print(',');
    Serial1.print("40");
    Serial1.print(',');
    Serial1.print("50");
    Serial1.print(',');
    Serial1.print("60");
    Serial1.print(',');
    Serial1.print("70");
    Serial1.print(',');
    Serial1.print("80");
    Serial1.print(',');
    Serial1.print("90");
    Serial1.print(',');
    Serial1.print("100");
    Serial1.print(',');
    Serial1.print("110");
    Serial1.print(',');
    Serial1.print("120");
    Serial1.print(',');
    Serial1.println("130");
    Serial1.flush();
    
    delay(100);
    digitalWrite(controlPin1, LOW);

    called_ID = 0;
  }

}

But when I send a '\n' character in very first from the slave, I can receive the readings in this way.

60
70
80
90
100
110
120
130This just in ...

This just in ...
10
20
30
40
50
60
70
80
90
100
110
120
130This just in ...

This just in ...
10
20
30
40
50
60
70
80
90
100
110
120
130This just in ...

This just in ...
10
20
30
40
50
60
70
80
90
100
110
120
130This just in ...

This just in ...
10
20
30
40
50
60
70
80
90
100
110
120
130This just in ...

I'm using '\n' character to separate the loop.

I'm using MAX485 chip built in shield to communicate with arduinos. Serial1 & Digital pin 48 from both arduino is used for communication and controlPin respectively.

Would be great help, if some one can help me to fix this!

Thanking you in advance..[/code]

hello_folks:
Hello friends,

I'm having a trouble in connecting two arduino megas with RS-485. I've attached the code bellow. In Serial Monitor, I get printed only the "This is just in..." & empty spaces.

Master code for Arduino Mega

You do realize, if you tie DE and !RE together and switch from Receive to Transmit mode, the MAX 485 tri-states the RO pin, with nothing driving the RX pin of your Arduino that signal falls to zero volts which cause the UART to interpret it as a Start bit. Make sure you have a pullup resistor on the RX pin, Use a 10k to Vcc.

Chuck.