Table of Contents

lamaPLC: Simatic and Modbus

Introduction

Certainly, I am aware that numerous descriptions of Modbus can be found online and in technical literature. As the oldest and most widely used industrial communication method, it serves as the backbone of industrial connectivity. While newer, more sophisticated communication protocols have emerged, Modbus remains prevalent. In fact, you might even encounter it on the first intergalactic spacecraft.

Although this communication method is widespread and often underestimated, it can lead to unexpected issues during commissioning, usually more negatively than positively. With over 25 years of experience in automation programming, primarily with Simatic systems, I'm sharing my observations. While the following is somewhat subjective, I hope many readers will have an „aha” or facepalm moment, helping them resolve certain problems.

Modbus Fundamentals

Origin and basics of Modbus

Modbus originated in 1979 and was created by Modicon (now part of Schneider Electric). During this period, industrial automation moved from relay-based systems to digital logic. As the pioneer of the first Programmable Logic Controller (PLC) a decade earlier, Modicon developed Modbus to facilitate communication among these controllers and with external devices via serial lines. The protocol features a straightforward query-response model, in which a “master” (client) initiates communication with one or more “slaves” (servers) to transfer data.

The protocol's emergence as a worldwide industry standard was fueled by several key factors:

In 2004, Schneider Electric officially transferred the rights to the Modbus Organization, an independent nonprofit that continues to manage and promote it as a public domain standard. Today, it is often called the “grandfather of industrial networking” due to its continued widespread use in both legacy factories and modern IoT systems.

Core application areas of Modbus

Industrial Automation & Manufacturing

Smart Buildings & Facility Management

Energy Management & Renewables

Water & Wastewater Management

Modbus Client and Server

In the Modbus protocol, the terms Client and Server specify the roles of devices during communication. These terms are the current, official replacements for the older “Master/Slave” terminology.

Modbus Client (formerly Master)

The Client is the active device that initiates all communication transactions. It's sending questions.

Modbus Server (formerly Slave)

A server is a passive device that responds to client requests.

Modbus RTU and TCP, and Hybrid

The core difference is the transport layer: Modbus RTU is designed for a physical wire (Serial), while Modbus TCP is designed for a network (Ethernet). Before Ethernet's advent, only the RTU (Remote Terminal Unit) protocol was available, primarily using RS-232 or RS-485. The rise of Ethernet greatly expanded options, enabling communication over the faster, more versatile TCP/IP protocol. Today, these two methods serve as the Modbus transport layer.

Although quite different, they can sometimes be integrated, such as in multimaster (hybrid) RTU scenarios. In this scenario, a signal converter needs to be integrated into the TCP network. The converter has its own IP address to receive Modbus/TCP telegrams. It's crucial that the client is aware of the Modbus/RTU network behind the converter, which uses traditional RTU addressing. Often, clients cannot manage both RTU addressing and TCP simultaneously, so verifying their ability to do so is essential. The Siemens TIA Portal is suitable for this task, and I will offer an example of its use later.

Modbus RTU shemaModbus TCP shemaModbus RTU-TCP hybrid shema
FeatureModbus RTUModbus TCP
MediaSerial (RS-485/232)Ethernet / Wi-Fi
Error CheckCRC (at the end)TCP/IP Checksum (built-in)
TopologyDaisy-chainStar (Switch-based)
SpeedTypically 9600 or 115200 baud10/100/1000 Mbps
Master/ClientOnly one MasterMulti-Master
PortSerial COM PortTCP Port 502
Segment distance1200 meters100 meters between switches
AddressingMaster ID: 0, slave ID: 1 to 247IP Address (like: 192.168.178.123)
Wiring3-core cable with shielding or 4-core cableEthernet cables (RJ45) and network switches

Modbus/RTU

Modbus/RTU was the first Modbus communication method and remained the main standard until Ethernet became popular. It remains widely used today, partly because its hardware integration is simpler and more affordable than Modbus/TCP. As a result, it is likely to stay available for quite some time.

Comparison of RS-232 and RS-485

The Modbus/RTU transmission options depend on the physical layer: RS-232 or RS-485. RS-232 is quite uncommon because it only supports point-to-point connections, meaning one Client and one Server. In contrast, RS-485 is a more flexible option; its technical specifications are outlined in the table below.

 RS-232RS-485
Operating modeasynchronous transmissionsynchronous transmission
Number of drives and receivers
per line
1 drive
1 receiver (point-to-point)
32 stations per segment
Data transfer methodhalf-duplex,
full-duplex
half duplex
Data transmissionp2pmultipoint
Max. cable length15 m1200 m
Max. data transfer
12 m
1200 m

20 kbps
(1 kbps)

35 Mbps
100 kbps
Receiver input
resistance
3..7 kΩ≧ 12 kΩ
Drive Load-
Impedance
3..7 kΩ54 Ω
Receiver “dead band”±3 V±200 mV
Receiver voltage level±15 V-7..+12 V
Drive output
voltage max.
±25 V–9..+14 V
Drive output
voltage min. (with load)
±5 V±1.5 V
Drive output
short circuit current limit
500 mA
to Vdc or Ground
150 mA to Ground
250 mA to Vdc
Receiver Hysteresis1.15 V50 mV

Modbus/RTU wiring

For Modbus/RTU communication, use RS-485 with either a 3-wire with shield or a 4-wire cable. To improve noise immunity, using shielded cables and twisted pairs is recommended. The units should be connected in a daisy-chain layout, though star topology can also work in some cases with a few units.

Modbus/RTU RS-485 wiring with end terminate

In a Modbus RTU network over RS-485, it is vital to terminate the bus to prevent signal reflections that can cause communication errors and CRC failures.

Guidelines on Proper Terminator Placement

Resistor Specifications

Modbus/RTU RS-485 Signaling

Modbus/RTU Signaling

In a Modbus/RTU network (which uses the RS-485 physical layer), A and B represent the two wires of a differential pair used to transmit data.

The Naming Confusion (A vs. B)

Since there is no universal naming standard, wiring errors are common. Terminal labels vary by manufacturer as follows:

Labeling ConventionNon-Inverting SignalInverting Signal
Common/ModbusB or B+A or A-
TIA/EIA-485 StandardA (Negative)B (Positive)
Alternate LabelsD+, Data+, Tx+D-, Data-, Tx-

Voltage Levels

If your devices have the correct baud rate and address but still can't communicate, try swapping the A and B wires on one side. This is a common cause of Modbus RTU setup failure and won't harm your hardware.

Modbus/RTU Speed (Baud Rate)

This is the transmission speed in bits per second (bps).

Modbus/RTU Data Format ("8N1")

Data Format 8N1:

This describes the structure of a single byte (character) sent over the wire. Totaling 10 bits per character:

Modbus/RTU Error Checking (CRC)

Even though “No Parity” (8N1) lacks bit-level checking, Modbus RTU is still secure because every full packet ends with a 16-bit CRC (Cyclic Redundancy Check). If a single bit is flipped during transmission due to noise, the CRC will fail, and the receiving device will ignore the command.

The CRC (Cyclic Redundancy Check) is an error-detection method that ensures data integrity in Modbus RTU. It is a 16-bit (2-byte) value appended to each message.

Key Characteristics

Modbus/TCP

Modbus/TCP (also known as Modbus TCP/IP) is a version of the Modbus protocol designed for Ethernet network communication. It wraps standard Modbus messages into TCP/IP packets, enabling reliable, high-speed data exchange.

Key Characteristics

Modbus/TCP and Modbus/RTU Hybrid

Modbus Registers and Coins

Modbus data is structured into four main “data banks” or “storage units”, categorized by whether the data is a single bit or a 16-bit word, and whether it is read-only or read-write.

Coils and Discrete Inputs are 1-bit variables. While a Coil can be read and written, a Discrete Input is only a read-only indicator of status.

Registers are 16-bit storage units: Holding registers are both writable and readable, and Input registers are read-only.

Although the Modbus standard allows Holding registers to be both read and written, many manufacturers restrict them to read-only. Always check the manufacturer’s specifications for accurate details.

Key Characteristics

Modbus Coin and Register Addressing

To index Modbus address ranges, a 5-digit address (e.g., 40001) was initially used. Over time, this was insufficient, as it allowed only 9,999 addresses per type. This was expanded to 6-digit addresses (e.g., 400001), offering 65,536 addresses aligned with Word boundaries. The first digit indicates the area type: 0x for Coils, 1x for Discrete Inputs, 3x for Input Registers, and 4x for Holding Registers.

