The ArduinoModbus library isn't supported with the Uno Wifi R4, but I've been trying to get it working.
First step was just to get it to compile, there were a bunch of lines that said:
`#if defined(ARDUINO) && defined(AVR)
I changed them to:
`#if defined(ARDUINO) && (defined(AVR) || (defined(ARDUINO_ARCH_RENESAS_UNO)))
to include the R4.
I have a very simple test program that calls ModbusRTUClient.begin() in setup and ModbusRTUClient.requestFrom() in loop. It works with an Uno R2, but not with the R4. I've hooked up a Modbus analyzer (WinModbus), and with the R4 version it says that the packet has failed checksum.
Under R2, the packet that is produced is: 0F 03 8D 00 15 09 E8
Under R4, the packet that is produced is: 0F 03 8D 00 15 09 FF
Same packet, except the last byte is FF instead of E8.
The function in the Modbus library that produces the crc checksum is called crc16. So in my test program I added this definition:
`extern uint16_t crc16(uint8_t *buffer, uint16_t buffer_length);
then in setup I put in the following code:
uint8_t buf[8] = {'D', 'E', 'A', 'D', 'B', 'E', 'E', 'F'};
uint16_t thecrc=crc16(buf, 8);
Serial.println("CRC Called");
Serial.println(thecrc, HEX);
while(1); // returns 18DD for R2, R4
This returns the same value for both boards, 18DD.
So I'm really at a loss. I also tried using the ModbusMaster library, (which has other issues). It was able to produce identical packets for both boards.
Any thoughts as to where I should be looking?