Skip to content

W5500Ethernet

A lightweight W5500 Ethernet library for STM32 microcontrollers, compatible with the official STM32duino Arduino core. Built and tested on STM32F446RE

Lihan__

Published May 08, 2026

Original author: Amir13600631Original source (new tab)

W5500Ethernet

Project description

 

 
W5500Ethernet

W5500Ethernet โ€” Production-Grade STM32 Ethernet Library Built for Industrial Modbus TCP

#STM32 #W5500 #WIZ550io #ModbusTCP #STM32duino #ioLibrary #Industrial #BareMetal #ArduinoCore #Embedded

๐Ÿ“š Independent open-source library by an industrial control systems engineer. ioLibrary-compatible API, reimplemented for STM32duino Arduino core. Hardware-verified on STM32F446RE + WIZ550io.


01 โ€” What is this project?

Getting Ethernet to work reliably on STM32 with the Arduino ecosystem has always been a frustrating experience. The official STM32Ethernet library only supports Nucleo-144 boards with built-in MAC + LAN8742A PHY โ€” which excludes every Nucleo-64, every Blue Pill, and every custom STM32 board that uses an external SPI Ethernet module. WIZnet's official ioLibrary exists, but it cannot be used directly in the Arduino environment. Third-party W5500 libraries exist, but each one targets an outdated core, requires manual header editing, or pulls in heavy dependencies.

This project delivers what the ecosystem has been missing: a lightweight, production-tested W5500 Ethernet library purpose-built for STM32 + STM32duino, with Modbus TCP slave and master built in. It compiles and runs out of the box on STM32F446RE Nucleo-64 with a WIZ550io module โ€” no header surgery, no dependency chains, no cryptic SPI framing bugs.

The library was developed as part of a complete bare-metal industrial control firmware project: custom SPI/DMA drivers, ADC DMA scanning with IIR filtering, bxCAN bus driver, and a Modbus TCP gateway. The Ethernet layer was extracted, cleaned up, and released as a focused open-source library so other engineers facing the same STM32 + W5500 wall can get past it in minutes instead of weeks.


02 โ€” Why a new STM32 W5500 library?

๐Ÿ”ท Existing libraries don't actually work on modern STM32duino

The community has multiple W5500 libraries โ€” Ethernet_STM32, Ethernet_STM, EthernetWebServer_STM32, the official Arduino Ethernet library โ€” and not one of them compiles and runs on a Nucleo-64 with the current STM32duino core and a W5500 module without non-trivial modifications. Older cores, manual header edits, outdated SPI handling, missing chip select logic. This library was written from scratch only after exhausting every existing option.

๐Ÿ”ท Correct BSB SPI framing โ€” the silent killer

W5500 uses Block Select Bits (BSB) in its SPI protocol to address registers, sockets, and buffers. Most generic Arduino W5500 implementations get this subtly wrong on STM32, causing the W5500 to silently reject SOCKET OPEN commands even though all register reads and writes appear to succeed. This is one of the most painful bugs in embedded networking. This library implements BSB-aware framing correctly from the register layer up.

๐Ÿ”ท Zero dynamic memory allocation

No new. No malloc. No heap. Every buffer is statically allocated, every state machine is explicit. This is non-negotiable for industrial firmware โ€” the kind that runs unattended on a DIN rail for years and cannot afford a heap fragmentation surprise.

๐Ÿ”ท API-compatible with WIZnet's official ioLibrary โ€” without the integration friction

The function names (wizchip_init(), wizchip_setnetinfo(), wiz_NetInfo) and module layout (w5500.cpp, socket.cpp, wizchip_conf.cpp) mirror WIZnet's official open-source ioLibrary. So why not just use ioLibrary?

ioLibrary is a standard C library, designed for STM32CubeIDE / CMake / HAL-based projects where the developer registers their own SPI driver function via callback (reg_wizchip_spi_cbfunc()). It assumes a traditional C-style embedded build environment. The Arduino ecosystem โ€” including STM32duino, the official Arduino core for STM32 boards maintained by STMicroelectronics โ€” is not that environment. Arduino expects .cpp files that include <Arduino.h>, direct use of the SPI.transfer() and digitalWrite() APIs, library-manager-discoverable metadata, and a build system that does not align with ioLibrary's callback-registration model.

This library takes ioLibrary's proven API design and reimplements the SPI/socket layer natively for Arduino. Engineers already familiar with ioLibrary recognize every function name. Arduino users get a library that compiles out of the box. Same API, two ecosystems.


03 โ€” System architecture

03 โ€” System architecture

04 โ€” Why W5500 (and WIZ550io)?

๐Ÿ”ท STM32 Nucleo-64 has no built-in Ethernet PHY

Nucleo-64 boards (F446RE, F401RE, F411RE, F103) and most STM32 development/custom boards do not have an integrated Ethernet MAC + PHY. The only practical path to wired Ethernet is an external SPI module. W5500 is the cleanest answer โ€” a complete TCP/IP offload engine over a 4-wire SPI interface that maps directly to STM32 GPIO.

๐Ÿ”ท Hardwired TCP/IP stack โ€” deterministic, no LwIP

Unlike software-based Ethernet solutions that require LwIP (memory-hungry, configuration-heavy, deep call stacks), W5500 runs the entire TCP/IP stack in silicon. No LwIP dependency, no ETH_FUNCTIONS macros, no LAN8742A_PHY_ADDRESS symbol errors. Just SPI commands and 8 hardware sockets.

๐Ÿ”ท WIZ550io โ€” single-module integration

WIZ550io combines W5500 + magnetics + RJ45 into a single drop-in module. For a Nucleo-64 + breadboard prototype or a small custom industrial PCB, this collapses the Ethernet hardware to a single component connection. No separate magnetics, no impedance matching, no PHY clock issues.

๐Ÿ”ท Verified hardware behavior

Hardware evidence built into the library development:

  • โœ… Correct BSB framing verified across all socket-mode commands
  • โœ… SOCKET OPEN succeeds reliably (the failure mode that breaks competing libraries)
  • โœ… Static IP, MAC, gateway, subnet configuration round-trip verified
  • โœ… PHY link status detection working
  • โœ… Modbus TCP slave tested with Modbus Poll
  • โœ… Modbus TCP master tested with Modbus Slave simulator
  • โœ… Auto-reconnect after physical cable disconnect verified

05 โ€” Key components

๐Ÿง  STM32F446RE (Nucleo-64) โ€” Reference Platform

180MHz Cortex-M4 with FPU. Compiled with the official STM32duino Arduino core. Also verified compatible with STM32F446ZE Nucleo-144, STM32F103C8 Blue Pill, and any STM32 with adjustable CS pin. Custom bare-metal core also tested for the same chip.

๐ŸŒ WIZnet W5500 / WIZ550io โ€” Ethernet Interface

The W5500 is operated via a custom SPI master implemented in w5500.cpp. The driver speaks correct BSB framing, addresses all 8 hardware sockets independently, and exposes a clean register-level API to the layers above. WIZ550io's integrated magnetics simplify hardware bring-up.

๐Ÿ“ฆ TCP Server (server.cpp)

Single-listener TCP server with automatic re-arm on disconnect. Designed for the industrial use case: one persistent client (a PLC, SCADA terminal, or gateway) connects, talks Modbus, disconnects, and the server immediately re-listens.

๐Ÿ“ฆ TCP Client (client.cpp)

Persistent TCP client with auto-reconnect. Survives cable pulls, switch reboots, and remote-server restarts โ€” reconnects on the next loop tick without intervention.

โš–๏ธ Modbus TCP Slave (FC03 + FC16)

Built into the server. Handles Read Holding Registers and Write Multiple Registers. Returns proper MBAP exception responses for invalid function codes or out-of-range addresses. Tested end-to-end with Modbus Poll simulator.

โš–๏ธ Modbus TCP Master

Built into the client. Polls a remote slave with persistent connection, reconnects on failure. Tested with Modbus Slave simulator polling 5 holding registers every 2 seconds.

๐Ÿงช Three Working Examples

  • 01_ethernet_netinfo โ€” link-up smoke test
  • 02_modbus_client โ€” Modbus TCP master
  • 03_modbus_server โ€” Modbus TCP slave on port 1502

All three verified on real STM32F446RE hardware.


