Page 1 of 1

MODBUS Slave Holding Registers

Posted: Tue Jan 18, 2022 9:39 am
by AbhijitR
Hello!

I am working on MODBUS Slave and i noticed one problem (i am not sure if this is a problem or it is like that only), when i assign SetHoldingRegister or ReadHoldingRegister in a sequence all goes well till i assign Coil Address 00007, when i assign Coil Address 00008 and 00009 then the warning is Syntax Error, then i assign the Coil Address as 00010 all goes well again until Coil Address 00018 and 00019 and probably so on, i guess.

When i check the MODBUS Slave on computer using MODBUS Master, then the Coil Address 00008 which is now 00010 and 00009 is now 00011 shows correct on the computer as 00008 and 00009 in real time.

Now the problem is when i provide the data to the user i need to cautiously mention correct Coil Address as there is a difference of 2 digits every time.

May i know if this is possible to rectify the problem of Coil Address 00008, 00009, 00018, 00019

Thank you.

Abhi

Re: MODBUS Slave Holding Registers

Posted: Tue Jan 18, 2022 11:09 pm
by chipfryer27
Hi Abhi

What chip are you using? Is it the same with all or just specific to the one you are using? Initially it does perhaps sound like a bug somewhere especially if your PC shows correct.

Not an expert in MODBUS but I do have Master/Slave emulators and some basic hardware that I can use to perhaps replicate issue if it helps. Bit busy just now but happy to help when/if I can.

Regards

Re: MODBUS Slave Holding Registers

Posted: Wed Jan 19, 2022 11:20 am
by Benj
Hello,

The problem is that a number starting with a 0 is interpreted as an octal number in C. Hence the problems with addresses 8 and 9 which are outside the range of an octal digit.

Try just using the values 8 and 9 instead of 0008 and 0009, hopefully they will work correctly for you.

More info here.
https://www.geeksforgeeks.org/octal-numbers-c/