Modbus Protocol

Modbus is a widely used protocol in industrial automation for serial communication. It facilitates communication between multiple devices connected to the same network, allowing for the monitoring and control of industrial equipment.

Overview of Modbus Protocol

Modbus is a communication protocol developed by Modicon systems (now Schneider Electric) in 1979. It is used for transmitting information over serial lines between electronic devices. The protocol is simple, robust, and widely adopted in industrial environments.

Key Features of Modbus

Modbus Communication Modes

Modbus supports different communication modes:

Modbus RTU (Remote Terminal Unit)

Modbus RTU is a binary protocol and the most common implementation. It uses a compact, binary representation of data for communication.

Modbus ASCII

Modbus ASCII uses ASCII characters for communication. It is less efficient than RTU but easier to read and debug.

Modbus TCP/IP

Modbus TCP/IP allows Modbus communication over Ethernet networks using TCP/IP protocol.

Modbus Message Structure

Modbus messages consist of four main parts:

Device Address

The address of the slave device (1 byte). In Modbus TCP/IP, this is replaced by an IP address.

Function Code

Indicates the type of operation to be performed (1 byte).

Data

The data to be transmitted or received (variable length).

Error Check

CRC (Cyclic Redundancy Check) for RTU or LRC (Longitudinal Redundancy Check) for ASCII (2 bytes).

Common Modbus Function Codes

Modbus supports various function codes for different operations:

Example: Reading Holding Registers

To read holding registers from a slave device, a Modbus RTU message might look like this:

| Device Address | Function Code | Starting Address | Quantity of Registers | Error Check (CRC) |
|       01       |       03      |     00 10        |         00 02          |       xxxx        |
  

This message requests to read 2 registers starting at address 0010 from the slave device with address 01.

Modbus RTU Frame Example

Consider a Modbus RTU request to read 2 registers starting from address 0x0010:

The complete frame: 01 03 00 10 00 02 C4 0B

Modbus Cables

Modbus communication can be carried out using different types of cables, primarily based on the physical layer being used:

1. Modbus RTU/ASCII (RS-485)

RS-485 is the most common physical layer used for Modbus RTU and ASCII communication. It allows for longer cable lengths and multiple devices on the same bus.

2. Modbus RTU/ASCII (RS-232)

RS-232 is also used for Modbus communication but is limited to point-to-point connections and shorter distances compared to RS-485.

3. Modbus TCP/IP

Modbus TCP/IP uses Ethernet for communication, allowing for easy integration into existing network infrastructures.

Modbus Pinout Configurations

Modbus pinout configurations vary based on the physical layer being used. Below are the common pinout configurations for RS-485 and RS-232.

Modbus RS-485 Pinout

RS-485 typically uses a two-wire or four-wire configuration for differential signaling:

RS-485 Pinout

Modbus RS-232 Pinout

RS-232 typically uses DB-9 or DB-25 connectors with the following pinout:

DB-9 Pinout

DB-9 Pinout

DB-25 Pinout

DB-25 Pinout