ArduinoMega2560 - communicating through RS485 in both directions using MAX485

Hi again!
I’am so sorry for late answer – didn’t had time yesterday at all + I won’t be able to try out new programs until monday :C

To "MorganS":

  1. Okey okey man thanks! I actually kept the baudrate pretty low, becase I have read somewhere that on higher baudrates “SoftwareSerial” isn’t that effective :open_mouth: Is it true or just a rumor? So if I speed it up, up to 57600 do you think SWserial will handle it?
  2. Alright! So if I add a little while function like this:
boolean stop_byte = false;
…
while( stop_byte != true){
   if(Serial3.available())//When you receive some data save it into the rx_buff[] variable
   {    
    rx_buff[rx_length] = Serial3.read();
    if(rx_buff[rx_length] == 0xDD)stop_byte = true;  
    rx_length++;  
   }    
}

Should it solve the problem? :open_mouth:
3) Why? :C I really liked this function because I don’t need to ask for Serial.availeble() in loop function (I have a feeling like its “unprofessional” to ask the program constantly “Is there something in the buffer …. Is there something in the buffer … ” :D). Doesn’t it work like an external interrupt? But okey! Will try it out without the serial event!

To "Rockwallaby":

  1. Umm – “hardwareSerial”? What is it? :open_mouth: Tried to look it up on the internet but didn’t find much useful information :open_mouth: I just found some libraries but not description how it works or what it does or what it is :smiley:
  2. As I said! “Amap99” configuration is completely fine! It has all the modules it needs to have and is working perfectly! 
  3. Yeah I know they exist – but it’s a school project and those are sooo expensive! And school won’t support me with such amount of money …
  4. Thanks so much for it!
  5. Surly will inform you! I will try new programs on Monday! Looking forward to it :slight_smile:
    [1st. program] So I made a new program from what you said – do you think this one has a better chance to work? :smiley:
#include <SoftwareSerial.h>

#define SSerialTxControl 3   // Pin for MAX485 - HIGH send, LOW receive

 
int byteReceived;
int rx_buff[64]; 
int rx_lenght = 0; 
boolean stop_byte = false;

void setup()  
{
  Serial.begin(57600);   //Serial communication for USB.
  Serial3.begin(57600);  //Serial communication for RS48 - 14 pin as Tx and 13 pin as Rx.
 
  pinMode(SSerialTxControl, OUTPUT);  
  digitalWrite(SSerialTxControl, LOW); //Just receive data from RS485
}
 
 
void loop()  
{

  if(Serial3.available()){
   while( stop_byte != true)
   {
     if(Serial3.available())//When you receive some data save it into the rx_buff[] variable
     {    
      rx_buff[rx_length] = Serial3.read();
      if(rx_buff[rx_length] == 0xDD)stop_byte = true;  //if the received pair of bytes is equal to 0xDD then stop reading
      rx_length++;  
     }    
   }

   stop_byte=false;
   
   if(rx_buff[0] != 0x00)
   {   
   digitalWrite(SSerialTxControl, HIGH); // Get ready for sending data 
    for(int i=0;i<rx_lenght;i++)
      {
        Serial.write(rx_buff[i]);    //Then just send it one by one through USB to the PC
        Serial3.write(rx_buff[i]);   //And also send the data through RS485 to "Amap99"
      } 
    rx_lenght = 0;
    delay(10);   //Wait some time for all the characters to be sended out!
    digitalWrite(SSerialTxControl, LOW); //Get ready for receiving data
   }
   else
   {
   rx_lenght = 0;
   }
   }
   
}

Thanks so much again for everything!