Wiznet makers

ronpang

Published June 28, 2024 ©

125 UCC

10 WCC

32 VAR

0 Contests

1 Followers

0 Following

Original Link

[Digi-Key Follow me Issue 4] Getting Started Tasks | Basic Task 1: Setting up the Environment and Pi

[Digi-Key Follow me Issue 4] Getting Started Tasks | Basic Task 1: Setting up the Environment and Pinging the Network

COMPONENTS Hardware components

WIZnet - W5500-EVB-Pico

x 1


PROJECT DESCRIPTION

Target

Build the development environment of RP2040 Pico + W5500 EVB

Control the onboard LED to blink to confirm that the hardware is normal

Initialize W5500, and confirm that the network connection is normal through the Ethernet Ping (Packet Internet Groper) command

Capture packets through wireshark and analyze ICMP packets

Theory

ICMP packet frame structure:

ICMP (Internet Control Message Protocol) is a network protocol that is used to transmit control information and error messages in IP networks. It is usually used with the IP protocol. The IP protocol is responsible for sending and routing data packets, while the ICMP protocol is responsible for checking whether the network is reachable, whether the route is correct, whether the host is reachable, and other network status feedback information.

The main functions of the ICMP protocol are as follows:

Discover network errors: When a data packet has an error during transmission, the ICMP protocol discovers network errors by sending an error notification to the sender.

Check whether the network is reachable: By sending ICMP ECHO requests and receiving ICMP ECHO reply messages, you can determine whether the target host is reachable.

Detect host errors: When a host fails to work properly, the ICMP protocol detects host errors by sending error notifications to the sender.

Send routing information: The ICMP protocol can send routing information to other hosts to help them find appropriate routes in the network.

Reference link

For more information about the ping command, please refer to: ping command

For more information about ICMP commands: Detailed analysis of ICMP commands

Hardware

  • When performing the experiment for this task, the expansion baseboard of Follow M3 Phase 1 Pico is used to facilitate the connection of subsequent peripheral devices.

At the same time, if you need to use SPI externally, try to avoid SPI multiplexing or mutual interference with the W5500 connection.

Other notes: The learning video provided by EEWorld uses the W5500 Pico EVB to connect through a router or switch, and then uses a PC to test the network. Therefore, the Ethernet cable is connected with a straight line. If the W5500 development board is directly connected to the Ethernet port of the PC, a crossover cable is required.

ps: Since this experiment was conducted during the holiday, there are no "high-end devices" such as routers/switches in my hometown, so the following experiments are all conducted using a PC and W5500 development link method.

software

Burning firmware

  • Connect the USB of W5500 Pico EVB to the computer via micro USB cable, then press and hold the bootlsel button, and then click the RUN button. The USB drive letter will appear on the PC.。

Download the UF2 file from the following download link: adafruit-circuitpython-wiznet_w5500_evb_pico-en_GB-8.2.9.uf2.
Download the firmware
Then drag the UF2 file into the drive letter. After the firmware is successfully burned, you can use MUEditor to program cirupython.

Test LED Blink

Use the simplest blinky program to test that the development environment and hardware are working properly.

Copy

  1. # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
  2. #
  3. # SPDX-License-Identifier: MIT
  4.  
  5. """Example for Pico. Turns on the built-in LED."""
  6. import board
  7. import digitalio
  8.  
  9. led = digitalio.DigitalInOut(board.LED)
  10. led.direction = digitalio.Direction.OUTPUT
  11.  
  12. while True:
  13. led.value = True
  14.  

Ping network

Refer to the lib file in the RP2040-HAT-CircuitPython example repository and import the W5500 library file into the development board.

Refer to the network ping test example in the RP2040-HAT-CircuitPython example repository for testing.

Copy

  1. import board
  2. import busio
  3. import digitalio
  4. import time
  5. from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
  6.  
  7. ##SPI0
  8. SPI0_SCK = board.GP18
  9. SPI0_TX = board.GP19
  10. SPI0_RX = board.GP16
  11. SPI0_CSn = board.GP17
  12.  
  13. ##reset
  14. W5x00_RSTn = board.GP20
  15.  
  16. print("Wiznet5k Ping Test (no DHCP)")
  17.  
  18. # Setup your network configuration below
  19. # random MAC, later should change this value on your vendor ID
  20. MY_MAC = (0x00, 0x01, 0x02, 0x03, 0x04, 0x05)
  21. IP_ADDRESS = (192, 168, 1, 100)
  22. SUBNET_MASK = (255, 255, 255, 0)
  23. GATEWAY_ADDRESS = (192, 168, 1, 1)
  24. DNS_SERVER = (8, 8, 8, 8)
  25.  
  26. led = digitalio.DigitalInOut(board.GP25)
  27. led.direction = digitalio.Direction.OUTPUT
  28.  
  29. ethernetRst = digitalio.DigitalInOut(W5x00_RSTn)
  30. ethernetRst.direction = digitalio.Direction.OUTPUT
  31.  
  32. # For Adafruit Ethernet FeatherWing
  33. cs = digitalio.DigitalInOut(SPI0_CSn)
  34. # For Particle Ethernet FeatherWing
  35. # cs = digitalio.DigitalInOut(board.D5)
  36. spi_bus = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX)
  37.  
  38. # Reset W5500 first
  39. ethernetRst.value = False
  40. time.sleep(1)
  41. ethernetRst.value = True
  42.  
  43. # Initialize ethernet interface with DHCP
  44. # eth = WIZNET5K(spi_bus, cs)
  45. # Initialize ethernet interface without DHCP
  46. eth = WIZNET5K(spi_bus, cs, is_dhcp=False, mac=MY_MAC)
  47.  
  48. # Set network configuration
  49. eth.ifconfig = (IP_ADDRESS, SUBNET_MASK, GATEWAY_ADDRESS, DNS_SERVER)
  50.  
  51. print("Chip Version:", eth.chip)
  52. print("MAC Address:", [hex(i) for i in eth.mac_address])
  53. print("My IP address is:", eth.pretty_ip(eth.ip_address))
  54.  
  55. while True:
  56. led.value = not led.value
  57. time.sleep(1)
  58.  
  59. print("Done!")
  60.  
  61.  
  62.  
 
 
 
Baidu cloud
Ping the network


 

  • On the PC side, you need to configure the IPv4 IP address in the 192.168.1.xx network segment.
  • Open a cmd window and execute ping: ping 192.168.1.100 -t
  • Serial port data log IP address printing

Packet capture

By capturing the packet as follows, you can see the ICMP data packet, and through the Type field, you can see the request packet and the response packet.

 
Documents
Comments Write