---
title: "10. W5100S/W5500+RP2040 Raspberry Pi Pico＜PING (ICMP) to detect network connectivity＞"
url: "https://maker.wiznet.io/ronpang/projects/10-w5100s-w5500-rp2040-raspberry-pi-picoping-icmp-to-detect-network-connectivity/"
markdown_url: "https://maker.wiznet.io/ronpang/projects/10-w5100s-w5500-rp2040-raspberry-pi-picoping-icmp-to-detect-network-connectivity/md"
type: "UCC: User Created Content"
author: "WIZnet HK"
author_url: "https://blog.csdn.net/WIZnet2012/article/details/134145655?spm=1001.2014.3001.5502"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "WIZnet HK"
original_url: "https://blog.csdn.net/WIZnet2012/article/details/134145655?spm=1001.2014.3001.5502"
published: "2023-11-20"
language: "en"
hardware: ["WIZnet W5100S-EVB-Pico", "WIZnet W5500-EVB-Pico"]
likes: 0
views: 1103
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# 10. W5100S/W5500+RP2040 Raspberry Pi Pico＜PING (ICMP) to detect network connectivity＞

> 10. W5100S/W5500+RP2040 Raspberry Pi Pico＜PING (ICMP) to detect network connectivity＞

Original author: WIZnet HK (source: https://blog.csdn.net/WIZnet2012/article/details/134145655?spm=1001.2014.3001.5502)

## Components

- **WIZnet W5100S-EVB-Pico** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5100S/w5100s-evb-pico))
- **WIZnet W5500-EVB-Pico** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5500/w5500-evb-pico))

## Documents and links

