Not able to read Holding registers more than 15. RX Buffer issue?
Closed this issue · 6 comments
I am using ArduinoModbus library with RP2040 Pico with Arduino Pico core.
I am able to communicate with Modbus slave and client using this library, the limitation I am facing is that I need to read around 100 holding registers from energy meter slave and process that data to serve it on to Modbus TCP server. but i can only read up to 14 holding registers using Modbus RTU client. please guide me how to fix the issue.
const int numHoldingRegisters = 100;
void readHoldingRegisterValues() {
Serial.print("Reading Holding Register values ... ");
// read 10 Input Register values from (slave) id 42, address 0x00
if (!ModbusRTUClient.requestFrom(42, HOLDING_REGISTERS, 0x00, numHoldingRegisters)) {
Serial.print("failed! ");
Serial.println(ModbusRTUClient.lastError());
} else {
Serial.println("success");
while (ModbusRTUClient.available()) {
Serial.print(ModbusRTUClient.read());
Serial.print(' ');
}
Serial.println();
}
// Alternatively, to read a single Holding Register value use:
// ModbusRTUClient.holdingRegisterRead(...)
}
the error shows:
.............. failed! Connection timed out
@codev123, any update / status + additional info? Thanks
I have increased serial buffer size for uart to 256 bytes and issue is resolved. Thankyou sir
@codev123, thanks for the update! Can you specify which specific file / line you changed for this? Thank you!
Please consider that Modbus RTU requires a termination resistor at the end of the line. i personally don't have problems with the buffer size. I used the Arduino Opta RS485 and i read currently 30 registers without problems.
Probably it can be helpful:
I currently writing a class for reading and writing registers of a mppt charger.
@codev123, thanks for the update! Can you specify which specific file / line you changed for this? Thank you!
I have used serial1 on my pico board, added this line in setup()
code:
Serial1.setFIFOSize(256);
And it works fine.
Issue with library is that it doesn't fix modbus response buffer size, it's microcontroller specific.