I'm currently facing a challenge in establishing Modbus communication between an Arduino OPTA (which already has an integrated module) and an Arduino Mega (where I added two separate modules).
For the OPTA, I utilized the libraries #include <ArduinoModbus.h> and #include <ArduinoRS485.h>, configuring it as a ModbusRTUClient, which, to my understanding, acts as the master responsible for requesting and sending values. On the Arduino Mega, as the ArduinoModbus library isn't available, I used <ModbusRtu.h>.
The issue I'm encountering is that while OPTA can successfully read and write, the problem arises when the Arduino Mega attempts to write to a register. During this write operation, OPTA generates a CRC error.
I suspect that the discrepancy in libraries might be causing the problem. Has anyone faced a similar situation or have suggestions on resolving this CRC error during the write operation?
Your insights and assistance would be highly appreciated. Thank you in advance!
Don't quite understand, sounds like 2 masters??
The ModbusRTUClient is a master, requesting and sending info to the servers (slaves), can only be 1 master..
Not sure how you have the ModbusRtu.h but servers (slaves) don't send anything unless client (master) asks for it..
CRC woes are typically bad comms, the CRC is in there to make sure data is proper when received..
I've already try that library and OPTA warn me, every time I try to read or write from Modbus that the connection is timed out, so OPTA cannot read or write registers.
Previously you said CRC error, now you are saying timed out? But you also said "The issue I'm encountering is that while OPTA can successfully read and write, the problem arises when the Arduino Mega attempts to write to a register. During this write operation, OPTA generates a CRC error." but the sketch for the Mega you showed does not write to a register (it is a slave).
Unfortunately your description of the problem is too confusing. We need to go back to basics I think.
Yes, I made a mistake. OPTA reads and writes to two registers. Arduino Mega periodically reads register 0x8A and then inserts the value into register 0x00. Register 0x8A is written by OPTA, while reading register 0x00 results in a CRC error when using the <ModbusRtu.h> library. However, with CMB27 - ModbusRTUSlave, it results in a timeout error.
Do you mean the OPTA is programmed to do that, or that it actually runs without error? Which registers is it reading/writing? How is it doing it? What commands does it send?
If you cannot provide details, we cannot help you.