Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to read Holding registers more than 15. RX Buffer issue? #126

Closed
codev123 opened this issue Oct 11, 2023 · 6 comments
Closed

Not able to read Holding registers more than 15. RX Buffer issue? #126

codev123 opened this issue Oct 11, 2023 · 6 comments
Assignees
Labels
conclusion: invalid Issue/PR not valid type: imperfection Perceived defect in any part of project

Comments

@codev123
Copy link

codev123 commented Oct 11, 2023

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
@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Oct 24, 2023
@pomplesiegel
Copy link

Hi @codev123, thanks for making the issue! What baud rate and microcontroller + additional hardware are you using?

I'm wondering if this is the same behavior as the more generalized issue I'm seeing on my RP2040: #125

Thanks!

@pomplesiegel

This comment was marked as outdated.

@codev123
Copy link
Author

I have increased serial buffer size for uart to 256 bytes and issue is resolved. Thankyou sir

@pomplesiegel
Copy link

@codev123, thanks for the update! Can you specify which specific file / line you changed for this? Thank you!

@AlexanderTonn
Copy link

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
Copy link
Author

codev123 commented Dec 19, 2023

@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.

@per1234 per1234 self-assigned this Dec 19, 2023
@per1234 per1234 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
@per1234 per1234 added the conclusion: invalid Issue/PR not valid label Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: invalid Issue/PR not valid type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

4 participants