---
title: "Modbus RTU-to-TCP Gateway with W5500 and STM32"
url: "https://maker.wiznet.io/jakelee/resellers/modbus-rtu-to-tcp-gateway-with-w5500-and-stm32/"
markdown_url: "https://maker.wiznet.io/jakelee/resellers/modbus-rtu-to-tcp-gateway-with-w5500-and-stm32/md"
type: "VAR: Value-Added Reseller Products"
author: "Ethernet Lab (玩转以太网)"
author_url: "https://aiot.csdn.net/69df5ada0a2f6a37c5a014df.html"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Ethernet Lab (玩转以太网)"
original_url: "https://aiot.csdn.net/69df5ada0a2f6a37c5a014df.html"
published: "2026-06-07"
language: "en"
hardware: ["WIZnet W5500"]
likes: 0
views: 454
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# 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.

Original author: Ethernet Lab (玩转以太网) (source: https://aiot.csdn.net/69df5ada0a2f6a37c5a014df.html)

## Components

- **WIZnet W5500** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5500))

WIZnet parts: W5500 ([Datasheet](https://docs.wiznet.io/Product/Chip/Ethernet/W5500/datasheet?utm_source=maker&utm_medium=project&utm_campaign=w5500), [product hub](https://maker.wiznet.io/products/w5500/))

## Article

## 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

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

### Modbus TCP Frame

```plaintext
[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:

```plaintext
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:

```plaintext
// 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.

---

Source: https://maker.wiznet.io/jakelee/resellers/modbus-rtu-to-tcp-gateway-with-w5500-and-stm32/