Addressing within each range begins at 1, so the first holding register is 40001 or 400001. Users should note that many manufacturers use hexadecimal addresses, while Modbus/RTU uses decimal addresses. Larger data types (>16 bit, such as REAL, LREAL, DT, or STRING, WSTRING) span multiple registers for a single variable; thus, both the start address (offset, e.g., 400012) and the area length are specified.

Modbus Register short and long Addressing

Modbus Telegram Structure, ADU/PDU

In Modbus, the Application Data Unit (ADU) represents the complete message frame sent over a physical network. It functions as an “envelope” that encloses the Protocol Data Unit (PDU)—the main message with commands and data—while also including addressing and error-checking fields specific to the communication method.

The ADU's structure changes based on whether you're using Modbus RTU (serial) or Modbus TCP (Ethernet):

Modbus Telegram Structure, ADU and PDU

Modbus/TCP ADU (Ethernet)Modbus/RTU ADU (Serial)
MBAP Header (7 Bytes):
- Transaction ID (2 Bytes): Matches requests with responses.
- Protocol ID (2 Bytes): Always 0 for Modbus.
- Length (2 Bytes): Number of remaining bytes.
- Unit ID (1 Byte): Used for routing to serial devices through a gateway.
PDU (Function Code + Data): The core command.

Max Size: 260 bytes.
Slave Address (1 Byte): Identifies the target device (1–247).
PDU (Function Code + Data): The core command.
CRC (2 Bytes): A Cyclic Redundancy Check used to detect transmission errors.

Max Size: 256 bytes.

Error checking by Modbus/TCP is managed by the TCP layer and is not included in the ADU.

Modbus Protocol Data Unit (PDU)

The Modbus Protocol Data Unit (PDU) is the core message structure common to all Modbus variants (RTU, ASCII, and TCP). It defines the actual command and data being exchanged between a client and a server, independent of the network medium. The PDU consists of two primary fields with a maximum combined size of 253 bytes.

FieldSizeDescription
Function Code1 ByteTells the server which action to perform, such as Read, Write, Diagnostic.
Data Field0–252 BytesContains request details such as register addresses, quantities, or the actual data values being transmitted or returned.

Function Code Types

The function code ranges from 1 to 255 and is categorized by its purpose:

Data Field Structure

The structure of the data field changes depending on whether the PDU is part of a Request or a Response:

Data Encoding (Endianness)

Modbus uses Big-Endian representation for all 16-bit values within the PDU. This means the Most Significant Byte (MSB) is transmitted before the Least Significant Byte (LSB). Example: A register value of 0x1234 is sent as 0x12 followed by 0x34.

Modbus Function Codes

The table below details the standard Modbus function codes, which cover data access, diagnostics, and advanced functions used in both RTU and TCP variants. The first byte in a PDU is the Function Code, indicating the operation that the telegram performs.

Code (Hex)Code (Dec)Function NameData TypeAccess
0x0101Read CoilsBit (0x)Read
0x0202Read Discrete InputsBit (1x)Read
0x0303Read Holding Registers16-bit (4x)Read
0x0404Read Input Registers16-bit (3x)Read
0x0505Write Single CoilBit (0x)Write
0x0606Write Single Register16-bit (4x)Write
0x0707Read Exception StatusSerial OnlyRead
0x0808DiagnosticsInternalRead
0x0B11Get Comm Event CounterSerial OnlyRead
0x0C12Get Comm Event LogSerial OnlyRead
0x0F15Write Multiple CoilsBit (0x)Write
0x1016Write Multiple Registers16-bit (4x)Write
0x1117Report Server IDSerial OnlyRead
0x1420Read File RecordFileRead
0x1521Write File RecordFileWrite
0x1622Mask Write Register16-bit (4x)Write
0x1723Read/Write Multiple Registers16-bit (4x)R/W
0x1824Read FIFO Queue16-bitRead
0x2B43Read Device IdentificationInternalRead

Function Code Categories

Modbus test programs, test methods

Modbus Problems and errors

Simatic and Modbus

Scheme of Simatic

Simatic and Modbus RTU and/or TCP

Modbus Installation examples, step by step

S7-1500 and Easton Energymeter

S7-1500 and Arduino Uno R4

Arduino and Modbus

Arduino and Modbus RTU and/or TCP

Modbus Installation examples, step by step

Appendix