Today is...
Tuesday, October 16, 2018
Welcome to the Modbus Community, about
the world's leading automation protocol.
Quandary: Software Layout of Registers
Is it acceptable for (say) two two-word registers to be one address apart?

I am laying out register definitions for an RTU based slave device. Previously, I would leave holes in my Modbus address map for registers that spanned more than one 16-bit word. For example, for two floating point registers (32 bits each), I might define the following (note that Modbus Addr 11 is undefined):


Modbus Addr: 10, Register Type: float, Register Name: sensor_1
Modbus Addr: 12, Register Type: float, Register Name: sensor_2

But since my slave device is controlling what gets returned in response to the master's request, leaving a hole isn't necessary:


Modbus Addr: 10, Register Type: float, Register Name: sensor_1
Modbus Addr: 11, Register Type: float, Register Name: sensor_2

The slave device would have no trouble returning the floating point value for sensor_1 when requested on address 10, nor the floating point value for sensor_2 when requested on address 11.

Though not immediately intuitive, I don't see any problem with this approach, and it would let me compact the register addresses.

The question: Is this "compressed" approach idiomatically acceptable? Or do slave implementations always allocate unused registers to reflect the number of words actually spanned?

Though it might work for some slaves there are slaves that will have problems with this approach.

If you take a look at the modbus manual "http://modbus.org/docs/PI_MBUS_300.pdf" you will see modbus register are 16 bit registers. A request from the master requests a number of registers and the response from the slave will be a number of bytes. In many modbus devices succeeding registers can contain integers, bytes, floats, long floats, ... and it is up to slave to extract the correct data. So register 1 can contain an integer value, register 2 a 4 byte floating point, register 3 will be 2 bytes of the previous floating point, ...

Look at modbus as a 16 bit register communication protocol. Whatever is in those 16 bit registers depends on the device.

If you want to access the registers in your example in one request you have to use "Read holding register: 03", Starting address: 10, No. of registers: 4. The slave will respond with 8 bytes of data.
If your second request the master uses "Read holding register: 03", Starting address: 10, No. of registers: 2. The slave will respond with 4 bytes of data which is not correct.