06 โ€” Application scenarios

01. Industrial Modbus TCP Gateway

The native use case. STM32 + W5500 + this library = a deterministic, bare-metal Modbus TCP gateway between an industrial network and field devices. Zero-heap, zero-OS, zero-surprise. The author built exactly this for industrial control deployment. #Modbus #Industrial #SCADA #PLCIntegration

02. STM32 Nucleo-64 Wired IoT Endpoints

Most STM32 IoT tutorials assume Nucleo-144 (built-in MAC) or push you to ESP32. This library opens up the entire Nucleo-64 line โ€” and any custom STM32 board โ€” for wired Ethernet IoT applications without WiFi's reliability and security tradeoffs. #IoT #Nucleo64 #WiredEthernet

03. Bare-Metal Embedded Networking

Engineers writing custom STM32 cores or working below the Arduino abstraction get a clean, heap-free, BSB-correct W5500 driver they can lift into their own projects. No Arduino assumptions baked in below the SPI layer. #BareMetal #EmbeddedSystems #Driver

04. STM32 + W5500 Reference Implementation

Educational and reference use. The library shows correct W5500 SPI framing on STM32, correct timing for SPI clock prescalers, correct CS handling, and a clean separation between hardware layer and protocol layer. A solid teaching example for embedded networking courses. #Education #Reference #OpenSource


Conclusion

Production-grade STM32 + W5500 Ethernet, finally โ€” with Modbus TCP built in and zero heap.

This project closes a real gap in the STM32 + Arduino ecosystem. After years of community libraries that almost work, a control systems engineer wrote, hardware-verified, and open-sourced a focused W5500 driver that actually compiles, actually runs, and actually ships in industrial firmware. The decision tree is simple: if you have an STM32 (any model) and a W5500 module and you want Ethernet without LwIP, this library is the path of least resistance.

