## C. Mapping coils/discrete inputs overlaid with holding/input registers

Some registers share the same physical address in a device, and in this case the address is said to be overlaid. Although one may overlay holding and input registers, no special configuration is needed. However, when a coil or discrete input is overlaid with a holding or input register, the mapping becomes more complex and it does require special configuration. This is because the individual bits of a holding or input register have to be addressed (as coils or discrete inputs), and that depends on the ordering of the bytes in a 16-bit register. This would not in itself be a problem if the Modbus specification had indicated how they should be ordered, but since it did not, devices differ in how message addresses map to model addresses where individual bits are used i.e. for coils and discrete inputs, so some device-specific configuration is needed. For this section, you may need to refer to the sections Map Addresses and Add Register.

To map your own addresses, check your slave device manual for the Modbus type (holding registers, input registers, coils, discrete inputs), for the base address used and for the number of addresses. Then you can define for a slave the range and mapping to message addresses as described below.

• Number of Addresses. This is the same as any other form of address mapping. (see Map Addresses).

to find the address of a holding or input register. Note that all the registers in the discrete input or coil address space must be the same size (otherwise the mapping would be a little obscure!). The remainder after dividing by bits_in_register is used to determine which bit in the register the address refers to:

The bits are numbered "from right to left" (i.e. bit 0 is the least significant bit). Table 1 shows a simple example of the address mapping for coils overlaid with holding registers.

Table C.1. Address mapping overlaid coil and holding register

Slave Id Hold: Base Hold: No Input: Base Input: No Disc: Base Disc: No Coil: Base Coil: No
1: Slave with overlaid Coils 0 65536 0 0 0 0 100 96

With this mapping, registers 100..105 would be accessible as holding registers 100..105 and also as coils 0..95. This assumes the use of 16-bit registers - 6 * 16 = 96 bits, 32-bit registers would map to registers 100..102 - 3 * 32 bits = 96. Note that 100..105 are both message and model addresses since the base starts at zero, but 0..95 is a message address only. Using the rules above coil 37 would map to bit 5 (37 (coil message address) modulo 16 (bits in register) of holding register 102 (100 (base address) + (37 (coil message address) / 16 (bits in register))). Coil 37 is indicated by the letter 'B' in the following when the value of holding register 102 is viewed in binary notation. Note that bits within a byte are numbered from zero and from right to left.

This example assumes a particular ordering of the bytes, which is a configuration requirement that is the subject of the next section.

• C/D Swap. This configures the byte order.

In the example in the previous section, there is an implicit ordering for each pair of bytes within a 16-bit word in which the rightmost, least significant byte, (LSB) is sent first. This means that bits 0-7 in the right byte correspond to coils 32-39 and bits 8-15 in the left most significant byte (MSB) corresponds to coils 40-47. In this case, C/D Swap on the Map Addresses panel is checked, which is the default setting.

If the default ordering is not the way the slave sends the bytes - in other words if it sends the leftmost byte before the right byte, then the C/D:Swap checkbox should be unchecked. With this ordering, bits 8-15 in the leftmost byte now correspond to coils 32-39 and bits 0-7 in the right byte (LSB) correspond to coils 40-47. In the example in the previous section, coil 37 would be in the position indicated by 'B' below when the value of holding register 102 is viewed in binary notation: