ESP32 W5100S Ethernet Controler on HSPI

Hello, I am currently working on an ESP32 based project that has both Ethernet and LoRa. For the Ethernet connection I am using a W5100S based module (actually a hat for the Pi Pico, but that's not important),¸. I would like to use HSPI with the Ethernet module as I think there isn't enough bandwidth on a single SPI bus for both the Ethernet module, and the LoRa module. I tried modifying the original Arduino Ethernet library to use HSPI but that didn't find the module. I also tried the EthernetSPI2 library but, the built in example didn't work, and when I tried including this library into the example code from the original library it woud "find" the module, but there wouldn't be any data, eg. IP:0.0.0.0.

Do you have any idea what could I try next?

Thank you in advance.

with esp32 arduino platform 3 and a W5500 it is easy because W5500 is supported with bundled Ethernet library and with my EthernetESP32 library. but W5100 is not supported.

Thank you for the information, it seems from my quick search that the w5500 and w5100 should be software compatible, the only difference should be that the w5500 can handle more open sockets at the same time, if I am not mistaken. I have also tried your library and it wont compile, it returns: "fatal error: Network.h: No such file or directory". Do you know where could i find the missing file, as I think making your library work would be the solution to my problem since you have awesome documentation for changing the SPI interface.

this ^

maybe simpler to move the LoRa module to HSPI
which LoRa module are you using?
LoRaWAN or LoRa point-to-point?
which LoRa library?

It might just be easier moving the LoRa module, I have now tried everything I can think of to use HSPI with the Ethernet module, even Juraj's library, it now compiles but I get the "W5500 version mismatched, expected 0x04, got 0x03" error. I am using an SX1280 based module from Ebyte, LoRa point-to-point, and the SX12XX-LoRa library from StuartsProjects.

with the LoRa.h library I used the following to connect a RFM95 to ESP32 HSPI

#include <LoRa.h>

// default HSPI pins used by RFM95 LoRa module
#define HSPI_SCK 14
#define HSPI_MISO 12
#define HSPI_MOSI 13
#define HSPI_CS 15

SPIClass *hspi = new SPIClass(HSPI);      // HSPI object used by MFRC522

void setup() {
  Serial.begin(115200);
  delay(2000);
  Serial.println("\n\nESP32 LoRa RFM95W Receiver");
  // void setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN);
  //LoRa.setPins(8, 4, 7);  // for Lora 32u4
  LoRa.setSPI(*hspi);
  LoRa.setPins(HSPI_CS, 4, 2);  // for ESP32
  if (!LoRa.begin(866E6)) {
    Serial.println("Starting LoRa failed!");
    while (1)    ;
  }
  Serial.println("Starting LoRa OK!");
}

will try with StuartsProjects.

this is using the library from StuartsProjects
not sure if it helps as there appears to be no way to specify the specific SPI port when there is choice, e.g. ESP32 VSPI and HSPI
this changes the default SPI port to use the ESP32 HSPI pins

// Heltec ESP32 LoRa SX1262 receiver text communication

/*******************************************************************************************************
  Programs for Arduino - Copyright of the author Stuart Robinson - 20/01/20
     from https://github.com/StuartsProjects/SX12XX-LoRa
 *******************************************************************************************************/

#include <SPI.h>              //the lora device is SPI based so load the SPI library
#include <SX127XLT.h>         //include the appropriate library
#include "SX1278_Settings.h"  //include the setiings file, frequencies, LoRa settings etc

SX127XLT LT;  //create a library class instance called LT

// receive a packet
char RXBUFFER[RXBUFFER_SIZE];  //create the buffer that received packets are copied into
void loop() {
  // wait for receive data
  int RXPacketL = LT.receive((uint8_t *)RXBUFFER, RXBUFFER_SIZE, 60000, WAIT_RX);  //wait for a packet to arrive with 60seconds (60000mS) timeout
  if (RXPacketL != 0) {                                                            //if the LT.receive() function detects an error, RXpacketL is 0
    Serial.print("Received OK ");
    LT.printASCIIPacket((uint8_t *)RXBUFFER, RXPacketL);  //print the packet as ASCII characters
    int count = 0;
    sscanf(RXBUFFER, "Hello World %d", &count);  // get the packet counter for reply
    transmitReply(count);
  }
}

// transmit reply
char buff[50];
void transmitReply(int count) {
  snprintf(buff, 50, "receive OK %d", count);
  Serial.print(F("\nTransmit Packet> "));
  LT.printASCIIPacket((uint8_t *)buff, strlen(buff));                      //print the buffer (the sent packet) as ASCI                                                  //start transmit timer
  if (LT.transmit((uint8_t *)buff, strlen(buff), 5000, TXpower, WAIT_TX))  //will return packet length sent if OK, otherwise 0 if transmit error
  {
    Serial.println(" Transmited OK!");
  } else {
    Serial.println(" transmit ERROR!");  //transmit packet returned 0, there was an error
  }
  delay(packet_delay);  //have a delay between packets
}

void setup() {
  Serial.begin(115200);
  delay(3000);
  Serial.println();
  Serial.println(F("LoRa_Receiver_ESP32 Starting"));
  Serial.println();
  SPI.begin(SCK, MISO, MOSI, NSS);
  if (LT.begin(NSS, NRESET, DIO0, LORA_DEVICE)) {
    Serial.println(F("LoRa Device found"));
  } else {
    Serial.println(F("No LoRa device responding"));
    while (1) delay(100);
  }
  LT.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate, Optimisation);
}

