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

Possible to add multiple blocks of holding registers? #102

Open
nikstp opened this issue Oct 17, 2022 · 2 comments
Open

Possible to add multiple blocks of holding registers? #102

nikstp opened this issue Oct 17, 2022 · 2 comments

Comments

@nikstp
Copy link

nikstp commented Oct 17, 2022

Hi,

I'm trying to have an Arduino Uno serve as a Modbus RTU server to simulate a device I need for work. I'd like to setup multiple holding register blocks but so far I'm not having any luck as I get the "illegal data address" error.

What I mean is that if I would like to read from holding registers 6, 254, 867, and 1023 then I can't get it to work just by running

//Configure 1024 registers
result = ModbusRTUServer.configureHoldingRegisters(0, 1023);
if (result != 0) {
  Serial.println("Holding registers configured incorrectly!");
}

//initialize the 1024 registers with the number of the register
for (int i = 0; i < 1024; i++) {
  result = ModbusRTUServer.holdingRegisterWrite(i, (uint16_t)i);
  if (result != 1) {
    Serial.println("Failed to write to the holding registers!");
    break;
  }
}

What would be the correct way to go about doing this?

I know this was just opened and closed, but I've used a wrong account for that (#101).

Thank you!

@BayesianScrub
Copy link

result = result = ModbusRTUServer.holdingRegisterWrite(i, (uint16_t)i);
Doesn't look right

Also check how much ram you are using, the Arduino Uno Rev3 only has 2kB and you are trying to allocate 2kB for Modbus registers on top of whatever else is going on.

@nikstp
Copy link
Author

nikstp commented Dec 14, 2022

@BayesianScrub

result = result = ModbusRTUServer.holdingRegisterWrite(i, (uint16_t)i);
Doesn't look right

That was a typo.

Also check how much ram you are using, the Arduino Uno Rev3 only has 2kB and you are trying to allocate 2kB for Modbus >registers on top of whatever else is going on.

Possible cause, but if I remember correctly I've tried with 100+ and 200+ as well and what worked consistently is only 8 consecutive registers. Maybe it's more to do with how Modbus is defined in the lib; it's been a while so I'd have to check again on the number that works and if it's possible to define those registers separately. My recollection is that did not work, but maybe I didn't test it right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants