Arduino MEGA - Modbus RTU over RS485. Any *surely* working sketch?

Hi all!
First of all, thanks to all of you, that forum is a great resource!!

Then..i need your help.. i'm trying to make Arduino Mega talk as MASTER with some Mitsubishi industrial stuff that implements Modbus RTU.

At the moment i'm just trying to make sure that my program works fine, so i'm developing it and trying to test it linking the serial output of the Arduino Mega to an rs232 usb port on another pc, and tryin to run some Modbus Slave simulator on it.

Well..i can see stuff going out from the serial but noone of the simulators i tried can read any correct input.
I tried using
and also
GitHub - 4-20ma/ModbusMaster: Enlighten your Arduino to be a Modbus master.

I read the whole MOdbus specifications trying to figure it out but i can't.

So... is anyone so kind to post a surely working (even simple!) code that sees an Arduino as a master, commanding some slaves?
I'll try to put it on my arduino and run the same system i did with my code, so if the various slave simulators still won't work i'll know i have some other problem on my rig :confused:

Any idea/suggestion is welcome!

thanks :slight_smile:

a question came to my mind while i was writing...... actually i connect the arduino 2560 board and the usb rs232 just using GND,TX and RX. Do i have to connect some other stuff for Read Enable/Write Enable even if i'm "simulating" it via rs232 and not on 485???? :astonished:

Help! :stuck_out_tongue:

Have a look at
There is a good explanation on how the messages and replies are all the FC. Then you should be able look at what you are sending through the serial port and check if the message is what you want it to be and off course, what the reply should be from the slave.
They also have a working modbus master and slave (limited to some messages) but enough to figure out if your sentence is correct.

Hi Talarno,

Were you successful with any libraries or working sketches?

I am embarking on something similar and looking for basic examples.