The Modbus TCP slave and master are the showcase โ€” but the real value is the underlying W5500 driver, which any embedded engineer can build on for HTTP, MQTT, custom binary protocols, or any other TCP/UDP application.

  • โœ… Correct BSB-aware SPI framing โ€” solves the silent SOCKET OPEN failure
  • โœ… Zero dynamic memory allocation, zero heap, zero new/malloc
  • โœ… API-compatible with WIZnet's official ioLibrary (wizchip_init, wiz_NetInfo, etc.)
  • โœ… Single file include (#include <W5500Ethernet.h>)
  • โœ… Built-in Modbus TCP slave (FC03, FC16) with MBAP exception handling
  • โœ… Built-in Modbus TCP master with persistent connection and auto-reconnect
  • โœ… TCP server with single-listener auto re-arm
  • โœ… TCP client with auto-reconnect
  • โœ… Hardware verified on STM32F446RE Nucleo-64 + WIZ550io
  • โœ… Compatible with STM32F446ZE, STM32F103, custom STM32 boards
  • โœ… MIT License โ€” usable in commercial products

Q&A

Q. Why not just use the official STM32Ethernet library? The official library only supports STM32 boards with built-in MAC + LAN8742A PHY (Nucleo-144 family). For Nucleo-64, Blue Pill, or any board using an external SPI Ethernet module, that library simply does not apply โ€” it has no W5500 support at all. Open issues on its GitHub repository show recurring LAN8742A_PHY_ADDRESS and PHY_IMR symbol errors even on supported boards. This library exists to fill the SPI Ethernet gap that the official library never addressed.

Q. What is BSB framing and why does it matter? W5500 uses Block Select Bits (BSB) in the second byte of every SPI transaction to address one of eight hardware sockets, common registers, or socket-specific buffers. If the BSB field is constructed incorrectly, register reads and writes appear to work โ€” they return values, they accept writes โ€” but socket-level commands like SOCKET OPEN fail silently. The socket never enters the listening state, no incoming connections are accepted, and there is no error indication. This library implements BSB framing correctly so that pattern can never occur.

Q. Why not just use WIZnet's official ioLibrary directly? ioLibrary is a standard C library built for STM32CubeIDE / CMake / HAL-based projects โ€” it expects the developer to register their own SPI driver as a callback. The Arduino ecosystem has a completely different build model: .cpp files including <Arduino.h>, the SPI and digitalWrite APIs, library-manager metadata, no callback registration. You cannot drop ioLibrary into an Arduino project as-is. STM32 does have Arduino support via STM32duino (the official Arduino core for STM32 boards, maintained by STMicroelectronics), but that doesn't bridge the build-system gap โ€” ioLibrary still needs a substantial integration layer to live there. This library solves that once: same ioLibrary API surface, reimplemented natively for Arduino. ioLibrary users keep their muscle memory, Arduino users get a library that compiles out of the box.

Q. Why no DHCP, DNS, or UDP? This library targets industrial deployment where every endpoint has a static IP, IP addresses are used directly (no DNS), and the protocol is TCP (Modbus TCP). Adding DHCP, DNS, and UDP would expand the code size and dependency surface for features that the target use case does not need. Engineers who need those features can either use the W5500 layer directly (the SPI driver is exposed) or add them on top. This is intentional scoping, not an oversight.

Q. Can I use this with ArduinoModbus or other Arduino TCP libraries? Not directly today โ€” the API uses explicit socket-number functions (EthernetClient_write_array(sock, buf, len)) rather than the standard Arduino EthernetClient / Stream interface. The author notes a thin C++ wrapper providing those interfaces is a planned future addition. For now, if you need ArduinoModbus compatibility, you can wrap the C-style API yourself, or use the Modbus TCP slave/master that ships with this library and skip ArduinoModbus entirely.

Q. What is the SPI clock speed and is it safe? The Quick Start example uses 11.25 MHz SPI, which works reliably on the STM32F446RE + WIZ550io combination. The README warns that SPI wires must be kept under 10 cm โ€” long unshielded wires at 11 MHz cause signal integrity issues that make the W5500 socket state machine silently reject OPEN commands. This is one of the trickiest bugs in W5500 bring-up, and the library documents it explicitly so users avoid it on their own hardware.



[ํ•œ๊ธ€ ๋ฒ„์ „]

W5500Ethernet โ€” ์‚ฐ์—…์šฉ Modbus TCP๋ฅผ ์œ„ํ•œ STM32 ์ด๋”๋„ท ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

#STM32 #W5500 #WIZ550io #ModbusTCP #STM32duino #ioLibrary #์‚ฐ์—…์šฉ #๋ฒ ์–ด๋ฉ”ํƒˆ #์•„๋‘์ด๋…ธ์ฝ”์–ด #์ž„๋ฒ ๋””๋“œ

๐Ÿ“š ์‚ฐ์—… ์ œ์–ด ์‹œ์Šคํ…œ ์—”์ง€๋‹ˆ์–ด๊ฐ€ ๋งŒ๋“  ๋…๋ฆฝ ์˜คํ”ˆ์†Œ์Šค ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ. ioLibrary ํ˜ธํ™˜ API๋ฅผ STM32duino Arduino ์ฝ”์–ด์šฉ์œผ๋กœ ์žฌ๊ตฌํ˜„. STM32F446RE + WIZ550io๋กœ ํ•˜๋“œ์›จ์–ด ๊ฒ€์ฆ ์™„๋ฃŒ.


01 โ€” ์ด ํ”„๋กœ์ ํŠธ๋Š” ๋ฌด์—‡์ธ๊ฐ€?

STM32์—์„œ Arduino ์ƒํƒœ๊ณ„๋กœ ์ด๋”๋„ท์„ ์•ˆ์ •์ ์œผ๋กœ ๋™์ž‘์‹œํ‚ค๋Š” ์ผ์€ ํ•ญ์ƒ ๋‹ต๋‹ตํ•œ ๊ฒฝํ—˜์ด์—ˆ์Šต๋‹ˆ๋‹ค. ๊ณต์‹ STM32Ethernet ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋‚ด์žฅ MAC + LAN8742A PHY๋ฅผ ๊ฐ€์ง„ Nucleo-144 ๋ณด๋“œ๋งŒ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค โ€” ์ฆ‰ ๋ชจ๋“  Nucleo-64, ๋ชจ๋“  Blue Pill, ์™ธ๋ถ€ SPI ์ด๋”๋„ท ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“  ์ปค์Šคํ…€ STM32 ๋ณด๋“œ๋Š” ์ œ์™ธ๋ฉ๋‹ˆ๋‹ค. ์œ„์ฆˆ๋„คํŠธ์—์„œ ์ œ๊ณตํ•˜๋Š” ioLibrary๊ฐ€ ์žˆ์ง€๋งŒ Arduino ํ™˜๊ฒฝ์—์„œ๋Š” ์‚ฌ์šฉ์ด ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์„œ๋“œํŒŒํ‹ฐ W5500 ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์กด์žฌํ•˜์ง€๋งŒ, ๊ฐ๊ฐ ๊ตฌ๋ฒ„์ „ ์ฝ”์–ด๋ฅผ ํƒ€๊ฒŸํŒ…ํ•˜๊ฑฐ๋‚˜, ํ—ค๋” ํŒŒ์ผ์„ ์ˆ˜๋™์œผ๋กœ ํŽธ์ง‘ํ•ด์•ผ ํ•˜๊ฑฐ๋‚˜, ๋ฌด๊ฑฐ์šด ์˜์กด์„ฑ์„ ๋Œ์–ด๋“ค์ž…๋‹ˆ๋‹ค.

์ด ํ”„๋กœ์ ํŠธ๋Š” ์ƒํƒœ๊ณ„์— ๋น„์–ด ์žˆ๋˜ ๊ฒƒ์„ ์ฑ„์›๋‹ˆ๋‹ค: STM32 + STM32duino๋ฅผ ์œ„ํ•ด ์ฒ˜์Œ๋ถ€ํ„ฐ ์„ค๊ณ„๋œ ๊ฐ€๋ณ๊ณ  ํ”„๋กœ๋•์…˜ ๊ฒ€์ฆ๋œ W5500 ์ด๋”๋„ท ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, Modbus TCP ์Šฌ๋ ˆ์ด๋ธŒ์™€ ๋งˆ์Šคํ„ฐ ๋‚ด์žฅ. STM32F446RE Nucleo-64 + WIZ550io ๋ชจ๋“ˆ์—์„œ ๊ทธ๋Œ€๋กœ ์ปดํŒŒ์ผ๋˜๊ณ  ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค โ€” ํ—ค๋” ์ˆ˜์ˆ  ์—†์Œ, ์˜์กด์„ฑ ์‚ฌ์Šฌ ์—†์Œ, ์ •์ฒด๋ถˆ๋ช…์˜ SPI ํ”„๋ ˆ์ด๋ฐ ๋ฒ„๊ทธ ์—†์Œ.

์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์™„์ „ํ•œ ๋ฒ ์–ด๋ฉ”ํƒˆ ์‚ฐ์—… ์ œ์–ด ํŽŒ์›จ์–ด ํ”„๋กœ์ ํŠธ์˜ ์ผ๋ถ€๋กœ ๊ฐœ๋ฐœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค: ์ปค์Šคํ…€ SPI/DMA ๋“œ๋ผ์ด๋ฒ„, IIR ํ•„ํ„ฐ๋ง์ด ์žˆ๋Š” ADC DMA ์Šค์บ๋‹, bxCAN ๋ฒ„์Šค ๋“œ๋ผ์ด๋ฒ„, Modbus TCP ๊ฒŒ์ดํŠธ์›จ์ด. ์ด๋”๋„ท ๊ณ„์ธต์„ ๋ถ„๋ฆฌํ•ด ์ •๋ฆฌํ•œ ๋’ค ์˜คํ”ˆ์†Œ์Šค๋กœ ๊ณต๊ฐœํ•ด, ๊ฐ™์€ STM32 + W5500 ๋ฒฝ์— ๋ถ€๋”ชํžŒ ๋‹ค๋ฅธ ์—”์ง€๋‹ˆ์–ด๋“ค์ด ๋ช‡ ์ฃผ๊ฐ€ ์•„๋‹ˆ๋ผ ๋ช‡ ๋ถ„ ๋งŒ์— ๊ทธ ๋ฒฝ์„ ๋„˜์„ ์ˆ˜ ์žˆ๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค.


02 โ€” ์™œ ์ƒˆ๋กœ์šด STM32 W5500 ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ํ•„์š”ํ•œ๊ฐ€?

๐Ÿ”ท ๊ธฐ์กด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์€ ํ˜„๋Œ€ STM32duino์—์„œ ์‹ค์ œ๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š๋Š”๋‹ค

์ปค๋ฎค๋‹ˆํ‹ฐ์—๋Š” ์—ฌ๋Ÿฌ W5500 ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค โ€” Ethernet_STM32, Ethernet_STM, EthernetWebServer_STM32, ๊ณต์‹ Arduino Ethernet โ€” ํ•˜์ง€๋งŒ ๊ทธ์ค‘ ์–ด๋А ๊ฒƒ๋„ ํ˜„์žฌ STM32duino ์ฝ”์–ด์™€ W5500 ๋ชจ๋“ˆ์„ ๊ฐ€์ง„ Nucleo-64์—์„œ ์‚ฌ์†Œํ•˜์ง€ ์•Š์€ ์ˆ˜์ • ์—†์ด ์ปดํŒŒ์ผ๋˜๊ณ  ๋™์ž‘ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ตฌ๋ฒ„์ „ ์ฝ”์–ด ํƒ€๊ฒŸํŒ…, ์ˆ˜๋™ ํ—ค๋” ํŽธ์ง‘, ๊ตฌ์‹ SPI ์ฒ˜๋ฆฌ, ๋ˆ„๋ฝ๋œ ์นฉ ์…€๋ ‰ํŠธ ๋กœ์ง. ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋ชจ๋“  ๊ธฐ์กด ์˜ต์…˜์„ ์†Œ์ง„ํ•œ ๋’ค์—์•ผ ์ฒ˜์Œ๋ถ€ํ„ฐ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ”ท ์ •ํ™•ํ•œ BSB SPI ํ”„๋ ˆ์ด๋ฐ โ€” ์นจ๋ฌต์˜ ์‚ด์ธ์ž

W5500์€ SPI ํ”„๋กœํ† ์ฝœ์—์„œ ๋ ˆ์ง€์Šคํ„ฐ, ์†Œ์ผ“, ๋ฒ„ํผ๋ฅผ ์ฃผ์†Œ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•ด Block Select Bits (BSB)๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ์ผ๋ฐ˜์ ์ธ Arduino W5500 ๊ตฌํ˜„์€ STM32์—์„œ ์ด ๋ถ€๋ถ„์„ ๋ฏธ๋ฌ˜ํ•˜๊ฒŒ ์ž˜๋ชป ์ฒ˜๋ฆฌํ•ด, ๋ชจ๋“  ๋ ˆ์ง€์Šคํ„ฐ ์ฝ๊ธฐ/์“ฐ๊ธฐ๋Š” ์„ฑ๊ณตํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด๋Š”๋ฐ๋„ W5500์ด SOCKET OPEN ๋ช…๋ น์„ ์กฐ์šฉํžˆ ๊ฑฐ๋ถ€ํ•˜๋Š” ์ƒํ™ฉ์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์ž„๋ฒ ๋””๋“œ ๋„คํŠธ์›Œํ‚น์—์„œ ๊ฐ€์žฅ ๊ณ ํ†ต์Šค๋Ÿฌ์šด ๋ฒ„๊ทธ ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค. ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋ ˆ์ง€์Šคํ„ฐ ๊ณ„์ธต๋ถ€ํ„ฐ BSB-aware ํ”„๋ ˆ์ด๋ฐ์„ ์ •ํ™•ํžˆ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ”ท ๋™์  ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น ์ œ๋กœ

new ์—†์Œ. malloc ์—†์Œ. ํž™ ์—†์Œ. ๋ชจ๋“  ๋ฒ„ํผ๋Š” ์ •์  ํ• ๋‹น, ๋ชจ๋“  ์ƒํƒœ ๋จธ์‹ ์€ ๋ช…์‹œ์ . ์ด๋Š” ์‚ฐ์—… ํŽŒ์›จ์–ด์—์„œ ํƒ€ํ˜‘ ๋ถˆ๊ฐ€๋Šฅํ•œ ์š”๊ฑด์ž…๋‹ˆ๋‹ค โ€” DIN ๋ ˆ์ผ์— ๋ฌด์ธ์œผ๋กœ ๋ช‡ ๋…„์”ฉ ๋™์ž‘ํ•˜๋ฉฐ ํž™ ๋‹จํŽธํ™” ๊ฐ™์€ ๊นœ์ง ์ด๋ฒคํŠธ๋ฅผ ๊ฐ๋‹นํ•  ์ˆ˜ ์—†๋Š” ์ข…๋ฅ˜์˜ ํŽŒ์›จ์–ด์ž…๋‹ˆ๋‹ค.

๐Ÿ”ท WIZnet ๊ณต์‹ ioLibrary์™€ API ํ˜ธํ™˜ โ€” ํ†ตํ•ฉ ๋งˆ์ฐฐ ์—†์ด

ํ•จ์ˆ˜ ์ด๋ฆ„(wizchip_init(), wizchip_setnetinfo(), wiz_NetInfo)๊ณผ ๋ชจ๋“ˆ ๋ ˆ์ด์•„์›ƒ(w5500.cpp, socket.cpp, wizchip_conf.cpp)์€ WIZnet ๊ณต์‹ ์˜คํ”ˆ์†Œ์Šค ioLibrary์™€ ๋™์ผํ•œ ๊ตฌ์กฐ์ž…๋‹ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ioLibrary๋ฅผ ์ง์ ‘ ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ์ด์œ ๋Š”?

ioLibrary๋Š” ํ‘œ์ค€ C ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ, STM32CubeIDE / CMake / HAL ๊ธฐ๋ฐ˜ ํ”„๋กœ์ ํŠธ์šฉ์œผ๋กœ ์„ค๊ณ„๋˜์—ˆ์Šต๋‹ˆ๋‹ค โ€” ๊ฐœ๋ฐœ์ž๊ฐ€ ์ž์‹ ์˜ SPI ๋“œ๋ผ์ด๋ฒ„ ํ•จ์ˆ˜๋ฅผ ์ฝœ๋ฐฑ(reg_wizchip_spi_cbfunc())์œผ๋กœ ๋“ฑ๋กํ•˜๋Š” ํ™˜๊ฒฝ์ž…๋‹ˆ๋‹ค. ์ „ํ†ต์ ์ธ C ์Šคํƒ€์ผ ์ž„๋ฒ ๋””๋“œ ๋นŒ๋“œ ํ™˜๊ฒฝ์„ ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค. Arduino ์ƒํƒœ๊ณ„ โ€” STMicroelectronics๊ฐ€ ๊ณต์‹์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๋Š” STM32 ๋ณด๋“œ์šฉ Arduino ์ฝ”์–ด์ธ STM32duino๋ฅผ ํฌํ•จํ•ด โ€” ๋Š” ๊ทธ ํ™˜๊ฒฝ์ด ์•„๋‹™๋‹ˆ๋‹ค. Arduino๋Š” <Arduino.h>๋ฅผ ์ธํด๋ฃจ๋“œํ•˜๋Š” .cpp ํŒŒ์ผ, SPI.transfer()์™€ digitalWrite() API์˜ ์ง์ ‘ ์‚ฌ์šฉ, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋งค๋‹ˆ์ €๊ฐ€ ๋ฐœ๊ฒฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ, ๊ทธ๋ฆฌ๊ณ  ioLibrary์˜ ์ฝœ๋ฐฑ ๋“ฑ๋ก ๋ชจ๋ธ๊ณผ ๋งž์ง€ ์•Š๋Š” ๋นŒ๋“œ ์‹œ์Šคํ…œ์„ ๊ธฐ๋Œ€ํ•ฉ๋‹ˆ๋‹ค.

์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ioLibrary์˜ ๊ฒ€์ฆ๋œ API ์„ค๊ณ„๋ฅผ ๊ฐ€์ ธ์™€ SPI/์†Œ์ผ“ ๋ ˆ์ด์–ด๋ฅผ Arduino์šฉ์œผ๋กœ ๋„ค์ดํ‹ฐ๋ธŒํ•˜๊ฒŒ ์žฌ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค. ioLibrary์— ์ต์ˆ™ํ•œ ์—”์ง€๋‹ˆ์–ด๋Š” ๋ชจ๋“  ํ•จ์ˆ˜ ์ด๋ฆ„์„ ์•Œ์•„๋ด…๋‹ˆ๋‹ค. Arduino ์‚ฌ์šฉ์ž๋Š” ์ฆ‰์‹œ ์ปดํŒŒ์ผ๋˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์–ป์Šต๋‹ˆ๋‹ค. ๊ฐ™์€ API, ๋‘ ์ƒํƒœ๊ณ„.


03 โ€” ์‹œ์Šคํ…œ ๊ตฌ์กฐ

03 โ€” ์‹œ์Šคํ…œ ๊ตฌ์กฐ

04 โ€” ์™œ W5500 (๊ทธ๋ฆฌ๊ณ  WIZ550io)์ธ๊ฐ€?

๐Ÿ”ท STM32 Nucleo-64์—๋Š” ๋‚ด์žฅ ์ด๋”๋„ท PHY๊ฐ€ ์—†๋‹ค

Nucleo-64 ๋ณด๋“œ(F446RE, F401RE, F411RE, F103)์™€ ๋Œ€๋ถ€๋ถ„์˜ STM32 ๊ฐœ๋ฐœ/์ปค์Šคํ…€ ๋ณด๋“œ๋Š” ํ†ตํ•ฉ ์ด๋”๋„ท MAC + PHY๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์œ ์„  ์ด๋”๋„ท์œผ๋กœ ๊ฐ€๋Š” ์œ ์ผํ•œ ์‹ค์šฉ์  ๊ฒฝ๋กœ๋Š” ์™ธ๋ถ€ SPI ๋ชจ๋“ˆ์ž…๋‹ˆ๋‹ค. W5500์ด ๊ฐ€์žฅ ๊น”๋”ํ•œ ๋‹ต์ž…๋‹ˆ๋‹ค โ€” STM32 GPIO์— ๊ทธ๋Œ€๋กœ ๋งคํ•‘๋˜๋Š” 4์„  SPI ์ธํ„ฐํŽ˜์ด์Šค ์œ„์— ๋™์ž‘ํ•˜๋Š” ์™„์ „ํ•œ TCP/IP ์˜คํ”„๋กœ๋“œ ์—”์ง„.

๐Ÿ”ท ํ•˜๋“œ์›จ์–ด TCP/IP ์Šคํƒ โ€” ๊ฒฐ์ •๋ก ์ , LwIP ๋ถˆํ•„์š”

LwIP๋ฅผ ์š”๊ตฌํ•˜๋Š” ์†Œํ”„ํŠธ์›จ์–ด ๊ธฐ๋ฐ˜ ์ด๋”๋„ท ์†”๋ฃจ์…˜(๋ฉ”๋ชจ๋ฆฌ ์†Œ๋ชจ ํผ, ์„ค์ • ๋ณต์žก, ๊นŠ์€ ์ฝœ ์Šคํƒ)๊ณผ ๋‹ฌ๋ฆฌ, W5500์€ ์ „์ฒด TCP/IP ์Šคํƒ์„ ์‹ค๋ฆฌ์ฝ˜์—์„œ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. LwIP ์˜์กด์„ฑ ์—†์Œ, ETH_FUNCTIONS ๋งคํฌ๋กœ ์—†์Œ, LAN8742A_PHY_ADDRESS ์‹ฌ๋ณผ ์—๋Ÿฌ ์—†์Œ. SPI ๋ช…๋ น๊ณผ 8๊ฐœ์˜ ํ•˜๋“œ์›จ์–ด ์†Œ์ผ“๋งŒ ์žˆ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๐Ÿ”ท WIZ550io โ€” ๋‹จ์ผ ๋ชจ๋“ˆ ํ†ตํ•ฉ

WIZ550io๋Š” W5500 + ์ž์„ฑ์ฒด + RJ45๋ฅผ ๋‹จ์ผ ๋“œ๋กญ์ธ ๋ชจ๋“ˆ๋กœ ๊ฒฐํ•ฉํ•ฉ๋‹ˆ๋‹ค. Nucleo-64 + ๋ธŒ๋ ˆ๋“œ๋ณด๋“œ ํ”„๋กœํ† ํƒ€์ž…์ด๋‚˜ ์†Œํ˜• ์ปค์Šคํ…€ ์‚ฐ์—… PCB์—์„œ, ์ด๋Š” ์ด๋”๋„ท ํ•˜๋“œ์›จ์–ด๋ฅผ ๋‹จ์ผ ์ปดํฌ๋„ŒํŠธ ์—ฐ๊ฒฐ๋กœ ์ถ•์†Œํ•ฉ๋‹ˆ๋‹ค. ๋ณ„๋„ ์ž์„ฑ์ฒด ์—†์Œ, ์ž„ํ”ผ๋˜์Šค ๋งค์นญ ์—†์Œ, PHY ํด๋Ÿญ ์ด์Šˆ ์—†์Œ.

๐Ÿ”ท ๊ฒ€์ฆ๋œ ํ•˜๋“œ์›จ์–ด ๋™์ž‘

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ฐœ๋ฐœ ๊ณผ์ •์— ๋‚ด์žฅ๋œ ํ•˜๋“œ์›จ์–ด ์ฆ๊ฑฐ:

  • โœ… ๋ชจ๋“  ์†Œ์ผ“ ๋ชจ๋“œ ๋ช…๋ น์—์„œ ์ •ํ™•ํ•œ BSB ํ”„๋ ˆ์ด๋ฐ ๊ฒ€์ฆ
  • โœ… SOCKET OPEN์ด ์•ˆ์ •์ ์œผ๋กœ ์„ฑ๊ณต (๊ฒฝ์Ÿ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์ด ๊นจ์ง€๋Š” ์‹คํŒจ ๋ชจ๋“œ)
  • โœ… ์ •์  IP, MAC, ๊ฒŒ์ดํŠธ์›จ์ด, ์„œ๋ธŒ๋„ท ์„ค์ • ๋ผ์šด๋“œํŠธ๋ฆฝ ๊ฒ€์ฆ
  • โœ… PHY ๋งํฌ ์ƒํƒœ ๊ฐ์ง€ ๋™์ž‘
  • โœ… Modbus Poll๋กœ Modbus TCP ์Šฌ๋ ˆ์ด๋ธŒ ํ…Œ์ŠคํŠธ
  • โœ… Modbus Slave ์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ๋กœ Modbus TCP ๋งˆ์Šคํ„ฐ ํ…Œ์ŠคํŠธ
  • โœ… ๋ฌผ๋ฆฌ์  ์ผ€์ด๋ธ” ๋ถ„๋ฆฌ ํ›„ ์ž๋™ ์žฌ์—ฐ๊ฒฐ ๊ฒ€์ฆ

05 โ€” ํ•ต์‹ฌ ๊ตฌ์„ฑ ์š”์†Œ

๐Ÿง  STM32F446RE (Nucleo-64) โ€” ๋ ˆํผ๋Ÿฐ์Šค ํ”Œ๋žซํผ

180MHz Cortex-M4 + FPU. ๊ณต์‹ STM32duino Arduino ์ฝ”์–ด๋กœ ์ปดํŒŒ์ผ. STM32F446ZE Nucleo-144, STM32F103C8 Blue Pill, CS ํ•€ ์กฐ์ • ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  STM32์™€ ํ˜ธํ™˜ ๊ฒ€์ฆ. ๋™์ผ ์นฉ์— ๋Œ€ํ•œ ์ปค์Šคํ…€ ๋ฒ ์–ด๋ฉ”ํƒˆ ์ฝ”์–ด๋„ ํ…Œ์ŠคํŠธ.

๐ŸŒ WIZnet W5500 / WIZ550io โ€” ์ด๋”๋„ท ์ธํ„ฐํŽ˜์ด์Šค

W5500์€ w5500.cpp์— ๊ตฌํ˜„๋œ ์ปค์Šคํ…€ SPI ๋งˆ์Šคํ„ฐ๋ฅผ ํ†ตํ•ด ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๋“œ๋ผ์ด๋ฒ„๋Š” ์ •ํ™•ํ•œ BSB ํ”„๋ ˆ์ด๋ฐ์„ ๊ตฌ์‚ฌํ•˜๊ณ , 8๊ฐœ์˜ ๋ชจ๋“  ํ•˜๋“œ์›จ์–ด ์†Œ์ผ“์„ ๋…๋ฆฝ์ ์œผ๋กœ ์ฃผ์†Œ ์ง€์ •ํ•˜๋ฉฐ, ์ƒ์œ„ ๊ณ„์ธต์— ๊น”๋”ํ•œ ๋ ˆ์ง€์Šคํ„ฐ ์ˆ˜์ค€ API๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. WIZ550io์˜ ํ†ตํ•ฉ ์ž์„ฑ์ฒด๊ฐ€ ํ•˜๋“œ์›จ์–ด ๋ธŒ๋ง์—…์„ ๋‹จ์ˆœํ™”ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“ฆ TCP ์„œ๋ฒ„ (server.cpp)

์—ฐ๊ฒฐ ํ•ด์ œ ์‹œ ์ž๋™ ์žฌ๋ฌด์žฅํ•˜๋Š” ๋‹จ์ผ ๋ฆฌ์Šค๋„ˆ TCP ์„œ๋ฒ„. ์‚ฐ์—… ์‚ฌ์šฉ ์‚ฌ๋ก€๋ฅผ ์œ„ํ•ด ์„ค๊ณ„๋จ: ํ•˜๋‚˜์˜ ์˜๊ตฌ ํด๋ผ์ด์–ธํŠธ(PLC, SCADA ๋‹จ๋ง, ๊ฒŒ์ดํŠธ์›จ์ด)๊ฐ€ ์—ฐ๊ฒฐ, Modbus ํ†ต์‹ , ์—ฐ๊ฒฐ ํ•ด์ œํ•˜๋ฉด ์„œ๋ฒ„๊ฐ€ ์ฆ‰์‹œ ๋‹ค์‹œ ๋ฆฌ์Šค๋‹ ์ƒํƒœ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

๐Ÿ“ฆ TCP ํด๋ผ์ด์–ธํŠธ (client.cpp)

์ž๋™ ์žฌ์—ฐ๊ฒฐ ์˜๊ตฌ TCP ํด๋ผ์ด์–ธํŠธ. ์ผ€์ด๋ธ” ๋ถ„๋ฆฌ, ์Šค์œ„์น˜ ์žฌ๋ถ€ํŒ…, ์›๊ฒฉ ์„œ๋ฒ„ ์žฌ์‹œ์ž‘์— ์‚ด์•„๋‚จ์Œ โ€” ๋‹ค์Œ ๋ฃจํ”„ ํ‹ฑ์— ๊ฐœ์ž… ์—†์ด ์žฌ์—ฐ๊ฒฐ๋ฉ๋‹ˆ๋‹ค.

โš–๏ธ Modbus TCP ์Šฌ๋ ˆ์ด๋ธŒ (FC03 + FC16)

์„œ๋ฒ„์— ๋‚ด์žฅ. Read Holding Registers์™€ Write Multiple Registers ์ฒ˜๋ฆฌ. ์ž˜๋ชป๋œ ํ•จ์ˆ˜ ์ฝ”๋“œ๋‚˜ ๋ฒ”์œ„ ์™ธ ์ฃผ์†Œ์— ๋Œ€ํ•ด ์ ์ ˆํ•œ MBAP ์˜ˆ์™ธ ์‘๋‹ต ๋ฐ˜ํ™˜. Modbus Poll ์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ๋กœ ์ข…๋‹จ ๊ฐ„ ํ…Œ์ŠคํŠธ.

โš–๏ธ Modbus TCP ๋งˆ์Šคํ„ฐ

ํด๋ผ์ด์–ธํŠธ์— ๋‚ด์žฅ. ์˜๊ตฌ ์—ฐ๊ฒฐ๋กœ ์›๊ฒฉ ์Šฌ๋ ˆ์ด๋ธŒ๋ฅผ ํด๋ง, ์‹คํŒจ ์‹œ ์žฌ์—ฐ๊ฒฐ. 5๊ฐœ Holding Registers๋ฅผ 2์ดˆ๋งˆ๋‹ค ํด๋งํ•˜๋Š” Modbus Slave ์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ๋กœ ํ…Œ์ŠคํŠธ.

๐Ÿงช ๋™์ž‘ํ•˜๋Š” 3๊ฐœ ์˜ˆ์ œ

  • 01_ethernet_netinfo โ€” ๋งํฌ ์—… ์Šค๋ชจํฌ ํ…Œ์ŠคํŠธ
  • 02_modbus_client โ€” Modbus TCP ๋งˆ์Šคํ„ฐ
  • 03_modbus_server โ€” ํฌํŠธ 1502์—์„œ Modbus TCP ์Šฌ๋ ˆ์ด๋ธŒ

์„ธ ์˜ˆ์ œ ๋ชจ๋‘ ์‹ค์ œ STM32F446RE ํ•˜๋“œ์›จ์–ด์—์„œ ๊ฒ€์ฆ.


06 โ€” ์‘์šฉ ์‹œ๋‚˜๋ฆฌ์˜ค

01. ์‚ฐ์—…์šฉ Modbus TCP ๊ฒŒ์ดํŠธ์›จ์ด

์›๋ž˜ ์‚ฌ์šฉ ์‚ฌ๋ก€. STM32 + W5500 + ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ = ์‚ฐ์—… ๋„คํŠธ์›Œํฌ์™€ ํ•„๋“œ ๋””๋ฐ”์ด์Šค ์‚ฌ์ด์˜ ๊ฒฐ์ •๋ก ์  ๋ฒ ์–ด๋ฉ”ํƒˆ Modbus TCP ๊ฒŒ์ดํŠธ์›จ์ด. ์ œ๋กœ ํž™, ์ œ๋กœ OS, ์ œ๋กœ ์„œํ”„๋ผ์ด์ฆˆ. ์ž‘์„ฑ์ž๊ฐ€ ์‚ฐ์—… ์ œ์–ด ๋ฐฐํฌ๋ฅผ ์œ„ํ•ด ์ •ํ™•ํžˆ ์ด๊ฒƒ์„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. #Modbus #์‚ฐ์—…์šฉ #SCADA #PLCํ†ตํ•ฉ

02. STM32 Nucleo-64 ์œ ์„  IoT ์—”๋“œํฌ์ธํŠธ

๋Œ€๋ถ€๋ถ„์˜ STM32 IoT ํŠœํ† ๋ฆฌ์–ผ์€ Nucleo-144(๋‚ด์žฅ MAC)๋ฅผ ๊ฐ€์ •ํ•˜๊ฑฐ๋‚˜ ESP32๋กœ ๋ฐ€์–ด๋ถ™์ž…๋‹ˆ๋‹ค. ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์ „์ฒด Nucleo-64 ๋ผ์ธ โ€” ๊ทธ๋ฆฌ๊ณ  ๋ชจ๋“  ์ปค์Šคํ…€ STM32 ๋ณด๋“œ โ€” ์„ WiFi์˜ ์•ˆ์ •์„ฑยท๋ณด์•ˆ ํŠธ๋ ˆ์ด๋“œ์˜คํ”„ ์—†์ด ์œ ์„  ์ด๋”๋„ท IoT ์‘์šฉ์œผ๋กœ ์—ด์–ด์ค๋‹ˆ๋‹ค. #IoT #Nucleo64 #์œ ์„ ์ด๋”๋„ท

03. ๋ฒ ์–ด๋ฉ”ํƒˆ ์ž„๋ฒ ๋””๋“œ ๋„คํŠธ์›Œํ‚น

์ปค์Šคํ…€ STM32 ์ฝ”์–ด๋ฅผ ์ž‘์„ฑํ•˜๊ฑฐ๋‚˜ Arduino ์ถ”์ƒํ™” ์•„๋ž˜์—์„œ ์ž‘์—…ํ•˜๋Š” ์—”์ง€๋‹ˆ์–ด๋Š” ์ž์‹ ์˜ ํ”„๋กœ์ ํŠธ๋กœ ๊ทธ๋Œ€๋กœ ๊ฐ€์ ธ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊น”๋”ํ•˜๊ณ , ํž™ ์—†๋Š”, BSB-correct W5500 ๋“œ๋ผ์ด๋ฒ„๋ฅผ ์–ป์Šต๋‹ˆ๋‹ค. SPI ๊ณ„์ธต ์•„๋ž˜์—๋Š” Arduino ๊ฐ€์ •์ด ๋ฐ•ํ˜€์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. #๋ฒ ์–ด๋ฉ”ํƒˆ #์ž„๋ฒ ๋””๋“œ์‹œ์Šคํ…œ #๋“œ๋ผ์ด๋ฒ„

04. STM32 + W5500 ๋ ˆํผ๋Ÿฐ์Šค ๊ตฌํ˜„

๊ต์œก ๋ฐ ๋ ˆํผ๋Ÿฐ์Šค ์šฉ๋„. ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” STM32์—์„œ์˜ ์ •ํ™•ํ•œ W5500 SPI ํ”„๋ ˆ์ด๋ฐ, SPI ํด๋Ÿญ ๋ถ„์ฃผ์˜ ์ •ํ™•ํ•œ ํƒ€์ด๋ฐ, ์ •ํ™•ํ•œ CS ์ฒ˜๋ฆฌ, ํ•˜๋“œ์›จ์–ด ๊ณ„์ธต๊ณผ ํ”„๋กœํ† ์ฝœ ๊ณ„์ธต์˜ ๊น”๋”ํ•œ ๋ถ„๋ฆฌ๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. ์ž„๋ฒ ๋””๋“œ ๋„คํŠธ์›Œํ‚น ๊ฐ•์˜์˜ ๊ฒฌ๊ณ ํ•œ ๊ต์œก ์˜ˆ์ œ. #๊ต์œก #๋ ˆํผ๋Ÿฐ์Šค #์˜คํ”ˆ์†Œ์Šค


๊ฒฐ๋ก 

๋“œ๋””์–ด, ํ”„๋กœ๋•์…˜ ์ˆ˜์ค€์˜ STM32 + W5500 ์ด๋”๋„ท โ€” Modbus TCP ๋‚ด์žฅ, ํž™ ์ œ๋กœ.

์ด ํ”„๋กœ์ ํŠธ๋Š” STM32 + Arduino ์ƒํƒœ๊ณ„์˜ ์‹ค์ œ ๊ณต๋ฐฑ์„ ๋ฉ”์›๋‹ˆ๋‹ค. ๊ฑฐ์˜ ๋™์ž‘ํ•˜๋Š” ์ปค๋ฎค๋‹ˆํ‹ฐ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์ด ์ˆ˜๋…„๊ฐ„ ์Œ“์ธ ๋์—, ํ•œ ์ œ์–ด ์‹œ์Šคํ…œ ์—”์ง€๋‹ˆ์–ด๊ฐ€ ์ž‘์„ฑํ•˜๊ณ , ํ•˜๋“œ์›จ์–ด ๊ฒ€์ฆํ•˜๊ณ , ์˜คํ”ˆ์†Œ์Šค๋กœ ๊ณต๊ฐœํ•œ ์ง‘์ค‘์ ์ธ W5500 ๋“œ๋ผ์ด๋ฒ„๊ฐ€ ์‹ค์ œ๋กœ ์ปดํŒŒ์ผ๋˜๊ณ , ์‹ค์ œ๋กœ ๋™์ž‘ํ•˜๊ณ , ์‹ค์ œ๋กœ ์‚ฐ์—… ํŽŒ์›จ์–ด๋กœ ์ถœํ•˜๋ฉ๋‹ˆ๋‹ค. ๊ฒฐ์ • ํŠธ๋ฆฌ๋Š” ๋‹จ์ˆœํ•ฉ๋‹ˆ๋‹ค: STM32(์–ด๋–ค ๋ชจ๋ธ์ด๋“ )์™€ W5500 ๋ชจ๋“ˆ์ด ์žˆ๊ณ  LwIP ์—†์ด ์ด๋”๋„ท์„ ์›ํ•œ๋‹ค๋ฉด, ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์ตœ์†Œ ์ €ํ•ญ ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค.

Modbus TCP ์Šฌ๋ ˆ์ด๋ธŒ์™€ ๋งˆ์Šคํ„ฐ๊ฐ€ ์‡ผ์ผ€์ด์Šค์ด์ง€๋งŒ โ€” ์ง„์งœ ๊ฐ€์น˜๋Š” ๊ทธ ์•„๋ž˜ W5500 ๋“œ๋ผ์ด๋ฒ„์— ์žˆ์Šต๋‹ˆ๋‹ค. ์–ด๋–ค ์ž„๋ฒ ๋””๋“œ ์—”์ง€๋‹ˆ์–ด๋“  ์ด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ HTTP, MQTT, ์ปค์Šคํ…€ ๋ฐ”์ด๋„ˆ๋ฆฌ ํ”„๋กœํ† ์ฝœ, ๋˜๋Š” ๋‹ค๋ฅธ ์–ด๋–ค TCP/UDP ์‘์šฉ๋„ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • โœ… ์ •ํ™•ํ•œ BSB-aware SPI ํ”„๋ ˆ์ด๋ฐ โ€” ์กฐ์šฉํ•œ SOCKET OPEN ์‹คํŒจ ํ•ด๊ฒฐ
  • โœ… ๋™์  ๋ฉ”๋ชจ๋ฆฌ ํ• ๋‹น ์ œ๋กœ, ํž™ ์ œ๋กœ, new/malloc ์ œ๋กœ
  • โœ… WIZnet ๊ณต์‹ ioLibrary์™€ API ํ˜ธํ™˜ (wizchip_init, wiz_NetInfo ๋“ฑ)
  • โœ… ๋‹จ์ผ ํŒŒ์ผ ์ธํด๋ฃจ๋“œ (#include <W5500Ethernet.h>)
  • โœ… Modbus TCP ์Šฌ๋ ˆ์ด๋ธŒ ๋‚ด์žฅ (FC03, FC16) + MBAP ์˜ˆ์™ธ ์ฒ˜๋ฆฌ
  • โœ… Modbus TCP ๋งˆ์Šคํ„ฐ ๋‚ด์žฅ + ์˜๊ตฌ ์—ฐ๊ฒฐ + ์ž๋™ ์žฌ์—ฐ๊ฒฐ
  • โœ… ๋‹จ์ผ ๋ฆฌ์Šค๋„ˆ ์ž๋™ ์žฌ๋ฌด์žฅ TCP ์„œ๋ฒ„
  • โœ… ์ž๋™ ์žฌ์—ฐ๊ฒฐ TCP ํด๋ผ์ด์–ธํŠธ
  • โœ… STM32F446RE Nucleo-64 + WIZ550io ํ•˜๋“œ์›จ์–ด ๊ฒ€์ฆ
  • โœ… STM32F446ZE, STM32F103, ์ปค์Šคํ…€ STM32 ๋ณด๋“œ ํ˜ธํ™˜
  • โœ… MIT ๋ผ์ด์„ ์Šค โ€” ์ƒ์šฉ ์ œํ’ˆ์— ์‚ฌ์šฉ ๊ฐ€๋Šฅ

Q&A

Q. ๊ทธ๋ƒฅ ๊ณต์‹ STM32Ethernet ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์“ฐ๋ฉด ์•ˆ ๋˜๋‚˜์š”? ๊ณต์‹ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋‚ด์žฅ MAC + LAN8742A PHY๋ฅผ ๊ฐ€์ง„ STM32 ๋ณด๋“œ(Nucleo-144 ๊ณ„์—ด)๋งŒ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. Nucleo-64, Blue Pill, ์™ธ๋ถ€ SPI ์ด๋”๋„ท ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“  ๋ณด๋“œ์—๋Š” ๊ทธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์ ์šฉ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค โ€” W5500 ์ง€์›์ด ์ „ํ˜€ ์—†์Šต๋‹ˆ๋‹ค. GitHub ์ €์žฅ์†Œ์˜ ์—ด๋ฆฐ ์ด์Šˆ๋“ค์€ ์ง€์›๋˜๋Š” ๋ณด๋“œ์—์„œ๋„ LAN8742A_PHY_ADDRESS์™€ PHY_IMR ์‹ฌ๋ณผ ์—๋Ÿฌ๊ฐ€ ๋ฐ˜๋ณต์ ์œผ๋กœ ๋ฐœ์ƒํ•จ์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๊ณต์‹ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๊ฒฐ์ฝ” ๋‹ค๋ฃจ์ง€ ์•Š์€ SPI ์ด๋”๋„ท ๊ณต๋ฐฑ์„ ์ฑ„์šฐ๊ธฐ ์œ„ํ•ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

Q. BSB ํ”„๋ ˆ์ด๋ฐ์ด ๋ฌด์—‡์ด๊ณ  ์™œ ์ค‘์š”ํ•œ๊ฐ€์š”? W5500์€ ๋ชจ๋“  SPI ํŠธ๋žœ์žญ์…˜์˜ ๋‘ ๋ฒˆ์งธ ๋ฐ”์ดํŠธ์— Block Select Bits (BSB)๋ฅผ ์‚ฌ์šฉํ•ด 8๊ฐœ์˜ ํ•˜๋“œ์›จ์–ด ์†Œ์ผ“ ์ค‘ ํ•˜๋‚˜, ๊ณตํ†ต ๋ ˆ์ง€์Šคํ„ฐ, ๋˜๋Š” ์†Œ์ผ“๋ณ„ ๋ฒ„ํผ๋ฅผ ์ฃผ์†Œ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. BSB ํ•„๋“œ๊ฐ€ ์ž˜๋ชป ๊ตฌ์„ฑ๋˜๋ฉด ๋ ˆ์ง€์Šคํ„ฐ ์ฝ๊ธฐ/์“ฐ๊ธฐ๋Š” ๋™์ž‘ํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ž…๋‹ˆ๋‹ค โ€” ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๊ณ , ์“ฐ๊ธฐ๋ฅผ ๋ฐ›์•„๋“ค์ž…๋‹ˆ๋‹ค โ€” ํ•˜์ง€๋งŒ SOCKET OPEN ๊ฐ™์€ ์†Œ์ผ“ ์ˆ˜์ค€ ๋ช…๋ น์€ ์กฐ์šฉํžˆ ์‹คํŒจํ•ฉ๋‹ˆ๋‹ค. ์†Œ์ผ“์ด ๋ฆฌ์Šค๋‹ ์ƒํƒœ์— ์ง„์ž…ํ•˜์ง€ ์•Š๊ณ , ๋“ค์–ด์˜ค๋Š” ์—ฐ๊ฒฐ์ด ๋ฐ›์•„๋“ค์—ฌ์ง€์ง€ ์•Š์œผ๋ฉฐ, ์—๋Ÿฌ ํ‘œ์‹œ๋„ ์—†์Šต๋‹ˆ๋‹ค. ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” BSB ํ”„๋ ˆ์ด๋ฐ์„ ์ •ํ™•ํ•˜๊ฒŒ ๊ตฌํ˜„ํ•ด ๊ทธ ํŒจํ„ด์ด ์ ˆ๋Œ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.

Q. WIZnet ๊ณต์‹ ioLibrary๋ฅผ ์ง์ ‘ ์‚ฌ์šฉํ•˜์ง€ ์•Š์€ ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”? ioLibrary๋Š” ํ‘œ์ค€ C ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ, STM32CubeIDE / CMake / HAL ๊ธฐ๋ฐ˜ ํ”„๋กœ์ ํŠธ์šฉ์œผ๋กœ ๋งŒ๋“ค์–ด์กŒ์Šต๋‹ˆ๋‹ค โ€” ๊ฐœ๋ฐœ์ž๊ฐ€ ์ž์‹ ์˜ SPI ๋“œ๋ผ์ด๋ฒ„๋ฅผ ์ฝœ๋ฐฑ์œผ๋กœ ๋“ฑ๋กํ•˜๋Š” ํ™˜๊ฒฝ์„ ๊ธฐ๋Œ€ํ•ฉ๋‹ˆ๋‹ค. Arduino ์ƒํƒœ๊ณ„๋Š” ์™„์ „ํžˆ ๋‹ค๋ฅธ ๋นŒ๋“œ ๋ชจ๋ธ์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค: <Arduino.h>๋ฅผ ์ธํด๋ฃจ๋“œํ•˜๋Š” .cpp ํŒŒ์ผ, SPI์™€ digitalWrite API, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋งค๋‹ˆ์ € ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ, ์ฝœ๋ฐฑ ๋“ฑ๋ก ์—†์Œ. ioLibrary๋Š” Arduino ํ”„๋กœ์ ํŠธ์— ๊ทธ๋Œ€๋กœ ๋–จ์–ด๋œจ๋ฆด ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. STM32๋Š” STMicroelectronics๊ฐ€ ๊ณต์‹์ ์œผ๋กœ ๊ด€๋ฆฌํ•˜๋Š” STM32duino(STM32 ๋ณด๋“œ์šฉ ๊ณต์‹ Arduino ์ฝ”์–ด)๋ฅผ ํ†ตํ•ด Arduino๋ฅผ ์ง€์›ํ•˜์ง€๋งŒ, ๊ทธ๊ฒƒ์ด ๋นŒ๋“œ ์‹œ์Šคํ…œ ๊ฐ„๊ทน์„ ๋ฉ”๊ฟ”์ฃผ์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค โ€” ioLibrary๊ฐ€ ๊ทธ ์•ˆ์—์„œ ๋™์ž‘ํ•˜๋ ค๋ฉด ์—ฌ์ „ํžˆ ์ƒ๋‹นํ•œ ํ†ตํ•ฉ ๋ ˆ์ด์–ด๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๊ทธ ์ž‘์—…์„ ํ•œ ๋ฒˆ์— ํ•ด๊ฒฐํ•ฉ๋‹ˆ๋‹ค: ๋™์ผํ•œ ioLibrary API ํ‘œ๋ฉด์„, Arduino์šฉ์œผ๋กœ ๋„ค์ดํ‹ฐ๋ธŒํ•˜๊ฒŒ ์žฌ๊ตฌํ˜„. ioLibrary ์‚ฌ์šฉ์ž๋Š” ๊ธฐ์กด ๋จธ์Šฌ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์œ ์ง€ํ•˜๊ณ , Arduino ์‚ฌ์šฉ์ž๋Š” ์ฆ‰์‹œ ์ปดํŒŒ์ผ๋˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์–ป์Šต๋‹ˆ๋‹ค.

Q. DHCP, DNS, UDP๋Š” ์™œ ์—†๋‚˜์š”? ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋ชจ๋“  ์—”๋“œํฌ์ธํŠธ๊ฐ€ ์ •์  IP๋ฅผ ๊ฐ€์ง€๊ณ , IP ์ฃผ์†Œ๋ฅผ ์ง์ ‘ ์‚ฌ์šฉํ•˜๋ฉฐ(DNS ์—†์Œ), ํ”„๋กœํ† ์ฝœ์ด TCP(Modbus TCP)์ธ ์‚ฐ์—… ๋ฐฐํฌ๋ฅผ ํƒ€๊ฒŸํ•ฉ๋‹ˆ๋‹ค. DHCP, DNS, UDP๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ํƒ€๊ฒŸ ์‚ฌ์šฉ ์‚ฌ๋ก€์— ํ•„์š”ํ•˜์ง€ ์•Š์€ ๊ธฐ๋Šฅ์„ ์œ„ํ•ด ์ฝ”๋“œ ํฌ๊ธฐ์™€ ์˜์กด์„ฑ ํ‘œ๋ฉด์ด ์ปค์ง‘๋‹ˆ๋‹ค. ๊ทธ ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•œ ์—”์ง€๋‹ˆ์–ด๋Š” W5500 ๊ณ„์ธต์„ ์ง์ ‘ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜(SPI ๋“œ๋ผ์ด๋ฒ„๊ฐ€ ๋…ธ์ถœ๋˜์–ด ์žˆ์Œ) ๊ทธ ์œ„์— ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ์˜๋„๋œ ๋ฒ”์œ„ ์„ค์ •์ด๋ฉฐ, ๋ˆ„๋ฝ์ด ์•„๋‹™๋‹ˆ๋‹ค.

Q. ArduinoModbus๋‚˜ ๋‹ค๋ฅธ Arduino TCP ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ํ•จ๊ป˜ ์“ธ ์ˆ˜ ์žˆ๋‚˜์š”? ์˜ค๋Š˜ ์‹œ์ ์—์„œ๋Š” ์ง์ ‘์ ์œผ๋กœ๋Š” ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค โ€” API๊ฐ€ ํ‘œ์ค€ Arduino EthernetClient / Stream ์ธํ„ฐํŽ˜์ด์Šค ๋Œ€์‹  ๋ช…์‹œ์ ์ธ ์†Œ์ผ“ ๋ฒˆํ˜ธ ํ•จ์ˆ˜(EthernetClient_write_array(sock, buf, len))๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ž‘์„ฑ์ž๋Š” ๊ทธ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•˜๋Š” ์–‡์€ C++ ๋ž˜ํผ๊ฐ€ ํ–ฅํ›„ ์ถ”๊ฐ€ ๊ณ„ํš์ž„์„ ์–ธ๊ธ‰ํ•ฉ๋‹ˆ๋‹ค. ์ง€๊ธˆ ArduinoModbus ํ˜ธํ™˜์„ฑ์ด ํ•„์š”ํ•˜๋‹ค๋ฉด, C ์Šคํƒ€์ผ API๋ฅผ ์ง์ ‘ ๋ž˜ํ•‘ํ•˜๊ฑฐ๋‚˜, ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ํฌํ•จ๋œ Modbus TCP ์Šฌ๋ ˆ์ด๋ธŒ/๋งˆ์Šคํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ArduinoModbus๋ฅผ ๊ฑด๋„ˆ๋›ฐ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

Q. SPI ํด๋Ÿญ ์†๋„๋Š” ์–ผ๋งˆ์ด๋ฉฐ ์•ˆ์ „ํ•œ๊ฐ€์š”? Quick Start ์˜ˆ์ œ๋Š” 11.25 MHz SPI๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, STM32F446RE + WIZ550io ์กฐํ•ฉ์—์„œ ์•ˆ์ •์ ์œผ๋กœ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. README๋Š” SPI ์™€์ด์–ด๋ฅผ 10cm ์ดํ•˜๋กœ ์œ ์ง€ํ•ด์•ผ ํ•œ๋‹ค๊ณ  ๊ฒฝ๊ณ ํ•ฉ๋‹ˆ๋‹ค โ€” 11 MHz์˜ ๊ธธ๊ณ  ์ฐจํ๋˜์ง€ ์•Š์€ ์™€์ด์–ด๋Š” W5500 ์†Œ์ผ“ ์ƒํƒœ ๋จธ์‹ ์ด OPEN ๋ช…๋ น์„ ์กฐ์šฉํžˆ ๊ฑฐ๋ถ€ํ•˜๊ฒŒ ๋งŒ๋“œ๋Š” ์‹ ํ˜ธ ๋ฌด๊ฒฐ์„ฑ ๋ฌธ์ œ๋ฅผ ์ผ์œผํ‚ต๋‹ˆ๋‹ค. W5500 ๋ธŒ๋ง์—…์—์„œ ๊ฐ€์žฅ ๊นŒ๋‹ค๋กœ์šด ๋ฒ„๊ทธ ์ค‘ ํ•˜๋‚˜์ด๋ฉฐ, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์ด๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ๋ฌธ์„œํ™”ํ•ด ์‚ฌ์šฉ์ž๊ฐ€ ์ž์‹ ์˜ ํ•˜๋“œ์›จ์–ด์—์„œ ์ด๋ฅผ ํ”ผํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.

Comments

Similar projects you might like

์—๋„ˆ์ง€ ๊ณ„์ธก ์žฅ๋น„์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋„คํŠธ์›Œํฌ์— ์—ฐ๊ฒฐํ•˜๋Š” DIN ๋ ˆ์ผํ˜• ๊ฒŒ์ดํŠธ์›จ์ด์ž…๋‹ˆ๋‹ค. ์ œํ’ˆ๊ณผ ์—ฐ๊ฒฐ๋œ ๊ณต๊ฐœ ๊ฐœ๋ฐœ ์ž๋ฃŒ๋Š” ์กฐ๋ฆฝ๋œ DIN ๋ ˆ์ผ ํ•˜๋“œ์›จ์–ด์™€ W5500 Lite Ethernet ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ตฌ์„ฑ์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

AmpX โ€” AmpX Energy Gateway

matthew
  • Views 21

  • Comments 0

Comments