I was trying to use ArduinoModbus library that is very tied with ArduinoRS485. Using in Arduino Mega 2560, it was unable to work properly. The examples using MobBusRTUServerLed (Arduino Mega) and ModBusRTUClientToggle doesn't work correctly, presenting "Connection Timeout" in the client-side.
If I change the Arduino Mega to another Arduino Uno, the exemple works like a charm... but doesn't with Mega.
Debugging a little bit the code, I could perceive that the problem was in the ArduinoRS485 library that doesn't setup correctly the board pins for the Arduino Mega board.
To fix the problem, in the end of the RS485.cpp file, I changed the instantiation of de RS485 object to:
And all the communication started work great.
I know I hard-coded some values, but I'm putting here just to help you guys to fix the code, if you intend to do in this way.
I was trying to use ArduinoModbus library that is very tied with ArduinoRS485. Using in Arduino Mega 2560, it was unable to work properly. The examples using MobBusRTUServerLed (Arduino Mega) and ModBusRTUClientToggle doesn't work correctly, presenting "Connection Timeout" in the client-side. If I change the Arduino Mega to another Arduino Uno, the exemple works like a charm... but doesn't with Mega.
Debugging a little bit the code, I could perceive that the problem was in the ArduinoRS485 library that doesn't setup correctly the board pins for the Arduino Mega board.
To fix the problem, in the end of the RS485.cpp file, I changed the instantiation of de RS485 object to:
And all the communication started work great. I know I hard-coded some values, but I'm putting here just to help you guys to fix the code, if you intend to do in this way.