Couldn't get XIAO ESP32S3 working with W5500 Ethernet module

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...

Start somewhere...

I am not fully familiar with the S3, but isn't that also a TX pin ?

Anyway, try using a different pin (also for CS)

i use

#include "Ethernet_Generic.h"

And have an initialization that first does

  pinMode(RST_PIN, OUTPUT);
  digitalWrite(RST_PIN, LOW);
  delayMicroseconds(500);
  digitalWrite(RST_PIN, HIGH);
  delay(2);
  Ethernet.init(CS_PIN);

The manual reset before init seemed to be required.

These:

should be:

#define MOSI_PIN D10
#define MISO_PIN D9
#define SCK_PIN D8

Because:

Or use:

Those can be available when you select board type as "XIAO_ESP32S3"

this works on a ESP32-S3-DevKitC-1 with a W5500

// ESP32-S3-DevKitC-1 + W56500 Ethernet

/*
 * HelloServer example from the ESP32 WebServer library modified for Ethernet.
 */

#include <EthernetESP32.h>
#include <WebServer.h>
#include <ESPmDNS.h>

 // ESP32_S3_DevKit_1 connections
// ESP32_S3 SCK pin GPIO12  to W5500 SCK
// ESP32_S3 MISO pin GPIO13  to W5500 MISO
// ESP32_S3 MOSI pin GPIO11  to W5500 MOSI
// ESP32_S3 SS  pin GPIO 10   to W5500 SCS



W5500Driver driver;
//ENC28J60Driver driver;
//EMACDriver driver(ETH_PHY_LAN8720);

WebServer server(80);

const int led = 13;

void handleRoot() {
  digitalWrite(led, 1);
  server.send(200, "text/plain", "hello from esp32!");
  digitalWrite(led, 0);
}

void handleNotFound() {
  digitalWrite(led, 1);
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i < server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
  digitalWrite(led, 0);
}

void setup(void) {
  pinMode(led, OUTPUT);
  digitalWrite(led, 0);
  Serial.begin(115200);

  Serial.begin(115200);
  delay(500);
  while (!Serial);

  Ethernet.init(driver);

  Serial.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin()) {
    Serial.print("  DHCP assigned IP ");
    Serial.println(Ethernet.localIP());
  } else {
    Serial.println("Failed to configure Ethernet using DHCP");
    while (true) {
      delay(1);
    }
  }

  if (MDNS.begin("esp32")) {
    Serial.println("MDNS responder started");
  }

  server.on("/", handleRoot);

  server.on("/inline", []() {
    server.send(200, "text/plain", "this works as well");
  });

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
}

void loop(void) {
  server.handleClient();
  delay(2);  //allow the cpu to switch to other tasks
}

Serial monitor displays

Initialize Ethernet with DHCP:
  DHCP assigned IP 192.168.1.70
MDNS responder started
HTTP server started

web client displays

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.