1

I have two Arduinos on a RS-485 line, one acting as a Master and the other as a Slave. The Master simply transmits information to the Slave, which parses it.

They work fine when the Master is turned on first and then the Slave is turned on. However, I'd like to make it so that the Slave can be disconnected and reconnected to the line and re-discover the connection (ideally without resetting either Arduino).

Here's the code from the Slave's loop

  void loop()
     {

       if (RS485Serial.available() >0 )  //Look for data from other Arduino
       {   
        char byteSend = RS485Serial.read();    // Read received byte
        String str = String(byteSend);
         if (str == "<")  {      //  beginning of the transmission
       // does stuff here
      }
   }

}

Here is the relevant section of Master's loop:

  output_value ="<1,1,1,1,1,1,1>";
 RS485Serial.print(output_value);
 delay(250);
 RS485Serial.flush();

Any advice is appreciated...

  • What is the problem ? Have you already tested without success? – TMa Oct 20 '14 at 15:22
  • @bluefeet - this is not an Arduino question. It is a protocol question which happens to be implemented on Arduinos, but what is important is the protocol, not the platform, and dumping it to the Arduino site merely disconnects it from other similar issues that don't happen to use that platform. – Chris Stratton Oct 20 '14 at 17:10
  • @ChrisStratton: I agree, but I wish you would say which site you think is better for protocol questions like this one. – David Cary Aug 31 '15 at 4:43
1
    char byteSend = RS485Serial.read();    // Read received byte
    String str = String(byteSend);
     if (str == "<")  {      //  beginning of the transmission
   // does stuff here
  }

This is an extremely inefficient way of testing for one character. Much better would be:

    char byteSend = RS485Serial.read();    // Read received byte
    if (byteSend == '<')  {      //  beginning of the transmission
   // does stuff here
  }

However, I'd like to make it so that the Slave can be disconnected and reconnected to the line and re-discover the connection (ideally without resetting either Arduino).

I know I'm not supposed to ask questions here, but what is stopping you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.