Need help in transmit and receive over RS485

I am working on home automation project to control relays over

  1. WiFi (Ethernet shield)
  2. Physical push buttons
  3. Remote HMI board (arduino UNO) link with modbus RS485 module

I completed the work with WiFi and physical push button which works fine. I also check the test sketch for RS485 which works fine but when I add this with my main sketch its not respond as expected.

Flow of code :

  1. Send the string "A" from transmitter
  2. Receiver receive "A" execute based on string and eco back to transmitter.

challenge :

Receiver always receive block sign or 255. while same setup working fine with test code.

Below first two is test code and 3rd code is my complet code focused area is line #186~223.

If someone can look into the code and correct me.

2nd Blink UNO DIY Sender .txt (13.6 KB)

2nd Blink Mega Receiver.txt (4.28 KB)

Smart_home_with_RS485.ino (15 KB)

I have not looked in detail but first thing I notice is your trying to use 115200 baud with SoftwareSerial but it cannot go this fast (see here).
Also you have delay code in one sketch that calculates the delay needed before switching the RS422 from TX to RX but in the other your using a simple delay(1) that might not allow time for buffers to empty and things to settle after the direction switch to RX.

Thanks Riva for your time and comment.

I follow your comment and put the sketch before delay and also modify my sender code and make it simple Serial.write('A') Now working fine.

I have 1 more thing when I am try to access through Ethernet shield RS48 sketch stuck for few sec until webpage opened. This web page is copied on SD card of Ethernet shield. I am also using digital pin 11 and 12 for soft serial. Is there conflict to use digital pin 11 and 12 on arduino mega with ethernet shield.

If yes which pin should I use.

I'm not on my PC (off on holiday) so difficult to check but look at the documents for the shield and it will tell you what pins it uses and yes pins 10 thru 13 will conflict and another on for the sd card that I don't remember.

EDIT:
I'm back from holiday now, did you get this sorted out okay?