rs485 controlling multiple master devices

Hi, I am trying to communicate with 3 arduinos via rs485. But all arduinos are sending and also receiving data (there is no master or slave). Except rs485 data line (A and B) I connected an other (additional) rs485 line and it's for putting in order which arduino will send data or receive data.

As an example, with additional rs485 line I am setting arduino's transmit and receive periods like below;

"arduino1 send data, arduino2-3 receive data" or
"arduino2 send data, arduino1-3 receive data" or
"arduino3 send data, arduino1-2 receive data" ...

With only one rs485 line I could not order which one will send or receive data, while arduino1 is sending data, also arduino2 or arduino3 is sending at the same time. So sending datas crashes,

As I told above, I solved this problem with adding one more rs485 line and I added one more arduino (exceptarduino1-2-3) and this additional arduino is controlling which arduino (arduino1 or 2 or 3) will send data or receive data. But I dont know is this true way, if it's not could you help me with the true way... thanks.

Hi,
Did you google;
arduino rs485 multiple devices

Can you post your codes and circuit diagrams please?

Thanks.. Tom.. :slight_smile:

hi Tom, I searced it before posting but couldnt find solution, maybe found but I could not understand :slight_smile:

// ARDUINO 1

#define SSerialTxControl 3   //RS485 Direction control
/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX

/*-----( Declare Variables )-----*/
int byteReceived;

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  RS485Serial.begin(4800);   // set the data rate
}


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  digitalWrite(SSerialTxControl, HIGH);  // Enable RS485 Transmit
  RS485Serial.write(200);          // Send 123 tO Arduino 2
  digitalWrite(SSerialTxControl, LOW); // disable RS485 Transmit

  if (RS485Serial.available())  //Look for data from Arduino 2
  {
    byteReceived = RS485Serial.read();    // Read received byte
    digitalWrite(SSerialTxControl, HIGH);  // Enable RS485 Transmit
    RS485Serial.write(byteReceived); // Send the byte back
    digitalWrite(SSerialTxControl, LOW);  // Disable RS485 Transmit
  }

}//--(end main loop )---
////////////////////////////////////////////////////////////////////////////////
// ARDUINO 2
// ARDUINO 2


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  digitalWrite(SSerialTxControl, HIGH);  // Enable RS485 Transmit
  RS485Serial.write(100);          // Send 100 to Arduino  1
  digitalWrite(SSerialTxControl, LOW); // disable RS485 Transmit

  
  if (RS485Serial.available()) //Look for data from Arduino 1
  {
    byteReceived = RS485Serial.read();   // Read the byte
    digitalWrite(SSerialTxControl, HIGH);  // Enable RS485 Transmit
    RS485Serial.write(byteReceived); // Send the byte back
    digitalWrite(SSerialTxControl, LOW);  // Disable RS485 Transmit
  }

  
}

I tried to explain my question with a basic code like above. As you see in the code Arduino1 (Ard1) and Arduino2 (Ard2) both sending and receiving data. But while Ard1 is sending data maybe Ard2 is not at receiving period, at the same time maybe Ard2 is also sending data to Ard1. Sometimes they will read sending data's of each other but sometimes will not. Becase while Ard1 is sending data, maybe Ard2 is also trying to send data to Ard1. Sending datas will crash if they do not know when to send when to receive.

I solved this problem (send and receiving time conflict) with adding one more arduino and connected it with additional rs485 line. This added arduino is telling them (ard1 and ard2) their sending and receiving time periods. But I guess this is not true way.

in brief, I want to ask you, How to set the sending and receiving timings while 3 or more arduinos trying to talk with each other :confused:

thanks for your help.

I searched more and I guess there is no way to communicate with multimaster devices on rs485. so if you want to use rs485 and if you have more then 1 master, you must addresses master devices and tell them which one will listen for data or send data.

thanks.

Make one Arduino the master, and all others slaves. Then make the master address each slave in turn and make it send either data or a dummy ACK or NACK. Each slave waits for its ID sent by the master and answers only when that ID was sent.

Hi,
Can you tell us the application you have, what does the system consist of.
Hardware, sensors, what is the overall hardware is going to do?

Thanks.. Tom.. :slight_smile: