Hi all,
I have been playing around with the Portenta H7 (M7 MCU for now), trying to implement Modbus RTU and TCP on it using Arduino485 / ArduinoModbus libraries since they cover the complete panel of Modbus Comms we need in our automation / BMS projects, and the results are ... mixed.
Modbus RTU works well, either as a slave (server) or a master (client). The only drawback is it seems to be able to use only Serial1 for its RS485. This seems to be a known problem of the library, and I tried various turnarounds I found on forums, and others I tried to devise myself, and no luck to this day.
Modbus IP server (I am stopped there for the moment) is trickier. The client connects and everything seems to work on the M7 side, but it just does not answer anything to the client when it asks for (in the current case) a block of 3 Inputregisters. It gets curiouser and curiouser when I load the exact same code (except the Ethernet library that switches from Breakout.Ethernet to the Ethernet2 library) to another platform (Industruino D21G based on an M0 processor) and it works perfectly.
I'm going to follow this post. I'm in the development of an industrial application and i need ModbusRTU to work. I had it working on a Controllino but was very unreliable in the field.
I think it's all to the bad libraries that Controllino has. If i could use the standard ModbusRTU libraries it would be bettter , but they indeed only work on Serial1 . Since i have the device constantly connected to a computer for future updates, using Serial1 is not an option.
Modbus RTU has to be "tuned" to the speed of the processor. In fact the H7, when only a Modbus master runs on it, has so low a scan time the slave network (I do not know at which level) is too slow to answer most requests, so sends an error and slows the whole RTU communication down. Corrected by inserting a delay(2) in my code, but this is unsatisfactory, since a more loaded H7 will not need it, so I will have a look at programming a minimum scan time of the MCU.
Modbus IP server works very erratically on the portenta, but does answer sometimes (which is a definite improvement). I am currently looking for a way to convince it to answer with a bit more reliability.
Why is this a problem ? Just use the USB or any of the other serial ports to connect your PC, or try another library like SimpleModbusSlaveV10 we have been using for years before on Industruino, that works very well and should work on, say, Serial3.
Well we also had some serial communication with the PC , so Serial1 was out of the question here. I have to see it took me some time to get ModbusRTU working on the Controllino, and yet in the field we still can't get it to work. The devices just won't connect. Not sure if this is due to the electrical pollution but we have taken allot of measurements to get rid of it. Still no luck.
I'll have a look at the library you posted. Thanks
Be careful about the termination resistors and the quality of your wiring in the field. Have a look at the resistance of your line. Do not hesitate to lower your communication speed.
If it works on the bench and not in the field, it means part of the problem at least is environmental.