arduino-esp32 icon indicating copy to clipboard operation
arduino-esp32 copied to clipboard

ETH_W5500_IDF_SPI.ino // It can not get dhcp ip.

Open sirapol opened this issue 9 months ago • 13 comments

Board

ESP32 Dev module.

Device Description

Screenshot from 2024-05-17 10-48-25 Screenshot from 2024-05-17 10-48-54

Hardware Configuration

#define ETH_PHY_TYPE ETH_PHY_W5500 #define ETH_PHY_ADDR 1 #define ETH_PHY_CS 27 #define ETH_PHY_IRQ 35 #define ETH_PHY_RST 15

// SPI pins #define ETH_SPI_SCK 18 #define ETH_SPI_MISO 19 #define ETH_SPI_MOSI 23

Version

latest development Release Candidate (RC-X)

IDE Name

Arduino 1.8.19

Operating System

Ubuntu

Flash frequency

40Mhz

PSRAM enabled

no

Upload speed

921600

Description

I using example. It can not get dhcp ip from router. I verify same cable to pc. It can get dhcp.

How to solve it ?

Sketch

//-------------------------
// This code can interface with W5500. But, It not obtain DHCP IP
#include <ETH.h>
#include <SPI.h>

#define ETH_PHY_TYPE ETH_PHY_W5500
#define ETH_PHY_ADDR 1
#define ETH_PHY_CS 27
#define ETH_PHY_IRQ 35
#define ETH_PHY_RST 15

// SPI pins
#define ETH_SPI_SCK 18
#define ETH_SPI_MISO 19
#define ETH_SPI_MOSI 23

static bool eth_connected = false;

void onEvent(arduino_event_id_t event, arduino_event_info_t info)
{
    switch (event)
    {
    case ARDUINO_EVENT_ETH_START:
        Serial.println("ETH Started");
        // set eth hostname here
        ETH.setHostname("esp32-eth0");
        break;
    case ARDUINO_EVENT_ETH_CONNECTED:
        Serial.println("ETH Connected");
        break;
    case ARDUINO_EVENT_ETH_GOT_IP:
        Serial.printf("ETH Got IP: '%s'\n", esp_netif_get_desc(info.got_ip.esp_netif));
        Serial.println(ETH);
        eth_connected = true;
        break;
    case ARDUINO_EVENT_ETH_LOST_IP:
        Serial.println("ETH Lost IP");
        eth_connected = false;
        break;
    case ARDUINO_EVENT_ETH_DISCONNECTED:
        Serial.println("ETH Disconnected");
        eth_connected = false;
        break;
    case ARDUINO_EVENT_ETH_STOP:
        Serial.println("ETH Stopped");
        eth_connected = false;
        break;
    default:
        break;
    }
}

void testClient(const char *host, uint16_t port)
{
    Serial.print("\nconnecting to ");
    Serial.println(host);

    NetworkClient client;
    if (!client.connect(host, port))
    {
        Serial.println("connection failed");
        return;
    }
    client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
    while (client.connected() && !client.available())
        ;
    while (client.available())
    {
        Serial.write(client.read());
    }

    Serial.println("closing connection\n");
    client.stop();
}

void setup()
{
    Serial.begin(115200);
    delay(200);
    Network.onEvent(onEvent);

    SPI.begin(ETH_SPI_SCK, ETH_SPI_MISO, ETH_SPI_MOSI);
    ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, SPI);
    Serial.println("Fin Setup");
}
unsigned long tUpdate;

void loop()
{
    // if (millis() - tUpdate > 2000)
    // {
    //     tUpdate = millis();
    //     Serial.println(ETH.localIP());
    //     Serial.println(ETH);
    // }
    if (eth_connected)
    {
        testClient("google.com", 80);
    }
    delay(1000);
}

Debug Message

