Modbus protocol basics

Modbus protocol is one of the most widely used communication protocols in the field of industrial automation, especially in data transmission between PLC, DCS, sensors, frequency converters and other equipment. It was proposed in 1979 by Modicon Corporation (now part of Schneider Electric) for communication between programmable logic controllers.

Basic features of Modbus protocol:

  • Simple and easy to implement.
  • Open standards and strong manufacturer compatibility.
  • Supports master-slave communication mode (Master-Slave).
  • Data transmission efficiency is high, but the function is relatively simple.

Modbus protocol communication mode:

Master-slave mode:

  • Master: Send commands, read or write data.
  • Slave: receives commands, returns data or performs operations.

Request and response:

  • The master station sends a request (such as reading a register value).
  • After receiving the request, the slave station processes and returns a response.

Multiple slaves:

  • There can be multiple slave stations on a bus, and each slave station has a unique address (1~247).

Modbus protocol communication method:

Modbus RTU (Remote Terminal Unit)

  • Based on serial communication (RS-232/RS-485).
  • Data is transferred in binary form.
  • Advantages: high efficiency, small bandwidth usage.
  • Commonly used in industrial field equipment.

Modbus ASCII

  • Based on serial communication (RS-232/RS-485).
  • Data is transmitted in ASCII code.
  • Advantages: Convenient for manual debugging.
  • Disadvantages: Communication efficiency is lower than RTU.

Modbus TCP/IP

  • Based on Ethernet communication (TCP/IP protocol).
  • Data is encapsulated and transmitted in TCP packets.
  • Advantages: Supports networking, connects a large number of devices, and is easy to integrate.
  • Nowadays, it is widely used in the industrial Internet of Things.

Data structure:

Modbus uses "registers" to store data, and each register occupies 16 bits. The main types are:

Type Function Address range Description
Coil Read/Write 00001~09999 Discrete output, single bit
Discrete Input Read only 10001~19999 Single bit input
Input Register Read only 30001~39999 16-bit analog input
Holding Register Read/Write 40001~49999 16-bit analog output or parameter

Common function code (Function Code)

The function code is used to tell the slave station the type of operation requested by the master station. Commonly used ones are:

Function code Function Description
01 Read coil status Read discrete output
02 Read discrete input Read discrete input
03 Read holding register Read writable register
04 Read input register Read read-only register
05 Write a single coil Control output
06 Write a single register Write a single analog quantity
15 Write multiple coils Batch output control
16 Write multiple registers Write analog quantities in batches

Communication process:

The master station sends a request:

  • Includes slave address, function code, data address, data length, etc.

Slave parsing request:

  • Perform operations (read/write) based on function codes.

Response returned from the station:

  • Return data successfully, and return exception code if failed.

Master station processing response:

  • Process the read data or confirm that the writing is successful.

Application of Modbus protocol:

  • Industrial automation control: communication between PLC and sensors and actuators.
  • Data acquisition system (SCADA/DCS): monitors on-site data in real time.
  • Industrial Internet of Things: Connect devices to the host computer system through Modbus TCP/IP.