Couldn’t get XIAO ESP32S3 to work with W5500 Ethernet module through SPI communication
I am having trouble trying to get the XIAO ESP32S3 to work with a W5500 Ethernet module. The XIAO ESP32S3 comes with a WiFi antenna for connecting to a modem or router wirelessly. However, instead of using WiFi, I want to connect to the network via an Ethernet connection using the W5500. For some reason the W5500 Ethernet module just could not initialize or gets stuck during initialization.
Previously, I was using the XIAO SAMD21 (Getting Started with Seeed Studio XIAO SAMD21 | Seeed Studio Wiki) with the same W5500 Ethernet module and it worked without any problem using the same pin layout wiring and the Ethernet_Generic (GitHub - khoih-prog/Ethernet_Generic: Simple Ethernet library for AVR, AVR Dx, Portenta_H7, Teensy, SAM DUE, SAMD21, SAMD51, STM32F/L/H/G/WB/MP1, nRF52 and RASPBERRY_PI_PICO boards using Ethernet shields W5100, W5200, W5500, W5100S, W6100. With this library you can use the Arduino Ethernet (shield or board) to connect to Internet to provides both Client and server functionalities.) library. But I wanted to switch over to using the XIAO ESP32S3 since it is capable of remote code upload using OTA (https://docs.arduino.cc/arduino-cloud/features/ota-getting-started/).
With the XIAO ESP32S3 and the W5500 Ethernet module, I tried all sorts of methods to try to get the ESP32S3 to communicate with the W5500. I tried switching to various Ethernet libraries like Ethernet_Generic.h, Ethernet.h, Ethernet2.h, Ethernet3.h, and EthernetENC.h. I even tried using different pins and still no luck.
Is the W5500 Ethernet module compatible with the XIAO ESP32S3? Am I using the wrong library or is there no library that supports the XIAO ESP32S3 with a W5500? Am I doing something wrong? Help is appreciated.
Below is some information about the setup I’m using and the code.
Hardware Used
XIAO ESP32S3: Pin Multiplexing with Seeed Studio XIAO ESP32S3 (Sense) | Seeed Studio Wiki
W5500 Ethernet module:
Image of Hardware Setup
ESP32S3 to W5500 Wiring
D10: MOSI → MOSI (8)
D9: MISO → MISO (9)
D8: SCK → SCLK (6)
D7: Use for CS → SCS (7)
D6: Use for RST → RST (3)
GND → GND (4)
3V3 → 3.3V (10)
Code
#include <SPI.h>
#include <Ethernet_Generic.h>
#include <Ethernet_Generic.hpp>
// #include <EthernetENC.h>
// #include <Ethernet.h>
// #include <Ethernet2.h>
// #include <Ethernet3.h>
// #include <EthernetESP32.h>
// #include <Ethernet/W5500.h>
#include <ESPping.h>
#define MOSI_PIN 10
#define MISO_PIN 9
#define SCK_PIN 8
#define CS_PIN 7
#define RST_PIN 6
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 };
IPAddress ethIP(192, 168, 66, 150);
IPAddress gateway(192, 168, 66, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8);
// W5500 eth(&SPI, CS_PIN, 0);
// SPIClass hspi(HSPI);
void setup() {
Serial.begin(115200);
pinMode(CS_PIN, OUTPUT);
// pinMode(7, OUTPUT);
digitalWrite(CS_PIN, HIGH);
// digitalWrite(7, HIGH);
// resetW5500();
SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);
// SPI.begin(8, 9, 10, 7);
// SPI.setFrequency(10000000); // 10 MHz
// SPI.setDataMode(SPI_MODE0);
delay(3000);
Serial.println("Initializing W5500 ...");
while (true) {
delay(1000);
// uint8_t response = readW5500Version();
// Serial.print("W5500 response: 0x");
// Serial.println(response, HEX);
// if (response != 0x04) {
// Serial.println("W5500 not responding. Retrying...");
// // resetW5500();
// delay(3000);
// continue;
// }
// Ethernet.setSPI(CS_PIN);
// Ethernet.setCsPin(CS_PIN);
Ethernet.init(CS_PIN);
// Ethernet.init(eth);
Ethernet.begin(mac, ethIP, primaryDNS, gateway, subnet);
if (Ethernet.localIP()) {
Serial.println("Ethernet hardware not found. Retrying...");
delay(1000);
continue;
}
Serial.println("Ethernet initialized!");
Serial.print("IP Address: ");
Serial.println(Ethernet.localIP());
break; // success, break out of the loop
}
}
void loop() {
pingModem2();
delay(3000);
}
uint8_t readW5500Version() {
digitalWrite(CS_PIN, LOW);
// digitalWrite(7, LOW);
SPI.transfer(0x00);
SPI.transfer(0x39);
SPI.transfer(0x00);
uint8_t ver = SPI.transfer(0x00);
digitalWrite(CS_PIN, HIGH);
// digitalWrite(7, HIGH);
return ver;
}
// void resetW5500() {
// pinMode(RST_PIN, OUTPUT);
// digitalWrite(RST_PIN, LOW);
// delay(100);
// digitalWrite(RST_PIN, HIGH);
// delay(200);
// }
void pingModem2() {
if (Ping.ping(gateway)) {
Serial.print("Ping ");
Serial.print(gateway);
Serial.println(" successful");
} else {
Serial.print("Ping ");
Serial.print(gateway);
Serial.println(" failed!");
}
}
Error Messages:
Using Ethernet_Generic:
11:29:32.886 -> Initializing W5500 …
11:29:34.545 -> [ETG] W5100::init: no chip :-(
11:29:34.545 -> Ethernet hardware not found. Retrying...
11:29:37.178 -> [ETG] W5100::init: no chip :-(
11:29:37.178 -> Ethernet hardware not found. Retrying...
11:29:39.798 -> [ETG] W5100::init: no chip :-(
11:29:39.798 -> Ethernet hardware not found. Retrying...
Using EthernetENC (stuck on initializing):
11:34:02.322 -> Initializing W5500 ...
Using Ethernet:
11:39:36.419 -> Initializing W5500 ...
11:39:38.038 -> Ethernet hardware not found. Retrying...
11:39:40.659 -> Ethernet hardware not found. Retrying...
11:39:43.279 -> Ethernet hardware not found. Retrying...
11:39:45.900 -> Ethernet hardware not found. Retrying...
11:39:48.536 -> Ethernet hardware not found. Retrying...
Using Ethernet2:
11:46:04.921 -> Initializing W5500 ...
11:46:06.949 -> Ethernet hardware not found. Retrying...
11:46:09.924 -> Ethernet hardware not found. Retrying...
11:46:12.972 -> Ethernet hardware not found. Retrying...
11:46:15.925 -> Ethernet hardware not found. Retrying…
Using Ethernet3:
11:49:52.794 -> Initializing W5500 ...
11:49:54.819 -> Ethernet hardware not found. Retrying...
11:49:57.807 -> Ethernet hardware not found. Retrying...
11:50:00.802 -> Ethernet hardware not found. Retrying...
11:50:03.803 -> Ethernet hardware not found. Retrying...
11:50:06.809 -> Ethernet hardware not found. Retrying...



