ESP32 with W5500 Ethernet Adapter

mgarbuli
Posts: 1
Joined: Sun Mar 20, 2022 9:11 pm

ESP32 with W5500 Ethernet Adapter

Postby mgarbuli » Sun Mar 20, 2022 9:48 pm

Hi there!
I´m totally newbie with Esp32.
I found a code for interface the esp32 with the W5500. It works fine. I found this code here: https://www.youtube.com/watch?v=z2PI0eP48Nw .

I have tried make a webserver with this code. Here is:

Code: Select all

/*
teste rede
 */

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include "local_config.h" // <--- Change settings for YOUR network here.

// A UDP instance to let us send and receive packets over UDP.
EthernetUDP Udp;
///////////
// ***************************************************************************************************
// *  Arquivos de include básicos                                                                    *  
// ***************************************************************************************************
#include "ESPAsyncWebServer.h"    // Biblioteca de servidor web

#include "SPIFFS.h"               // Biblioteca do sistema de arquivos SPIFFS

// ***************************************************************************************************
// *  Definições auxiliares                                                                          *
// ***************************************************************************************************
#define OFF           0
#define ON            1

// ***************************************************************************************************
// *  Definição da pinagem                                                                           *
// ***************************************************************************************************
// Digitais
#define LED           13              // Pino ligado ao LED

// ***************************************************************************************************
// *  Variáveis globais                                                                              *
// ***************************************************************************************************
String ledState;                     // Estado do LED

// ***************************************************************************************************
// *  Cria instâncias das classes e objetos necessários                                              *
// ***************************************************************************************************
AsyncWebServer server(80);            // Cria objeto para servidor associado à porta 80

/*
 * Wiz W5500 reset function.  Change this for the specific reset
 * sequence required for your particular board or module.
 */
void WizReset() {
    Serial.print("Resetting Wiz W5500 Ethernet Board...  ");
    pinMode(RESET_P, OUTPUT);
    digitalWrite(RESET_P, HIGH);
    delay(250);
    digitalWrite(RESET_P, LOW);
    delay(50);
    digitalWrite(RESET_P, HIGH);
    delay(350);
    Serial.println("Done.");
}

void prt_hwval(uint8_t refval) {
    switch (refval) {
    case 0:
        Serial.println("No hardware detected.");
        break;
    case 1:
        Serial.println("WizNet W5100 detected.");
        break;
    case 2:
        Serial.println("WizNet W5200 detected.");
        break;
    case 3:
        Serial.println("WizNet W5500 detected.");
        break;
    default:
        Serial.println
            ("UNKNOWN - Update espnow_gw.ino to match Ethernet.h");
    }
}

void prt_ethval(uint8_t refval) {
    switch (refval) {
    case 0:
        Serial.println("Uknown status.");
        break;
    case 1:
        Serial.println("Link flagged as UP.");
        break;
    case 2:
        Serial.println("Link flagged as DOWN. Check cable connection.");
        break;
    default:
        Serial.println
            ("UNKNOWN - Update espnow_gw.ino to match Ethernet.h");
    }
}


void setup() {
    Serial.begin(115200);
    delay(500);
    Serial.println("\n\tteste de rede\r\n");
    /////
    // Configuração das portas utilizadas
    pinMode(LED, OUTPUT);                  //Habilita porta como saída

  // Initializa o sistema de arquivos SPIFFS
  if(!SPIFFS.begin(true)){
    #if (DEBUG==ON)
      Serial.println("O sistema de arquivos SPIFFS não pode ser iniciado!");
      return;
    #endif
  }

    // Use Ethernet.init(pin) to configure the CS pin.
    Ethernet.init(5);           // GPIO5 on the ESP32.
    WizReset();
    
    Serial.println("Starting ETHERNET connection...");
    Ethernet.begin(eth_MAC, eth_IP, eth_DNS, eth_GW, eth_MASK);

    delay(200);

    Serial.print("Ethernet IP is: ");
    Serial.println(Ethernet.localIP());

    /*
     * Sanity checks for W5500 and cable connection.
     */
    Serial.print("Checking connection.");
    bool rdy_flag = false;
    for (uint8_t i = 0; i <= 20; i++) {
        if ((Ethernet.hardwareStatus() == EthernetNoHardware)
            || (Ethernet.linkStatus() == LinkOFF)) {
            Serial.print(".");
            rdy_flag = false;
            delay(80);
        } else {
            rdy_flag = true;
            break;
        }
    }
    if (rdy_flag == false) {
        Serial.println
            ("\n\r\tHardware fault, or cable problem... cannot continue.");
        Serial.print("Hardware Status: ");
        prt_hwval(Ethernet.hardwareStatus());
        Serial.print("   Cable Status: ");
        prt_ethval(Ethernet.linkStatus());
        while (true) {
            delay(10);          // Halt.
        }
    } else {
        Serial.println(" OK");
    }

//    Udp.begin(localPort);//acho que precisa comentar para não dar conflito
  // configura as rotas das páginas do sistema
     set_routes();

    // Inicia Servidor
    server.begin();
}

void loop() {
        int n;
        for (n = 10; n >= 1; n--){
        Serial.print("ok ");
        delay(200);
        }
        while (1);
}
but i have this message in arduino monitor:


teste de rede

Resetting Wiz W5500 Ethernet Board... Done.
Starting ETHERNET connection...
Ethernet IP is: 192.168.0.111
Checking connection...... OK
assertion "Invalid mbox" failed: file "/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/api/tcpip.c", line 416, function: tcpip_api_call
abort() was called at PC 0x400ddb0f on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x400851f4:0x3ffb1e50 0x40085471:0x3ffb1e70 0x400ddb0f:0x3ffb1e90 0x400f390f:0x3ffb1ec0 0x400d90b4:0x3ffb1ef0 0x400d79da:0x3ffb1f40 0x400d1bad:0x3ffb1f60 0x400db5a6:0x3ffb1fb0 0x40086472:0x3ffb1fd0

Rebooting...
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4


what are i doing wrong??
Many thanks in advance!!

Who is online

Users browsing this forum: Google [Bot] and 85 guests