Modbus
Modbus is an open, mature, and straight forward communications protocol. It was originally published in 1979 by Modicon (Schneider Electric) and has since evolved into a standard communications protocol for industrial electronic devices.
Modbus was specifically designed to be used in supervisory control and data acquisition systems, connecting a supervisory computer with several remote terminal units (RTU). It therefore uses a master-slave-technique in which one device, the master, initiates transactions (called queries). Other devices, the slaves, respond by performing the action requested in the query and/or by supplying the requested data to the master.
See Wikipedia for further information.
emModbus
emModbus, SEGGER's implementation of the Modbus protocol, supports communication via UART (ASCII, RTU) and Ethernet (Modbus/TCP and Modbus/UDP) and is capable to communicate with any Modbus compliant device.
emModbus supports building master and slave devices, which can even be combined in the same product. Also, multiple interfaces in the same product are supported. Each interface can be configured at runtime, making it possible to build a pretested library to be deployed in multiple projects.
Easy to integrate.
Low memory footprint.
ANSI-C code is completely portable and runs on any target.
Follows the SEGGER coding standards: Efficient and compact, yet easy to read, understand & debug.
Supports ASCII, RTU and Modbus/TCP (and UDP) protocol.
Sample applications for all protocols included.
Kernel abstraction layer: can be used with or without any RTOS.
Works out-of-the-box with embOS.
Modbus/TCP can be used with standard socket interface and any TCP/IP stack.
Works out-of-the-box with embOS/IP.
Project for executable on PC for Microsoft Visual Studio available.
SEGGER offers emModbus in two distinct shipments, both of which are optimized for use in embedded systems.
Feature |
Master | Slave |
---|---|---|
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
|
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
TCP/IP stack
For usage of Modbus/TCP, emModbus requires a TCP/IP capable stack. emModbus can be used with any TCP/IP stack that supports BSD Standard Sockets.
Multi tasking
Although emModbus can be used completely without an RTOS it is recommended to use emModbus in a multi tasking system, at least when implementing a Modbus master.
ROM usage
emModbus requires approximately 2.5 KBytes of ROM for a master device and approximately 3 KBytes of ROM for a slave device.
RAM usage
emModus requires approximately 30 Bytes of RAM for the stack itself and approximately 300 Bytes of RAM for each channel added.
emModbus currently supports the following instructions:
Function code |
Description |
---|---|
1 |
Read Coil. |
2 |
Read Discrete Input. |
3 |
Read Holding Register. |
4 |
Read Input Register. |
5 |
Write Coil. |
6 |
Write Register. |
15 |
Write Coils. |
16 |
Write Registers. |
emModbus supports all three Modbus standard protocols covered by the official Modbus documentation:
Protocol |
Description |
---|---|
RTU |
Original Modbus standard. Binary data is sent via serial connections such as RS-232 or similar. |
ASCII |
Similar to RTU. Instead of raw binary, data is encoded in ASCII. |
Modbus/TCP |
Binary data is encapsulated in a TCP frame and sent via network connections such as Ethernet. This variant can also be used with UDP instead of TCP and is then called Modbus/UDP. |
Although the different message frames are each handled differently by the protocol, both RTU and ASCII frames consist of the same four specified fields. Field 2 and 3 constitute the Protocol Data Unit (PDU), which is included in the Modbus/TCP frame as well.
When using RTU frames, each byte contained in a message is sent as binary data. The main advantage of this mode is its greater density, allowing better data throughput for the same baud rate compared to ASCII frames.
When using ASCII frames, each byte contained in a message is encoded and sent as two ASCII characters. This allows time intervals of up to one second to occur between characters without causing an error.
Data type |
Description |
---|---|
Coil |
Single bit, alterable by an application program, read-write. |
Discrete Input |
Single bit, provided by an I/O system, read-only. |
Holding Register |
16-bit, alterable by an application program, read-write. |
Input Register |
16-bit, provided by an I/O system, read-only. |