10:52:42.363 -> ets Jun  8 2016 00:22:57
10:52:42.363 -> 
10:52:42.363 -> rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
10:52:42.396 -> configsip: 0, SPIWP:0xee
10:52:42.396 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
10:52:42.396 -> mode:DIO, clock div:1
10:52:42.396 -> load:0x3fff0030,len:1448
10:52:42.396 -> load:0x40078000,len:14844
10:52:42.396 -> ho 0 tail 12 room 4
10:52:42.396 -> load:0x40080400,len:4
10:52:42.396 -> load:0x40080404,len:3356
10:52:42.396 -> entry 0x4008059c
10:52:42.562 -> [     2][D][esp32-hal-cpu.c:264] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
10:52:42.595 -> =========== Before Setup Start ===========
10:52:42.595 -> Chip Info:
10:52:42.595 -> ------------------------------------------
10:52:42.595 ->   Model             : ESP32
10:52:42.628 ->   Package           : D0WD-Q6
10:52:42.628 ->   Revision          : 100
10:52:42.628 ->   Cores             : 2
10:52:42.628 ->   Frequency         : 240 MHz
10:52:42.628 ->   Embedded Flash    : No
10:52:42.661 ->   Embedded PSRAM    : No
10:52:42.661 ->   2.4GHz WiFi       : Yes
10:52:42.661 ->   Classic BT        : Yes
10:52:42.661 ->   BT Low Energy     : Yes
10:52:42.661 ->   IEEE 802.15.4     : No
10:52:42.661 -> ------------------------------------------
10:52:42.661 -> INTERNAL Memory Info:
10:52:42.695 -> ------------------------------------------
10:52:42.695 ->   Total Size        :   379844 B ( 370.9 KB)
10:52:42.695 ->   Free Bytes        :   349724 B ( 341.5 KB)
10:52:42.695 ->   Allocated Bytes   :    23052 B (  22.5 KB)
10:52:42.695 ->   Minimum Free Bytes:   344204 B ( 336.1 KB)
10:52:42.728 ->   Largest Free Block:   114676 B ( 112.0 KB)
10:52:42.728 -> ------------------------------------------
10:52:42.728 -> Flash Info:
10:52:42.728 -> ------------------------------------------
10:52:42.728 ->   Chip Size         :  4194304 B (4 MB)
10:52:42.728 ->   Block Size        :    65536 B (  64.0 KB)
10:52:42.761 ->   Sector Size       :     4096 B (   4.0 KB)
10:52:42.761 ->   Page Size         :      256 B (   0.2 KB)
10:52:42.761 ->   Bus Speed         : 80 MHz
10:52:42.761 ->   Bus Mode          : QIO
10:52:42.761 -> ------------------------------------------
10:52:42.794 -> Partitions Info:
10:52:42.794 -> ------------------------------------------
10:52:42.794 ->                 nvs : addr: 0x00009000, size:    20.0 KB, type: DATA, subtype: NVS
10:52:42.794 ->             otadata : addr: 0x0000E000, size:     8.0 KB, type: DATA, subtype: OTA
10:52:42.841 ->                app0 : addr: 0x00010000, size:  1280.0 KB, type:  APP, subtype: OTA_0
10:52:42.841 ->                app1 : addr: 0x00150000, size:  1280.0 KB, type:  APP, subtype: OTA_1
10:52:42.861 ->              spiffs : addr: 0x00290000, size:  1408.0 KB, type: DATA, subtype: SPIFFS
10:52:42.861 ->            coredump : addr: 0x003F0000, size:    64.0 KB, type: DATA, subtype: COREDUMP
10:52:42.894 -> ------------------------------------------
10:52:42.894 -> Software Info:
10:52:42.894 -> ------------------------------------------
10:52:42.894 ->   Compile Date/Time : May 17 2024 10:51:26
10:52:42.894 ->   Compile Host OS   : linux
10:52:42.927 ->   ESP-IDF Version   : v5.1.4-51-g442a798083-dirty
10:52:42.927 ->   Arduino Version   : 3.0.0
10:52:42.927 -> ------------------------------------------
10:52:42.927 -> Board Info:
10:52:42.927 -> ------------------------------------------
10:52:42.927 ->   Arduino Board     : ESP32_DEV
10:52:42.960 ->   Arduino Variant   : esp32
10:52:42.960 ->   Arduino FQBN      : esp32:esp32:esp32:JTAGAdapter=default,PSRAM=disabled,PartitionScheme=default,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,LoopCore=1,EventsCore=1,DebugLevel=debug,EraseFlash=none,ZigbeeMode=default
10:52:42.960 -> ============ Before Setup End ============
10:52:43.324 -> ETH Started
10:52:43.324 -> Fin Setup
10:52:43.324 -> ETH Started
10:52:43.324 -> =========== After Setup Start ============
10:52:43.324 -> INTERNAL Memory Info:
10:52:43.324 -> ------------------------------------------
10:52:43.324 ->   Total Size        :   379844 B ( 370.9 KB)
10:52:43.324 ->   Free Bytes        :   326764 B ( 319.1 KB)
10:52:43.357 ->   Allocated Bytes   :    44548 B (  43.5 KB)
10:52:43.357 ->   Minimum Free Bytes:   321012 B ( 313.5 KB)
10:52:43.357 ->   Largest Free Block:   114676 B ( 112.0 KB)
10:52:43.357 -> ------------------------------------------
10:52:43.357 -> GPIO Info:
10:52:43.357 -> ------------------------------------------
10:52:43.357 ->   GPIO : BUS_TYPE[bus/unit][chan]
10:52:43.357 ->   --------------------------------------  
10:52:43.357 ->      1 : UART_TX[0]
10:52:43.357 ->      3 : UART_RX[0]
10:52:43.357 ->     15 : ETHERNET_SPI
10:52:43.357 ->     18 : SPI_MASTER_SCK[3]
10:52:43.357 ->     19 : SPI_MASTER_MISO[3]
10:52:43.357 ->     23 : SPI_MASTER_MOSI[3]
10:52:43.357 ->     27 : ETH_CS
10:52:43.357 ->     35 : ETHERNET_SPI
10:52:43.357 -> ============ After Setup End =============
10:52:47.296 -> ETH Connected

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.

sirapol avatar May 17 '24 03:05 sirapol