---
title: "How to Implement GPIO Debouncing and TCP Communication on W55MH32?"
url: "https://maker.wiznet.io/ronpang/projects/how-to-implement-gpio-debouncing-and-tcp-communication-on-w55mh32/"
markdown_url: "https://maker.wiznet.io/ronpang/projects/how-to-implement-gpio-debouncing-and-tcp-communication-on-w55mh32/md"
type: "UCC: User Created Content"
author: "weixin_30687051"
author_url: "https://blog.csdn.net/weixin_30687051/article/details/159334220?ops_request_misc=&request_id=&biz_id=102&utm_term=W55MH32&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-4-159334220.142^v102^pc_search_result_base9&spm=1018.2226.3001.4187"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "weixin_30687051"
original_url: "https://blog.csdn.net/weixin_30687051/article/details/159334220?ops_request_misc=&request_id=&biz_id=102&utm_term=W55MH32&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-4-159334220.142^v102^pc_search_result_base9&spm=1018.2226.3001.4187"
published: "2026-04-10"
language: "en"
likes: 0
views: 246
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# How to Implement GPIO Debouncing and TCP Communication on W55MH32?

> This project demonstrates how to implement stable GPIO input handling on the W55MH32 while transmitting button events over TCP.

Original author: weixin_30687051 (source: https://blog.csdn.net/weixin_30687051/article/details/159334220?ops_request_misc=&request_id=&biz_id=102&utm_term=W55MH32&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-4-159334220.142^v102^pc_search_result_base9&spm=1018.2226.3001.4187)

## Article

## How to Implement GPIO Debouncing and TCP Communication on W55MH32?

### Summary

This project demonstrates how to implement stable GPIO input handling on the W55MH32 while transmitting button events over TCP. The W55MH32 integrates an MCU with a hardware TCP/IP Ethernet controller, enabling deterministic network communication without software stacks. It is used here as both the debounce-processing unit and the network transport layer for reliable event delivery in educational embedded systems.

### What the Project Does

The project focuses on reading mechanical button inputs through GPIO while eliminating signal noise caused by contact bounce. Without filtering, a single press can generate multiple rapid transitions, leading to false triggers.

The system combines:

- **GPIO input sampling** for button state detection

- **Software debounce logic** to filter unstable transitions

- **TCP communication** to transmit validated button events to a remote host (e.g., PC or server)

- Optional **hardware RC filtering** to further stabilize the signal

The data flow is straightforward:
Button press → GPIO interrupt/polling → debounce validation → event packaging → TCP transmission.

This makes it suitable for teaching reliable input handling in network-connected embedded systems.

### Where WIZnet Fits

The **W55MH32** is central to this design, combining MCU functionality with a hardware TCP/IP stack.

Its role includes:

- **GPIO control and debounce execution** on the MCU side

- **TCP socket handling via hardware offload**, eliminating the need for LwIP or similar stacks

- **Deterministic Ethernet communication**, ensuring that validated button events are transmitted without timing jitter

This integration is particularly useful in educational environments where:

- MCU resources are limited

- Students need to understand both embedded I/O and networking

- Simplified software architecture improves learning clarity

Unlike STM32 + LwIP setups, the W55MH32 avoids software TCP/IP overhead, allowing the firmware to focus on input logic.

### Implementation Notes

The original article explains debounce using both hardware and software approaches, but does not provide a full WIZnet TCP integration codebase.

Below is a **conceptual integration example based on WIZnet ioLibrary**:

// Conceptual integration example based on WIZnet ioLibrary

#include "wizchip_conf.h"
#include "socket.h"

#define BUTTON_PIN GPIO_PIN_0
#define DEBOUNCE_MS 20

static uint8_t last_state = 0;
static uint32_t last_time = 0;

void check_button_and_send(void) {
uint8_t current = gpio_read(BUTTON_PIN);
uint32_t now = millis();

// Debounce logic: state must be stable for 20ms
if (current != last_state) {
if ((now - last_time) > DEBOUNCE_MS) {
last_state = current;
last_time = now;

// Send event via TCP when valid press detected
if (current == 1) {
uint8_t msg[] = "BUTTON_PRESSED\n";
send(0, msg, sizeof(msg), 0); // socket 0
}
}
}
}

**Why this matters:**

- Debounce ensures **signal integrity before network transmission**

- TCP send is triggered only on **validated state changes**

- Hardware TCP/IP offload keeps timing consistent even during network activity

### Practical Tips / Pitfalls

- Use **20–50 ms debounce windows** depending on switch quality

- Combine **hardware RC filter + software debounce** for noisy environments

- Ensure **SPI stability** if external PHY/stack interaction is used

- Monitor **link status** before sending TCP data to avoid blocking

- Allocate socket buffers carefully if multiple events are transmitted rapidly

- Avoid sending data inside tight polling loops without debounce validation

- Use watchdog timers to recover from unexpected network stalls

### FAQ

**Q: Why use W55MH32 instead of STM32 for this project?**
A: W55MH32 integrates a hardware TCP/IP stack, eliminating the need for LwIP. This reduces CPU load and simplifies firmware, especially when combining GPIO processing with networking.

**Q: How does W55MH32 connect for TCP communication?**
A: It includes an internal Ethernet controller, so no external TCP/IP stack is required. The MCU communicates with the network hardware internally, unlike STM32 which typically requires external PHY and software stack.

**Q: What role does W55MH32 play in this project?**
A: It performs both GPIO debounce processing and TCP event transmission, acting as a self-contained input-to-network bridge.

**Q: Can beginners follow this project?**
A: Yes, it is suitable for intermediate beginners familiar with GPIO and basic networking. The reduced software complexity (no LwIP) makes it easier to understand end-to-end behavior.

**Q: How does this compare to STM32 GPIO + LwIP approach?**
A: STM32 requires a software TCP/IP stack, increasing memory usage and timing variability. W55MH32 offloads TCP handling to hardware, resulting in more deterministic timing and simpler firmware design.

### Source

- Original Article: <https://blog.csdn.net/weixin_30687051/article/details/159334220>

- License: Not specified (CSDN blog content)

### Tags

#W55MH32 #GPIO #Debounce #TCP #EmbeddedSystems #Ethernet #MQTT #STM32Comparison #Education #WIZnet

## W55MH32에서 GPIO 디바운싱과 TCP 통신을 구현하는 방법은?

### Summary

이 프로젝트는 W55MH32에서 기계식 버튼 입력을 안정적으로 처리하면서, 검증된 버튼 이벤트를 TCP로 전송하는 방법을 보여줍니다. W55MH32는 MCU와 하드웨어 TCP/IP 이더넷 컨트롤러를 함께 통합한 구조이므로, 소프트웨어 네트워크 스택 없이도 비교적 결정론적인 통신 구성이 가능합니다. 이 프로젝트에서 W55MH32는 디바운싱 처리와 네트워크 전송을 동시에 담당하는 핵심 장치로 사용됩니다.

### What the Project Does

이 프로젝트의 핵심은 GPIO를 통해 기계식 버튼 입력을 읽고, 접점 바운스로 인해 발생하는 불안정한 신호를 제거하는 것입니다. 디바운싱이 없으면 버튼을 한 번 눌렀을 때도 짧은 시간 동안 여러 번 상태가 바뀐 것처럼 감지되어 오동작이 발생할 수 있습니다.

이 시스템은 다음 요소로 구성됩니다.

- **GPIO 입력 샘플링**: 버튼 상태 감지

- **소프트웨어 디바운싱 로직**: 불안정한 상태 변화 제거

- **TCP 통신**: 유효한 버튼 이벤트를 원격 호스트(PC 또는 서버)로 전송

- 필요 시 **하드웨어 RC 필터링**: 입력 신호 안정성 추가 확보

데이터 흐름은 단순합니다.

버튼 입력 → GPIO 인터럽트 또는 폴링 → 디바운스 검증 → 이벤트 패키징 → TCP 전송

이 구조는 교육용 임베디드 시스템에서 안정적인 입력 처리와 네트워크 통신을 함께 설명하기에 적합합니다.

### Where WIZnet Fits

이 설계에서 **W55MH32**는 핵심 역할을 합니다. 이 장치는 MCU 기능과 하드웨어 TCP/IP 스택을 함께 제공하므로, GPIO 처리와 네트워크 전송을 한 플랫폼 안에서 다룰 수 있습니다.

이 프로젝트에서의 역할은 다음과 같습니다.

- MCU 측에서 **GPIO 제어와 디바운싱 실행**

- **TCP 소켓 처리의 하드웨어 오프로드**를 통해 LwIP 같은 소프트웨어 스택 의존도 감소

- 검증된 버튼 이벤트를 보다 안정적으로 전송하기 위한 **유선 이더넷 기반 통신 경로 제공**

이 접근 방식은 특히 교육 환경에서 유용합니다.

- MCU 자원이 제한적인 상황에서도 구조를 단순하게 유지할 수 있음

- 학습자가 임베디드 I/O와 네트워크를 한 번에 이해할 수 있음

- 소프트웨어 구조가 단순해져 학습 난이도를 낮출 수 있음

STM32 GPIO + LwIP 방식과 비교하면, W55MH32는 네트워크 처리 부담을 줄여 펌웨어가 입력 처리 로직에 더 집중할 수 있다는 점이 장점입니다.

### Implementation Notes

원문 글은 하드웨어 방식과 소프트웨어 방식의 디바운싱 개념을 설명하지만, WIZnet TCP 통합 전체 코드 저장소를 직접 제공하지는 않습니다.

따라서 아래 코드는 **WIZnet ioLibrary 기반의 개념적 통합 예시**입니다.

// Conceptual integration example based on WIZnet ioLibrary

#include "wizchip_conf.h"
#include "socket.h"

#define BUTTON_PIN GPIO_PIN_0
#define DEBOUNCE_MS 20

static uint8_t last_state = 0;
static uint32_t last_time = 0;

void check_button_and_send(void) {
uint8_t current = gpio_read(BUTTON_PIN);
uint32_t now = millis();

// Debounce logic: state must be stable for 20ms
if (current != last_state) {
if ((now - last_time) > DEBOUNCE_MS) {
last_state = current;
last_time = now;

// Send event via TCP when valid press detected
if (current == 1) {
uint8_t msg[] = "BUTTON_PRESSED\n";
send(0, msg, sizeof(msg), 0); // socket 0
}
}
}
}

이 코드가 중요한 이유는 다음과 같습니다.

- 디바운싱을 먼저 수행해 **유효한 입력만 네트워크로 전송**할 수 있음

- TCP 전송이 **검증된 상태 변화**에서만 발생하도록 제한할 수 있음

- 네트워크 처리를 하드웨어가 담당하면 입력 처리 타이밍이 더 예측 가능해짐

MQTT를 함께 고려한다면, 버튼 이벤트를 바로 TCP 페이로드로 보내는 대신 MQTT publish 메시지의 트리거로 사용할 수 있습니다. 이 경우에도 핵심은 동일합니다. 먼저 디바운싱으로 입력 신뢰성을 확보하고, 그 다음에 네트워크 계층으로 이벤트를 넘겨야 합니다.

### Practical Tips / Pitfalls

- 버튼 품질에 따라 **20~50ms 디바운스 시간**을 조정하는 것이 안전합니다.

- 노이즈가 많은 환경에서는 **RC 필터와 소프트웨어 디바운싱을 함께** 사용하는 편이 낫습니다.

- TCP 전송 전에 **링크 상태**를 확인하지 않으면 송신 실패나 블로킹 상황이 생길 수 있습니다.

- 짧은 주기의 폴링 루프에서 디바운싱 없이 바로 send를 호출하면 중복 이벤트가 쉽게 발생합니다.

- 여러 이벤트를 빠르게 전송하는 구조라면 **소켓 버퍼 사용량**을 먼저 점검해야 합니다.

- MQTT를 사용할 경우에도 버튼 바운스를 제거하지 않으면 **중복 publish** 문제가 그대로 발생합니다.

### FAQ

**Q: 왜 이 프로젝트에 W55MH32를 사용하나요?**
A: GPIO 입력 처리와 TCP 통신을 한 장치 안에서 함께 다룰 수 있기 때문입니다. STM32처럼 별도의 소프트웨어 TCP/IP 스택을 얹는 방식보다 구조가 단순하고, 교육용 예제로 설명하기도 더 수월합니다.

**Q: W55MH32는 플랫폼에 어떻게 연결되나요?**
A: 이 프로젝트에서는 W55MH32 자체가 GPIO 입력 처리와 이더넷 통신의 중심이 됩니다. 즉, STM32에 외부 이더넷 컨트롤러를 붙이는 구조와 달리, 입력 감지와 TCP 송신을 같은 장치 내부에서 처리하는 구성이 가능합니다.

**Q: 이 프로젝트에서 W55MH32는 정확히 어떤 역할을 하나요?**
A: 버튼 입력을 읽고, 디바운싱으로 유효한 상태 변화를 걸러낸 뒤, 그 결과를 TCP 패킷으로 송신하는 입력-네트워크 브리지 역할을 합니다. MQTT를 붙일 경우에도 publish 트리거를 만드는 앞단 처리 역할은 동일합니다.

**Q: 초보자도 따라할 수 있나요?**
A: GPIO 입력, 타이머 기반 지연 처리, TCP 소켓의 기본 개념을 알고 있다면 교육용 프로젝트로 충분히 따라갈 수 있습니다. 다만 인터럽트 처리와 네트워크 송수신 흐름을 함께 이해해야 하므로 완전 입문자보다는 초중급 수준에 더 적합합니다.

**Q: STM32 GPIO 방식과 비교하면 어떤 차이가 있나요?**
A: STM32 GPIO 자체는 입력 처리에 문제없지만, 네트워크까지 포함하면 일반적으로 외부 Ethernet PHY 또는 컨트롤러와 소프트웨어 스택 구성이 추가됩니다. 반면 W55MH32는 GPIO 처리와 TCP 통신을 더 단순한 구조로 묶을 수 있어, 교육 목적이나 소형 네트워크 노드 설계에서 더 직접적인 설명이 가능합니다.

### Source

- Original Article: CSDN 블로그의 W55MH32 GPIO 디바운싱 관련 글

- License: 명시되지 않음

### Tags

#W55MH32 #GPIO #Debounce #TCP #MQTT #EmbeddedSystems #Ethernet #STM32 #Education #WIZnet

---

Source: https://maker.wiznet.io/ronpang/projects/how-to-implement-gpio-debouncing-and-tcp-communication-on-w55mh32/