and the SX1278_Settings.h file (you would use the SX1280 header file)

/*******************************************************************************************************
  Programs for Arduino - Copyright of the author Stuart Robinson - 20/01/20

  This program is supplied as is, it is up to the user of the program to decide if the program is
  suitable for the intended purpose and free from errors.
*******************************************************************************************************/

//*******  Setup hardware pin definitions here ! ***************

//These are the pin definitions for one of the Tracker boards, the ESP32_Micro_Node, be sure to change
//them to match your own setup. You will also need to connect up the pins for the SPI bus, which on the
//ESP32_Micro_Node are SCK on pin 18, MISO on pin 19 and MOSI on pin 23.
// VSPI
//#define NSS 5                                   //select pin on LoRa device
//#define SCK 18                                  //SCK on SPI3
//#define MISO 19                                //MISO on SPI3 
//#define MOSI 23                                 //MOSI on SPI3 

// HSPI
#define NSS 15                                   //select pin on LoRa device
#define SCK 14                                  //SCK on SPI3
#define MISO 12                                //MISO on SPI3 
#define MOSI 13                                 //MOSI on SPI3 

#define NRESET 4                               //reset pin on LoRa device
#define LED1 13                                  //on board LED, high for on
#define DIO0 2                                 //DIO0 pin on LoRa device, used for RX and TX done 
#define VCCPOWER 16                             //pin controls power to external devices

#define LORA_DEVICE DEVICE_SX1278               //we need to define the device we are using


//*******  Setup LoRa Parameters Here ! ***************

//LoRa Modem Parameters
const uint32_t Frequency = 866000000;           //frequency of transmissions in hertz
const uint32_t Offset = 0;                      //offset frequency for calibration purposes

const uint8_t Bandwidth = LORA_BW_125;          //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7;       //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5;           //LoRa coding rate
const uint8_t Optimisation = LDRO_AUTO;         //low data rate optimisation setting, normally set to auto

const int8_t TXpower = 10;                      //LoRa transmit power in dBm

const uint16_t packet_delay = 1000;             //mS delay between packets

#define RXBUFFER_SIZE 32                        //RX buffer size  

when run the serial monitor displays that the LoRa module is found, e.g.

18:01:30.770 -> LoRa Device found
18:01:31.846 -> Received OK Hello World 1234567890*
18:01:31.846 -> Transmit Packet> receive OK 1234567890 Transmited OK!
18:01:33.964 -> Received OK Hello World 1234567890*
18:01:33.964 -> Transmit Packet> receive OK 1234567890 Transmited OK!
18:01:36.079 -> Received OK Hello World 1234567890*
18:01:36.079 -> Transmit Packet> receive OK 1234567890 Transmited OK!
18:01:38.227 -> Received OK Hello World 1234567890*
18:01:38.227 -> Transmit Packet> receive OK 1234567890 Transmited OK!

may have to edit the library files

with the problem of being unable to specify the SPI interface using the library from StuartsProjects as reported in post 8 it may be simpler to get a W5500 module
e.g. using EthernetESP32 library to set up a W5500 to use HSPI to run Fil;e>Examples>EthernetESP32>HelloServer

// ESP32/W5500 ethernet using HSPI interface

// W5500 SCK to HSPI_SCK GPIO14
// W5500 MOSI to HSPI_MOSI GPIO13
// W5500 MISO to HSPI_MISO GPIO12
// W5500 SCS to HSPI_CS GPIO15
// W5500 3.3V to ESP32 3.3V
// W5500 GND to ESP32 GND

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

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

W5500Driver driver(15);  // HSPI SS is GPIO15
//ENC28J60Driver driver;
//EMACDriver driver(ETH_PHY_LAN8720);

SPIClass hspi(HSPI);  // HSPI object used by W5500

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);
  delay(2000);
  while (!Serial)
    ;
  driver.setSPI(hspi);        // specify driver SPI interface
  Ethernet.init(driver);      // initialise 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.65
MDNS responder started
HTTP server started

and webclient displays
image