Introduction to Modbus


So what is modbus? I have heard many people ask me this and the reason it is confusing is because the term modbus is used with a variety of hardware and comes in different flavours: modbus RTU and modbus ASCII. Modbus is in itself a master-slave protocol intended to transfer small packets of data between a master and one or more nodes over a physical medium such as a serial wire. Some modbus devices only support rs-232 whereas others support RS-485, and even Ethernet. Modbus RTU and modbus ASCII differ in the way they transfer the data across, RTU mode uses a more compact packet whereas ASCII mode formats data bytes as strings. An example of each is shown below:

11 03 00 6B 00 03

The complete ASCII request is made by first adding the message delimiting characters. A colon is added to the start of the message, the LRC, carriage return and line feed are added to the end:

  : 1 1  0 3  0 0  6 B  0 0  0 3  7 E  CR LF

Each character is now treated as an ASCII character and replaced with it's hex value to give the final message, making a total of 17 bytes.

Modbus Registers

Every modbus device has zero or more registers, coils and digital inputs. Every register has an address between 0 and 65535. Normally registers are grouped together at certain addresses. In wattmon for example, digital inputs are at 1000, digital outputs at 2000, read only registers at 3000 and writable registers at 4000. I have seen different implementations of modbus that do not adhere completely to the specifications and interchange holding registers and input registers. Holding registers are used to set a value, either permanently in the EEPROM of a device or temporarily, such as an analog output. Input Registers generally give live readings of some digitised signal such as a current.

Wattmon devices have calibration registers which store calibration constants in EEPROM. All current sensors digitise the filtered analog signal and place the raw reading in one input register. A second register is used to store the calculated value. For example, a single channel sensor has a 12 bit range over 100 amps bidirectional current. The adc gives a reading of approx 2048 at 0 current, 4096 at 100 amps and 0 at -100 amps. But due to different factors this is sometimes off by a few points. For example, the 0 current could be at 2032, 2054 or something close.

One calibration register used in these sensors is an offset register. This is subtracted from the reading before further processing. Next, the reading needs to be scaled. This is done by multiplication and division since registers are 16 bit integers. For example, a 50 amp sensor typically is multiplied by 302 and divided by 10. This gives 30.2 mA per adc change. By pure calculation you would expect 2048/50 or 40.6 and this may vary from device to device, so every one needs to be calibrated against a known current. Wattmon includes one register for the multiplication factor and one for the division. Finally, a fourth register is used to allow the sign to be inverted, if the wire was pulled through in the wrong direction. The following shows an example of the registers:

holding registers:
Register 4000: 2032
Register 4001: 302
Register 4002: 10
Register 4003: 0

At adc reading 2000, input registers would look like this:

Register 3000: -966
Register 3001: 2000

Register 3000 is the calibrated value and indicates a current of -9.66 amps.

For a good simple reference on modbus, visit

Comments | Add yours
  • No comments found
Add comment