ArduinoMega2560 - communicating through RS485 in both directions using MAX485

Serial is

S

L

O

W

...really slow!

Your little while(Serial3.available) loop will usually only ever see one character. There's probably more characters coming down the pipe but you can't tell until after they arrive. So if you immediately turn around and try to transmit, you'll probably collide with the next character.

To make this work, your receiver-retransmitter needs to understand the packets of data that it's being sent. It needs to identify the end of a transmission so that it can turn over to transmit mode without clashing with the incoming data.

Also, get rid of the serialEvent3() function. It's a relic of an old idea from Arduino which never really worked out. You can do all of this in the main loop.