STM32 Ethernet Communication Tutorial using Wiznet W5500 Module
STM32 Ethernet Communication Tutorial using Wiznet W5500 Module
The article “Ethernet Communication using STM32 Microcontroller and Wiznet (Interrupt Mode)” from EmbeddedThere demonstrates how to build a TCP-based Ethernet communication system using the STM32F103C8T6 (Bluepill) and WIZnet W5500 Ethernet module.
The project focuses on implementing interrupt-driven TCP communication, leveraging the W5500’s hardware TCP/IP stack for non-blocking, efficient, and reliable data transfer.
Hardware Setup
- Microcontroller: STM32F103C8T6 (Bluepill)
- Ethernet Controller: WIZnet W5500
- Interface: SPI (PA4–PA7)
- Interrupt Pin: PB1 (Falling Edge)
- Reset Pin: PB0
- LED Indicator: PB9
- Power Supply: External 3.3V (recommended for W5500 stability)
This setup provides a simple yet effective hardware base for anyone looking to add wired Ethernet connectivity to embedded systems or IoT devices.
Project Workflow
- Create and configure the project using STM32CubeIDE
- Set up SPI1 and GPIO interrupt pin (PB1)
- Add the WIZnet driver library to the project
- Initialize and open a TCP server socket (default port 8080)
- Communicate with a PC client (e.g., using Hercules) over Ethernet
When a message “Hello” is received from the PC, the MCU toggles an LED and replies with a confirmation message — “Received from [socket]”.
This simple interaction effectively demonstrates how STM32 communicates through the W5500 hardware stack.
Software Architecture
W5500Init()- Registers SPI and control callbacks
- Performs hardware reset on the chip
- Allocates internal buffer memory
- Configures static network parameters (MAC, IP, gateway, subnet)
W5500_Enable_Interrupts()- Enables global and socket-level interrupts
- Monitors CON, DISCON, RECV, and TIMEOUT events for all sockets
HAL_GPIO_EXTI_Callback()- Triggered when W5500 pulls the INT pin low
- Calls
W5500_InterruptHandler()to read and clear interrupt flags
W5500_Handle_Events()- Iterates through sockets and checks event flags
- Invokes the appropriate handler (
handle_connection,handle_received, etc.) - Manages socket state transitions like reconnecting or closing
main.cLoop- Periodically calls
W5500_Handle_Events() - Detects “Hello” messages in the receive buffer, toggles the LED, and responds with acknowledgment
- Periodically calls
Key Features
- Interrupt-driven communication:
Efficient event handling with low CPU usage compared to polling. - Hardware TCP/IP processing:
W5500 manages the entire network protocol stack internally, freeing MCU resources. - STM32CubeIDE-based configuration:
Clean setup for SPI, EXTI, and GPIO via CubeMX graphical interface.
Conclusion
This project serves as a practical introduction to Ethernet communication using STM32 and WIZnet’s W5500 in interrupt mode.
By offloading TCP/IP tasks to the W5500 chip, developers can achieve stable and responsive network communication even on resource-limited microcontrollers.
It’s an excellent starting point for embedded engineers building IoT or industrial Ethernet applications with STM32.

