CO2_Gateway
STM32F103 and W5500 based gateway converting RS-485 Modbus sensor data into TCP/IP for smart factory, greenhouse and building monitoring systems.
0
Project description

๐ Overview
STM32F103 + WIZnet W5500 ์กฐํฉ์ผ๋ก RS-485(Modbus RTU) ์ผ์ ๋ฐ์ดํฐ๋ฅผ ์ด๋๋ท(TCP)์ผ๋ก ์ฐ๋ํ๋ โํ์ฅ ์ผ์ โ ๋คํธ์ํฌโ ๊ฒ์ดํธ์จ์ด ์์ ์ ๋๋ค. MCU ์ค์ ํ์ผ์์ STM32F103C8T6 ๊ณ์ด ์ฌ์ฉ์ด ํ์ธ๋ฉ๋๋ค.
๐ Features
RS-485(Modbus RTU) ์ง์/์๋ต ๊ธฐ๋ฐ ์ผ์๊ฐ ์์ง
- CRC16 ๊ณ์ฐ ํ ํ๋ ์ ์ก์ , ์์ ๋ฐ์ดํฐ ๊ธฐ๋ฐ ํ์ฑ ๊ตฌ์กฐ๊ฐ ํฌํจ๋ฉ๋๋ค.
W5500 ํ๋์จ์ด TCP/IP ์คํ๋ก๋ฉ ๊ธฐ๋ฐ TCP Client ํต์
- MCU ๋ถํ๋ฅผ ๋ฎ์ถ๊ณ , ์๋ฒ ๋๋์์ ๋น๊ต์ ๋จ์ํ ์์ผ API๋ก TCP ์ฐ๊ฒฐ์ ๊ตฌ์ฑํฉ๋๋ค.
๋ฉํฐ ํ์คํฌ(FreeRTOS) ํํ์ ๊ธฐ๋ฅ ๋ถ๋ฆฌ
- ํต์ ์์ , ๋์คํ๋ ์ด, ๋ก์ปฌ ์จ๋(DS18B20), RS-485 ์์ง์ ํ์คํฌ๋ก ๋ถ๋ฆฌํด ํ์ฅ์ ์ ๋ฆฌํฉ๋๋ค.
๋ก์ปฌ ํ์(OLED) ๋ฐ ๋ก์ปฌ ์จ๋ ์ผ์(DS18B20) ํฌํจ
- ๊ฒ์ดํธ์จ์ด๊ฐ ๋จ์ ์ค๊ณ๊ธฐ ์ญํ ์ ๋์ด ํ์ฅ ๋๋ฒ๊น /์ํ ํ์ธ์ฉ UI๋ฅผ ๊ฐ์ง ์ ์๋ ํํ์ ๋๋ค.
๊ณ ์ IP/ํฌํธ ๊ธฐ๋ฐ์ ๊ฐ๋จํ ์๋ฒ ์ฐ๋ ๋ผ๋
- ์๋ฒ IP/ํฌํธ๊ฐ ์ฝ๋์ ๊ณ ์ ๋ ํํ๋ก ์กด์ฌํด, PoC(๊ฐ๋ ๊ฒ์ฆ) ๊ตฌํ์ด ๋น ๋ฆ ๋๋ค.
๐ System Architecture
๊ตฌ์ฑ ์์
- MCU: STM32F103C8T6
- Ethernet: WIZnet W5500 (SPI ์ฐ๊ฒฐ, CS/RST ํ ์ฌ์ฉ)
- Field I/F: RS-485(UART ๊ธฐ๋ฐ, Modbus RTU)
- Local Sensor/UI: DS18B20(1-Wire), OLED
๋ฐ์ดํฐ ํ๋ฆ
- RS-485 ์ผ์ โ (Modbus RTU ์๋ต) โ STM32
- STM32 โ (W5500 ์์ผ send/recv) โ TCP ์๋ฒ
- TCP ์๋ฒ โ STM32๋ก ๋ฐ์ดํฐ ์ก์ ์, ํ๋ก์ ํธ๋ ๋ฌธ์์ด ํ์ฑ(์: co2, temperature ํํ) ๊ตฌ์กฐ๋ฅผ ํฌํจ
- STM32 โ OLED์ ์จ๋/์ต๋ ๋ฑ ์ํ ํ์
๐ Role and Application of the WIZnet's Chip
์ฌ์ฉ ์นฉ: WIZnet W5500
๋คํธ์ํฌ์์์ ์ญํ :
- TCP Client ์์ผ ํต์ (์๋ฒ IP/Port๋ก connect ํ send/recv)
๐ Market & Application Value
์ ์ฉ ์ฐ์ /์์ฅ
- ์ค๋งํธ ํฉํ ๋ฆฌ/๋น๋ฉ ์๋ํ: RS-485(์ผ์/์ธ๋ฒํฐ/๊ณ์ธก๊ธฐ) โ Ethernet(์์ ๊ด์ ) ๋ณํ ์์๊ฐ ๊พธ์คํฉ๋๋ค.
- ์จ์ค/ํ๊ฒฝ ๋ชจ๋ํฐ๋ง: CO2/์จ์ต๋/๊ณต๊ธฐ์ง ์ผ์๊ฐ RS-485(Modbus)๋ก ์ ๊ณต๋๋ ์ ํ๊ตฐ์ด ์กด์ฌํฉ๋๋ค(์ผ์ ์์ฅ ์ผ๋ฐ ์ ๋ณด).
- ๋ ๊ฑฐ์ ์ค๋น ๋ฐ์ดํฐ ์์ง: โ๊ธฐ์กด RS-485 ์ฅ๋น๋ฅผ IP๋ก ๋์ด์ฌ๋ฆฌ๋โ ์ ํ ์์
๐ WIZnet Strategic Value
Maker ์ํ๊ณ ๊ด์ ์๋ฏธ
- โW5500 + STM32 + RS-485โ๋ ํ์ฅ IoT์์ ๋ฐ๋ณต ๋ฑ์ฅํ๋ ์กฐํฉ์ด๋ผ, ๊ฒ์ดํธ์จ์ด ๋ ํผ๋ฐ์ค ํ ํ๋ฆฟ์ผ๋ก ๊ฐ์น๊ฐ ์์ต๋๋ค.
- FreeRTOS ํ์คํฌ ๋ถ๋ฆฌ ๊ตฌ์กฐ๋ Maker ์ฌ์ฉ์์๊ฒ โํ์ฅ ๊ฐ๋ฅํ ์ฝ๋ ๋ผ๋โ๋ก ๊ต์ก ํจ๊ณผ๊ฐ ์์ต๋๋ค.
- W5500์ ์ฐ๋ฉด ๊ณ ์ฑ๋ฅ MCU ์์ด๋ ์์ ์ ์ธ ์ด๋๋ท ๊ธฐ๋ฐ ํ๋ ๊ฒ์ดํธ์จ์ด๋ฅผ ๋น ๋ฅด๊ฒ ๋ง๋ค ์ ์์ต๋๋ค.
๐ Summary
์ด UCC๋ STM32F103 + W5500 ๊ธฐ๋ฐ ์ด๋๋ท ๊ฒ์ดํธ์จ์ด๋ก, RS-485(Modbus) ์ผ์ ๋ฐ์ดํฐ๋ฅผ TCP ์๋ฒ์ ์ฐ๋ํ๋ ํ์ฅ IoT ๋ธ๋ฆฟ์ง ๊ตฌ์กฐ๋ฅผ ๋ณด์ฌ์ค๋๋ค.
๐ FAQ
Q1. STM32F103 + W5500 COโ Gateway ํ๋ก์ ํธ๋ ๋ฌด์์ธ๊ฐ์?
์ด ํ๋ก์ ํธ๋ STM32F103C8T6 MCU์ WIZnet W5500์ ์ฌ์ฉํ์ฌ RS-485(Modbus RTU) ์ผ์ ๋ฐ์ดํฐ๋ฅผ TCP ์๋ฒ๋ก ์ ์กํ๋ ์ด๋๋ท ๊ฒ์ดํธ์จ์ด ์์ ์
๋๋ค.
ํ์ฅ RS-485 ๊ธฐ๋ฐ ์ผ์ ๋ฐ์ดํฐ๋ฅผ IP ๋คํธ์ํฌ๋ก ๋ณํํ๋ IoT ๋ธ๋ฆฟ์ง ๊ตฌ์กฐ๋ฅผ ๊ตฌํํฉ๋๋ค.
Q2. ์ด ๊ฒ์ดํธ์จ์ด๋ ์ด๋ค ํต์ ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ๋์?
๊ฒ์ดํธ์จ์ด๋ ๋ค์๊ณผ ๊ฐ์ ๊ตฌ์กฐ๋ก ๋์ํฉ๋๋ค:
- RS-485 (UART ๊ธฐ๋ฐ Modbus RTU) โ STM32 ์์ง
- STM32 โ W5500 (SPI ์ฐ๊ฒฐ) โ TCP Client ํต์
- TCP ์๋ฒ โ STM32 (๋ฌธ์์ด ๊ธฐ๋ฐ ๋ฐ์ดํฐ ์ก์์ )
- ๋ก์ปฌ OLED์ ์ํ ํ์
์ฆ, Field Bus(RS-485) โ Ethernet(TCP/IP) ๋ณํ ๊ตฌ์กฐ์ ๋๋ค.
Q3. WIZnet W5500์ ์ญํ ์ ๋ฌด์์ธ๊ฐ์?
W5500์ ํ๋์จ์ด TCP/IP ์คํ๋ก๋ฉ ๊ธฐ๋ฅ์ ๊ฐ์ง SPI ๊ธฐ๋ฐ Ethernet ์ปจํธ๋กค๋ฌ์ ๋๋ค.
์ด ํ๋ก์ ํธ์์ W5500์:
- TCP Client ์์ผ ์์ฑ
- ์๋ฒ IP/Port๋ก connect ์ํ
- send()/recv() ๊ธฐ๋ฐ ๋ฐ์ดํฐ ์ก์์ ์ฒ๋ฆฌ
- MCU ๋ถํ ๊ฐ์
๋ฅผ ๋ด๋นํฉ๋๋ค.
Q4. ์ W5500์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ ๋ฆฌํ๊ฐ์?
W5500์ TCP/IP ์คํ์ ํ๋์จ์ด๋ก ์ฒ๋ฆฌํ๋ฏ๋ก:
- STM32F103๊ณผ ๊ฐ์ ์ค๊ธ MCU์์๋ ์์ ์ ์ธ TCP ํต์ ๊ฐ๋ฅ
- ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ๊ฐ์
- ์ํํธ์จ์ด ๋คํธ์ํฌ ์คํ ๊ตฌํ ๋ถ๋ด ์ ๊ฑฐ
- ์ฐ์ ์ฉ ๋คํธ์ํฌ ํ๊ฒฝ์์ ๋์ ์์ ์ฑ ์ ๊ณต
๋ฐ๋ผ์ ์ ๋น์ฉ MCU ๊ธฐ๋ฐ ๊ฒ์ดํธ์จ์ด ์ค๊ณ์ ์ ํฉํฉ๋๋ค.
Q5. RS-485(Modbus RTU)๋ ์ด๋ป๊ฒ ์ฒ๋ฆฌ๋๋์?
STM32๋ UART ๊ธฐ๋ฐ RS-485 ์ธํฐํ์ด์ค๋ฅผ ํตํด Modbus RTU ์ง์/์๋ต์ ์ํํฉ๋๋ค.
๊ตฌํ ํน์ง:
- CRC16 ๊ณ์ฐ ํ ํ๋ ์ ์ ์ก
- ์์ ๋ฐ์ดํฐ ํ์ฑ ๊ตฌ์กฐ ํฌํจ
- COโ, ์จ๋ ๋ฑ ์ผ์ ๊ฐ ์ถ์ถ
์ด๋ฅผ ํตํด ํ๋ ์ผ์ ๋ฐ์ดํฐ๋ฅผ ๋์งํธ ๋คํธ์ํฌ๋ก ๋ณํํฉ๋๋ค.
๐ Overview
This is an example of a โfield sensor โ networkโ gateway that links RS-485 (Modbus RTU) sensor data to Ethernet (TCP) using a combination of STM32F103 + WIZnet W5500. It is confirmed from the MCU configuration file that the STM32F103C8T6 series is used.
๐ Features
RS-485 (Modbus RTU) query/response-based sensor data collection
- Includes a structure for transmitting frames after CRC16 calculation and parsing based on received data.
TCP client communication based on W5500 hardware TCP/IP offloading
- Reduces MCU load and enables TCP connection setup using a relatively simple socket API in embedded systems.
Multi-task structure (FreeRTOS-based functional separation)
- Separates communication reception, display, local temperature (DS18B20), and RS-485 collection into individual tasks, making it advantageous for scalability.
Includes local display (OLED) and local temperature sensor (DS18B20)
- Allows the gateway to go beyond a simple relay and provide a UI for on-site debugging and status monitoring.
Basic server integration structure based on fixed IP/port
- Server IP and port are hardcoded in the firmware, enabling rapid PoC (proof-of-concept) implementation.
๐ System Architecture
Components
- MCU: STM32F103C8T6
- Ethernet: WIZnet W5500 (SPI connection, using CS/RST pins)
- Field I/F: RS-485 (UART-based, Modbus RTU)
- Local Sensor/UI: DS18B20 (1-Wire), OLED
Data Flow
- RS-485 sensor โ (Modbus RTU response) โ STM32
- STM32 โ (W5500 socket send/recv) โ TCP server
- When the TCP server sends data to STM32, the project includes a string parsing structure (e.g., in the form of
co2,temperature) - STM32 โ Displays temperature/humidity and other status information on the OLED
๐ Role and Application of the WIZnet's Chip
Chip used: WIZnet W5500
Role in the network:
- TCP client socket communication (connect to server IP/port, then perform send/recv)
๐ Market & Application Value
Applicable Industries/Markets
- Smart factory/building automation: There is steady demand for converting RS-485 (sensors/inverters/meters) โ Ethernet (upper-level control/monitoring systems).
- Greenhouse/environmental monitoring: There are product lines where CO2, temperature/humidity, and air quality sensors are provided via RS-485 (Modbus) (general information about the sensor market).
- Legacy equipment data acquisition: Demand for transitioning โexisting RS-485 devices to IP-based networks.โ
๐ WIZnet Strategic Value
Significance from the Maker ecosystem perspective
- โW5500 + STM32 + RS-485โ is a frequently recurring combination in field IoT, giving it value as a gateway reference template.
- The FreeRTOS task separation structure provides educational value to Maker users as a โscalable code framework.โ
- By using the W5500, it is possible to quickly build a stable Ethernet-based field gateway without requiring a high-performance MCU.
๐ Summary
This UCC presents a field IoT bridge architecture based on an STM32F103 + W5500 Ethernet gateway, linking RS-485 (Modbus) sensor data with a TCP server.
๐ FAQ
Q1. What is the STM32F103 + W5500 COโ Gateway project?
This project is an Ethernet gateway example that uses the STM32F103C8T6 MCU and the WIZnet W5500 to transmit RS-485 (Modbus RTU) sensor data to a TCP server.
It implements an IoT bridge architecture that converts field RS-485-based sensor data into an IP network.
Q2. What communication architecture does this gateway use?
The gateway operates with the following structure:
- RS-485 (UART-based Modbus RTU) โ Data collected by STM32
- STM32 โ W5500 (SPI connection) โ TCP client communication
- TCP server โ STM32 (string-based data transmission and reception)
- Local status displayed on OLED
In other words, it implements a Field Bus (RS-485) โ Ethernet (TCP/IP) conversion architecture.
Q3. What is the role of the WIZnet W5500?
The W5500 is an SPI-based Ethernet controller with hardware TCP/IP offloading capability.
In this project, the W5500 is responsible for:
Creating TCP client sockets
Connecting to the server IP/port
Handling data transmission and reception using send()/recv()
Reducing MCU load
Q4. Why is it advantageous to use the W5500?
Since the W5500 processes the TCP/IP stack in hardware:
- Stable TCP communication is possible even with mid-range MCUs like the STM32F103
- Reduced memory usage
- Eliminates the burden of implementing a software network stack
- Provides high stability in industrial network environments
Therefore, it is well suited for low-cost MCU-based gateway designs.
Q5. How is RS-485 (Modbus RTU) handled?
The STM32 performs Modbus RTU query/response communication through a UART-based RS-485 interface.
Implementation features:
- Frame transmission after CRC16 calculation
- Includes a structure for parsing received data
- Extracts sensor values such as COโ and temperature
Through this process, field sensor data is converted into a digital IP-based network format.
