Wiznet makers

jakelee

Published June 07, 2026 ©

19 UCC

4 VAR

0 Contests

0 Followers

0 Following

Original Link

Modbus RTU-to-TCP Gateway with W5500 and STM32

W5500 and STM32 enable seamless Modbus RTU-to-TCP conversion, bridging RS485 devices to Ethernet industrial networks.

COMPONENTS Hardware components

WIZnet - W5500

x 1


PROJECT DESCRIPTION

Step 1: Understanding the Hardware

This project demonstrates how to convert legacy Modbus RTU devices into Ethernet-connected Modbus TCP devices using an STM32 MCU and the WIZnet W5500 Ethernet controller.

Hardware used:

  • W5500io-M Ethernet module
  • STM32F103VCT6 development board
  • RS485 serial interface
  • Ethernet connection
  • Modbus RTU slave devices
  • Modbus TCP master software (Modbus Poll) 

The W5500io-M module offers:

  • Integrated MAC + PHY
  • Hardwired TCP/IP stack
  • 32KB internal buffer memory
  • RJ45 Ethernet interface
  • SPI host interface
  • 8 hardware sockets
  • Simplified Ethernet integration without porting a software TCP/IP stack to the MCU 

This architecture is particularly valuable for industrial automation systems where thousands of existing RS485 Modbus RTU devices still need connectivity to modern Ethernet networks.

Step 2: Understanding RTU-to-TCP Conversion

The core function of this project is protocol translation between Modbus RTU and Modbus TCP.

Modbus RTU Frame

 
[Slave Address][Function Code][Data][CRC16]
 

Modbus TCP Frame

 
[MBAP Header][Unit ID][Function Code][Data]
 

The conversion process works as follows:

RTU → TCP

  1. Remove CRC16 field
  2. Add MBAP header
  3. Preserve Unit ID
  4. Forward through Ethernet

TCP → RTU

  1. Remove MBAP header
  2. Extract Unit ID
  3. Calculate CRC16
  4. Rebuild RTU frame
  5. Send through RS485

This allows existing serial Modbus devices to communicate with Ethernet-based SCADA, PLC, and industrial monitoring systems.

Step 3: W5500 Ethernet Architecture

The W5500 acts as the Ethernet communication engine while the STM32 handles protocol conversion logic.

Architecture:

 
Modbus TCP Client
        │
        ▼
     Ethernet
        │
        ▼
      W5500
        │ SPI
        ▼
      STM32
        │ UART / RS485
        ▼
 Modbus RTU Device
 

Unlike software networking solutions, W5500 processes:

  • TCP
  • UDP
  • ARP
  • ICMP
  • Socket management

in hardware.

This significantly reduces STM32 firmware complexity and frees MCU resources for protocol conversion and industrial control tasks.

Step 4: Firmware Integration

The project modifies WIZnet's loopback TCP server example to perform Modbus protocol translation.

Conceptual initialization:

 
// Conceptual example based on WIZnet ioLibrary
// Not project-specific source code

uint8_t tx_size[] = {2,2,2,2,2,2,2,2};
uint8_t rx_size[] = {2,2,2,2,2,2,2,2};

void ethernet_init(void)
{
    wizchip_init(tx_size, rx_size);

    wiz_NetInfo netinfo = {
        .ip = {192,168,1,100},
        .sn = {255,255,255,0},
        .gw = {192,168,1,1}
    };

    wizchip_setnetinfo(&netinfo);
}
 

The implementation extends the TCP server loop to:

  • Receive Modbus TCP requests
  • Convert TCP frames into RTU frames
  • Forward data over UART/RS485
  • Receive RTU responses
  • Validate CRC16
  • Convert RTU responses into TCP packets
  • Return data to the Modbus TCP client 

Step 5: Industrial Applications

This gateway architecture is ideal for:

  • PLC modernization
  • Factory automation
  • Building automation
  • Energy monitoring systems
  • EV charging infrastructure
  • Smart grid deployments
  • Industrial data acquisition
  • SCADA integration

Instead of replacing existing Modbus RTU equipment, developers can use W5500-based gateways to connect legacy assets to modern Ethernet networks.

FAQ

Q1: Why use W5500 for Modbus gateways?

A: W5500 provides a hardwired TCP/IP stack that eliminates the need to port and maintain a complex software networking stack. This reduces development time, improves reliability, and allows the STM32 to focus on protocol conversion and application logic.

Q2: What are the benefits of converting Modbus RTU to Modbus TCP?

A: Modbus TCP enables higher-speed Ethernet communication, remote access, and easier integration with SCADA and industrial management systems while preserving compatibility with existing Modbus RTU devices.

Q3: Where is this architecture commonly deployed?

A: Typical deployments include factory automation, smart energy systems, charging stations, industrial monitoring, building management systems, and legacy equipment modernization projects requiring Ethernet connectivity.

Documents
Comments Write