I am having issues communicating via Modbus with the hardware listed below. There is an example using the same Click 3v3 board but only reading sensor data. I need to read and write data. I have some simple code written that initialized Modbus, write to a single register (function code 0x06) and then read from that same register, but in my serial console I repeatedly get errors from ModbusMaster library: E2 and E0. (response timed out exception / invalid response slave ID exception). Pictures and code below as well of qModbusMaster configuration + payload frames. The photon is being powered by USB as well.
Let me know if I am missing any information that would be helpful or something that I am missing.
Although it says that the values are written correctly, it does not show the value in the register. The response frame from the bus monitor also shows FF FF which isn't the data. Any help would be appreciated.
Hi @mprzez what is your jumper configuration on the Click 3.3V? Do you have the termination resistor enabled (J4)?
I'm also reading the documentation for the Click 3.3V and this line:
Therefore, RS485 Click 3.3V offers UART RX and TX pins routed to the appropriate mikroBUS™ TX and RX UART pins.
kind of makes me think that the TX/RX pins might be already swapped for you. Could you try reversing the TX/RX configuration you have currently and report back?
@ericpietrowicz Nothing seemed to change after replacing the code. Same errors/packets.
I have also attached an image of my setup with the wiring of the hardware.
(sorry for using the same wire colors for everything, it was convenient for me)
I am unsure if this is a hardware or software issue. I am leaning towards software since the ModbusMaster library is the only library available for particle boards and it is outdated by a few versions from the most recent.
To be sure the data would update correctly, I also set the data to 0x5a0f and got the correct output in the debug log and the logic analyzer. The CRC calculator also returned a match.
Maybe there is a misunderstanding, or I am not understanding how Modbus works, I need bidirectional communication, to be able to write to registers and then also read those values. My tests have been made using qModMaster software, and I just don't see anything being stored in any registers although I see the same payload received that you also are getting.
That error is because I didn't have a modbus device, or even a bus. I just connected the logic analyzer to the TX pin (at 3.3V level), so the timeout is expected in my test.
Would this mean that it is a hardware or wiring issue then?
Or could it potentially be Modbus test software issue?
I am trying to pinpoint what I should try to debug further; I have already tried various softwares to interface with the USB on my laptop and I have tried different wiring configurations (as well as trying a different board: https://www.amazon.com/DSD-TECH-SH-U12-MAX13487-Raspberry/dp/B07B667STP)