Interview Question - Explain modbus protocol concept?


Modbus Protocol Concept

1.Master/Slave relationship

Master sends a request to the slave
Slave replies to the master requests

  1. Message contains device address (Slave id),Function code,Data,Error check

3.Each slave must have a unique device address
Range 1-247

4.Operating mode

ASCII: Legacy - human readable messages
RTU: Most efficient - efficient 8 bit binary character

Modbus device Function Code

Modbus device function code

Description of Modbus Function Code

Description of Modbus Function Code

Modbus Wiring -

Interface types -
RS232 : Point to Point (1 master - 1 slave)
RS 485- Multi drop bus (1 master - Many slaves)

RS 485

Differential signalling allows distance of upto 4000 ft.
Up to 32 devices with standard RS 485-Line drivers
Only 1 device may talk at a time
Require termination resistors at each end of bus


That’s a good summary of the Modbus protocol, with one exception, Modbus ASCII is not really a human readable format.

First, the Modbus ASCII data is normally SCADA data: process values, not text
Second, the data values always need to be decoded from binary transmission mode at application level. The decoding displays the original value, but that happens with RTU or TCP as well. No one reads raw binary.

But Modbus ASCII uses the hex representation of ASCII characters for the hex representation of the data value. So to read Modbus ASCII would be the same as reading hexadecimal, which is scarcely human readable.

In Modbus (RTU, TCP or ASCII), a 16 bit register consists of two 8 bit bytes.

Each 8 bit byte can be represented by two hexadecimal characters. So a 16 bit integer is represented by 4 hexadecimal characters

The hex value for the ASCII character for each hexadecimal number representing the data value is used in the Modbus message.

How convoluted is that?

For example, take a typical SCADA value, 472Vac, or 472 (decimal)

The 16 bit hex representation of 472 is 01D8

The Modbus ASCII representation of those four hex characters is
0 1 D 8
48 49 68 56

The hex representation of each of the ASCII character is
ASCII 48 49 68 56
Hex 30 31 44 38

The Modbus message then contains the binary equivalent of 30 31 44 38 (hex).

How does the message 30 31 44 38 resemble the value 472 ?
In what fashion is 30 31 44 38 (h) “human readable” ?

Yes, 30 31 44 38 can be converted to 48 49 68 56 which is then converted to 0 1 D 8, which is then converted to 472, but that’s just as readable as any Modbus RTU or Modbus TCP value converted to display in decimal.

The value of Modbus ASCII was that telephony modems were 7 bit and ASCII is 7 bit. Modbus RTU is 8 bit, it didn’t work on the modems of the '70’s, '80’s and '90’s era.

Furthermore, ASCII does not have the strict timing requirements of of RTU, which made ASCII useable over telephony modems.

The use of ASCII doubles the number bits for the data, compared to RTU. With the decline in use of telephony, the use of Modbus ASCII has declined because RTU is more efficient over local RS-485 networks or when it is packed as RTU over Ethernet.