AM263Px INDUSTRIAL COMMUNICATIONS SDK  2025.00.00
Modbus/TCP

Introduction

These examples act as Modbus/TCP server devices, responding to requests from Modbus/TCP clients by serving data through standard Modbus registers such as coils, discrete inputs, input registers, and holding registers. By using the NanoModbus library, developers can create lightweight, efficient Modbus/TCP servers suitable for embedded systems with limited resources.

  • The implementation consists of
    • Modbus/TCP Stack
    • NanoModbus Lib
    • ENET ICSSG (Ethernet Driver)
    • ENET CPSW (Ethernet Driver)
    • LwIP TCP/IP networking stack with SNMP support on top of ethernet driver
    • Modbus Server Application

Modbus/TCP Device Datasheet

Supported Modbus/TCP Functionality

Feature Description Implementation
Modbus/TCP Protocol Supports the Modbus/TCP protocol for communication between devices. Yes
Modbus Function Codes Supports a wide range of Modbus functions Yes
Modbus/TCP Server The stack supports being a Modbus/TCP Server. Yes
Modbus/TCP Client The stack supports being a Modbus/TCP Client. No
Exception Handling Supports exception handling for Modbus requests. Yes
Data Integrity Supports CRC and error checking mechanisms. No
Modbus/TCP over Ethernet The stack works over standard Ethernet interfaces for Modbus/TCP. Yes
Timeout Handling Supports configurable timeout values for Modbus transactions. Yes
Secure Modbus/TCP (SSL/TLS) Secure Modbus/TCP connections over SSL/TLS. No
Modbus/TCP over NanoModbus Support for using Modbus/TCP in a lightweight, optimized stack. Yes

Key Performance Parameters

Feature Detail Value
Maximum Connections Number of simultaneous Modbus TCP connections 4
Response Time Average time to respond to a Modbus request (from client to server) > 200ms
Error Detection and Recovery Modbus CRC error detection and error recovery mechanisms No
Max Data Length Maximum Modbus TCP message length supported 250 Bytes
Min Timeout Duration Modbus TCP timeout duration 10ms
Max Coils read per second Maximum number of coils that can be read per second 7957 coils
Max holding Registers read per second Maximum number of registers(125) to be read per second 986 registers
Max Coils write per second Maximum number of coils(1000) to be written per second 7986 coils
Max holding Registers write per second Maximum number of registers(123) to be written per second 979 registers
Max Coils write per second Maximum number of coils (1000) that can be written per second 7986 coils
Max Input Registers read per second Maximum number of registers(125) to be read per second 995 registers
Max discrete Inputs read per second Maximum number of registers(1000) to be read per second 7883 registers

General Stack Parameters

Supported Function Codes

Function Code Description Supported
01 Read Coils Yes
02 Read Discrete Inputs Yes
03 Read Holding Registers Yes
04 Read Input Registers Yes
05 Write Single Coil Yes
06 Write Single Register Yes
15 Write Multiple Coils Yes
16 Write Multiple Registers Yes

Stack Memory Usage

Demo Type Code RO Data RW Data
Modbus Server CPSW 161,79kB 38,49kB 456,03kB

Steps to Run the Example

Build the example

HW Setup

Note
Make sure you have setup the EVM with cable connections as shown here, EVM Setup. In addition do below steps.

AM263PX-LP

  • Connect an ethernet cable to the AM243X-LP from host PC as shown below

Ethernet cable for ICSS based ethernet

Run the example

Attention
If you need to reload and run the example again, EVM power-cycle is MUST.
  • Launch a CCS debug session and run the example executable, see CCS Launch, Load and Run
  • You will see logs in the UART terminal as shown in the next section.
  • Note the IP address seen in the log, this is what we will use to communicate with the EVM.
  • Open the Modbus tester tool, set the device’s IP address and port, and send Modbus requests, for instance request read holding register

UART Log

  • The application shows a message New MODBUS client connected once a TCP client requests to connect.

Sample Output

==========================
CPSW LWIP TCP CLIENT
==========================
EnetAppUtils_reduceCoreMacAllocation: Reduced Mac Address Allocation for CoreId:0 From 4 To 3
Open MAC port 1
EnetPhy_bindDriver:1935
PHY 3 is alive
PHY 12 is alive
Starting lwIP, local interface IP is dhcp-enabled
[LWIPIF_LWIP] NETIF INIT SUCCESS
Host MAC address-0 : 70:ff:76:1f:d0:19
[0]Enet IF UP Event. Local interface IP:0.0.0.0
[LWIPIF_LWIP] Enet has been started successfully
[0]Enet IF UP Event. Local interface IP:192.168.0.200
Waiting for network UP ...
Waiting for network UP ...
Waiting for network UP ...
Cpsw_handleLinkUp:1616
MAC Port 1: link up
[0]Network Link UP Event
Network is UP ...
CPU load = 0 %
CPU load = 0 %
New MODBUS client connected 70099AA0
CPU load = 0 %

Communicate with the LP using ethernet

  • Firstly you can try to reach the LP using ping as shown below, using a command shell on the host PC
        > ping 192.168.0.200
    

Reference

  • Modbus Application Protocol Specification, v1.1b3