- [Code for this article](https://gitee.com/wiznet-hk/W5100_W5500_C_SDK.git) (code)
- [WIZnet Official Website](https://www.wiznet.io/)
- [WIZnet Official IOlibrary](https://github.com/Wiznet/ioLibrary_Driver)
- [YouTube Video](https://youtu.be/5g957nRETvQ)

## Article

## 1 Introduction

As network applications become increasingly abundant and popular, the application scenarios of network PING will also continue to expand. For example, the development of the network security field will have an increasing demand for network PING. Through the continuous expansion and development of the network security field, network PING will gain more opportunities and challenges. At the same time, with the popularity of the Internet of Things, network PING will also be more applied to the remote management and monitoring of Internet of Things devices.

W5100S/W5500 is an embedded Ethernet controller integrating a full hardware TCP/IP protocol stack. It is also an industrial-grade Ethernet control chip. This tutorial will introduce the basic principles, usage steps, application examples and precautions of W5100S/W5500 Ethernet PING application to help readers better master this technology.

## 2 Introduction to the protocol

### 2.1 What is PING

PING is a computer network tool used to test connectivity between hosts. It sends an ICMP (Internet Control Message Protocol) echo request message to the target host and waits for the target host to send a reply message. Based on the reception of the reply message, it can be determined whether the target host is reachable, as well as network performance indicators such as the round-trip delay time from the local host to the target host, packet loss rate, and so on. This information can help programmers diagnose network problems, optimize network performance, and ensure the stability of network connections.

### 2.2 Advantages of PING

The main advantages of PING are:

**Connectivity test: **The PING tool can test the connectivity between two computers. By sending an ICMP echo request to the target host and waiting for the target host to send a reply message, if a reply message is received, connectivity exists between the two computers.

**Latency and packet loss rate testing:** The PING tool can also test network performance indicators such as round-trip delay time from the local host to the target host and packet loss rate. This information can help users diagnose network problems, optimize network performance, and ensure the stability of network connections.

**Easy to use: **The PING tool does not require any additional tools or software. You only need to enter the PING command in the terminal window to test.

### 2.3 Principle of PING

![](https://maker.wiznet.io/upload/ckeditor5/265322290%5F1700495234%2Epng)

![](https://maker.wiznet.io/upload/ckeditor5/265322290%5F1700495262%2Epng)

There are mainly the following main steps in the PING request process:

The application layer initiates a PING request to the target host (B).

The transport layer fragments the data and adds headers.

The network layer encapsulates the IP address with the source IP address of A and the IP address of the destination IP address into data packets according to the ICMP protocol.

Based on the target IP address and subnet mask, detect whether A and B belong to the same subnet. If so, search the local machine's ARP cache to find the MAC address of target host B; if not, send an ARP request broadcast based on the gateway's IP address.

After receiving the ARP broadcast, target host B decapsulates it and finds that the requested MAC address is its own, so it writes the sender's MAC address into the ARP cache table, and then sends an ARP reply unicast to A.

A uses B's Mac address as the destination MAC address and encapsulates it into a data frame, and sends it to the network interface layer for transmission.

After B receives this data frame, it first finds that the target MAC address points to itself in the network interface layer, so it removes the frame header and uploads it.

The transport layer receives the PING request message, removes the header, and transmits it to the application layer.

## **2.4 Application scenarios**

PING has a wide range of application scenarios. Here are some common examples:

**Network troubleshooting: **When the network connection fails, you can use the PING command to check whether the network connection is normal. If the destination host cannot be accessed, it may be due to network device failure, network connection interruption, or other problems.

**Network performance test: **The PING command can be used to test network performance indicators such as delay, packet loss rate, and bandwidth. Through these indicators, you can have a comprehensive understanding of the performance of the network.

**Network topology discovery: **You can discover hosts and devices in the network through the PING command and build the network topology. This is very useful for network administrators to help them better understand and manage their networks.

**Network security monitoring: **The PING command can also be used to monitor network security. For example, you can set up a program to regularly PING a specific host. If it is found to be inaccessible, the host may be under attack or malfunctioning.

## 3 WIZnet Ethernet chip

**WIZnet mainstream hardware protocol stack Ethernet chip parameter comparison**

| **Model** | **Embedded Core** | **Host I/F** | **TX/RX Buffer** | **HW Socket** | **Network Performance** |
| --- | --- | --- | --- | --- | --- |
| W5100S | TCP/IPv4， MAC & PHY | 8bit BUS, SPI | 16KB | 4 | Max.25Mbps |
| W6100 | TCP/IPv4/IPv6, MAC & PHY | 8bit BUS, Fast SPI | 32KB | 8 | Max.25Mbps |
| W5500 | TCP/IPv4, MAC & PHY | Fast SPI | 32KB | 8 | Max 15Mbps |

W5100S/W6100 supports 8-bit data bus interface, and the network transmission speed will be better than W5500.

W6100 supports IPV6 and is compatible with W5100S hardware. If users who already use W5100S need to support IPv6, they can be Pin to Pin compatible.

W5500 has more Sockets and send and receive buffers than W5100S.

## 4 PING network setting example overview and usage

### 4.1 Flowchart

The running block diagram of the program is as follows:

![](https://maker.wiznet.io/upload/ckeditor5/265322290%5F1700495435%2Epng)

## **4.2 Core preparation workSoftware:**

Visual Studio Code

WIZnet UartTool

**Hardware:**

W5100SIO module + RP2040 Raspberry Pi Pico development board or WIZnet W5100S-EVB-Pico development board

Micro USB interface data cable

TTL to USB

cable

### 4.3 Connection method

Connect the USB port of the PC through the data cable (mainly used for burning programs, but can also be used as a virtual serial port)

Convert TTL serial port to USB and connect the default pin of UART0:

RP2040 GPIO0 (UART0 TX) &lt;----> USB_TTL_RX

RP2040 GPIO1 (UART0 RX) &lt;----> USB_TTL_TX

When using module connection RP2040 for wiring

RP2040 GPIO16 &lt;----> W5100S MISO

RP2040 GPIO17 &lt;----> W5100S CS

RP2040 GPIO18 &lt;----> W5100S SCK

RP2040 GPIO19 &lt;----> W5100S MOSI

RP2040 GPIO20 &lt;----> W5100S RST

Connect the PC and device to the router LAN port through network cables

### 4.4 Main code overview

We are using the official ioLibrary_Driver library of WIZnet. The library supports rich protocols and is easy to operate. The chip integrates the TCP/IP protocol stack on the hardware. The library also encapsulates the protocols above the TCP/IP layer. We only need to simply call the corresponding function to complete the application of the protocol. .

Step 1: Add the corresponding .h file to the ping_client.c file.

Step 2: Define the macros required for DHCP configuration.

Step 3: Configuration of network information.

Step 4: Write a timer callback processing function for the DHCP 1s tick timer processing function.

Step 5: The main function first initializes the serial port and SPI, and then writes the network configuration parameters of W5100S. After initializing DHCP, it starts DHCP to obtain the IP. When obtained, it prints the obtained IP. When the number of acquisitions exceeds the maximum number of acquisitions, static is used. IP, and then the main loop performs the operation of PING the gateway IP. The parameters that need to be passed in are the socket number to be executed and the target IP to be PING.。

```
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/binary_info.h"
#include "hardware/spi.h"
​
#include "wizchip_conf.h"
#include "bsp_spi.h"
#include "socket.h"
#include "ping.h"
#include "dhcp.h"
​
#define SOCKET_DHCP 1
#define SOCKET_PING 0
#define ETHERNET_BUF_MAX_SIZE (1024 * 2)
#define DHCP_RETRY_COUNT 5 // DHCP retry times
​
wiz_NetInfo net_info = {
    .mac = {0x00, 0x08, 0xdc, 0x16, 0xed, 0x2e}, // Define MAC variables
    .ip = {192, 168, 1, 10},                     // Define IP variables
    .sn = {255, 255, 255, 0},                    // Define subnet variables
    .gw = {192, 168, 1, 1},                      // Define gateway variables
    .dns = {8, 8, 8, 8},                         // Define DNS  variables
    .dhcp = NETINFO_DHCP};                       // Define the DNCP mode
wiz_NetInfo get_info;
static uint8_t ethernet_buf[ETHERNET_BUF_MAX_SIZE] = {
    0,
};
static uint8_t remote_ip[4] = {192, 168, 1, 1}; // The IP to be ping
static uint8_t dhcp_get_ip_flag = 0;            // Define the DHCP acquisition flag
​
/**
 * @brief   Timer callback processing function, used for dhcp timing processing
 * @param   repeating :Timer structure
 * @return  bool
 */
bool repeating_timer_callback(struct repeating_timer *t);
​
/**
 * @brief   Initialization of chip network information
 * @param   conf_info :Static configuration information
 * @return  none
 */
void network_init(wiz_NetInfo *conf_info);
​
int main()
{
    struct repeating_timer timer; // Define the timer structure
​
    /*mcu init*/
    stdio_init_all();     // Initialize the main control peripheral
    wizchip_initialize(); // spi initialization
​
    /*dhcp init*/
    DHCP_init(SOCKET_DHCP, ethernet_buf);                                 // DHCP initialization
    add_repeating_timer_ms(1000, repeating_timer_callback, NULL, &timer); // Add DHCP 1s Tick Timer handler
​
    printf("wiznet chip ping client example.\r\n");
    network_init(&net_info);              // Configuring Network Information
    print_network_information(&get_info); // Read back the configuration information and print it
​
    while (true)
    {
        do_ping(SOCKET_PING, remote_ip); // Ping the target IP
    }
}
```

### 4.5 Burning Verification

![](https://maker.wiznet.io/upload/ckeditor5/265322290%5F1700495610%2Epng)

Open WIZ UartTool, fill in the parameters: select the COM Port corresponding to the serial port, baud rate 115200, 8 data bits, 1 stop bit, no check bit, no flow control, click open after filling in the parameters.

Press reset, you can see that after obtaining the IP through DHCP, the dynamic IP is obtained, and then use the obtained IP192.168.1.137 to PING the target IP192.168.1.1. You can see that the PING is successful and the PING related information is printed out. information.

## 5 Precautions

If the device is directly connected to the computer and a static IP is used because the dynamic IP cannot be obtained, the static IP and the computer IP must be set to the same network segment, otherwise the ping cannot be successful.

Note that the socket number of PING and the socket number of DHCP cannot be the same, otherwise it will cause socket number conflict and PING failure.

If we want to use WIZnet's W5500 to implement the example in this chapter, we only need to modify two places:

(1) Find the wizchip_conf.h header file under library/ioLibrary_Driver/Ethernet/, and modify the WIZCHIP macro definition to W5500;

(2) Find the CMakeLists.txt file under library and set COMPILE_SEL to ON. OFF is W5100S and ON is W5500.

---

Source: https://maker.wiznet.io/ronpang/projects/10-w5100s-w5500-rp2040-raspberry-pi-picoping-icmp-to-detect-network-connectivity/
