DHCP not working on ESP32 with Ethernet module ENC28J60

My setup is : ESP32 with ENC28J60 ,Arduino IDE 2.3.2 ,EthernetENC library.
The issue I am facing is that in the setup code,it never returns from Ethernet.begin(). I am expecting to see "DCHP OK" (BTW static IP works)
This is the relevant part

/*
 Web client with enc28j60 and EthernetENC
 
 This sketch connects to a test website (httpbin.org)
 and try to do a GET request, the output is printed
 on Serial
 
 by Renzo Mischianti <www.mischianti.org>
 
 https://www.mischianti.org
 
 */
 
#include "SPI.h"
#include "EthernetENC.h"
 
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
//char server[] = "www.google.com";    // name address for Google (using DNS)
char server[] = "httpbin.org";    // name address for Google (using DNS)
 
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

 
// Set the static IP address to use if the DHCP fails to assign
#define MYIPADDR 192,168,1,28
#define MYIPMASK 255,255,255,0
#define MYDNS 192,168,1,1
#define MYGW 192,168,1,1

 
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
 
// Variables to measure the speed
unsigned long beginMicros, endMicros;
unsigned long byteCount = 0;
bool printWebData = true;  // set to false for better speed measurement




 
void setup() {
    
    Serial.begin(115200);
    delay(5000);
    Serial.println("Begin Ethernet");
 
    // You can use Ethernet.init(pin) to configure the CS pin
    
    Ethernet.init(5);   // MKR ETH Shield

   
    if (Ethernet.begin(mac))
    { // Dynamic IP setup
        Serial.println("DHCP OK!");
    }
    else
    {
        Serial.println("Failed to configure Ethernet using DHCP");
        // Check for Ethernet hardware present
        if (Ethernet.hardwareStatus() == EthernetNoHardware) {
          Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
          while (true) {
            delay(1); // do nothing, no point running without Ethernet hardware
          }
        }
        if (Ethernet.linkStatus() == LinkOFF) {
          Serial.println("Ethernet cable is not connected.");
        }
 
          IPAddress ip(MYIPADDR);
          IPAddress dns(MYDNS);
          IPAddress gw(MYGW);
          IPAddress sn(MYIPMASK);
          Ethernet.begin(mac, ip, dns, gw, sn);
          Serial.println("STATIC OK!");
    }
    delay(5000);
 

And this is what I see

13:13:52.184 -> Begin Ethernet

13:13:52.328 -> udp beginPacket, rip: 255.255.255.255, port: 67

13:13:52.329 -> udp, uip_poll preparing packet to send: 1, size: 325

13:13:52.329 -> Enc28J60Network_send uip_packet: 1, hdrlen: 42

13:13:52.329 -> sendPacket(1) [801-93E]: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 80 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Searching found a issue on DHCP and broadcast that suggest a fix. Tried but same result.
Not receiving DHCP Offer Packet · Issue #9 · Networking-for-Arduino/EthernetENC · GitHub
Any idea what is wrong here?

Hi @zenonmb ,

Welcome to the forum..

The dead beef feed mac is used allot..
Is it possible this is a dup mac on your net??
Try changing the mac address..

good luck.. ~q

the EthernetENC sets broadcast filtering so if the DHCP response can't arrive as unicast, then it will not work.

with ESP32 platform version 3 you can now use my new EthermetESP32 library

#include <EthernetESP32.h>

ENC28J60Driver driver;

void setup() {

  Ethernet.init(driver);

  Ethernet.begin(); // begin with default MAC address and DHCP IP

Thanks Q.
I do not think the issue is with the mac. My network is just a wireless router. There is nothing at this time.

Juraj,

Can not find this library. Tried through arduino and then searched in the web.
Can you point where to download it?

image

It looks like we have different versions of ArduinoIDE...

looks like you don't have the latest library manager index

image

Yes, you were right . UPdated and installed and now I am getting this

15:36:52.061 -> Begin Ethernet

15:36:52.061 -> E (5146) enc28j60: enc28j60_verify_id(566): wrong chip ID

15:36:52.061 -> E (5146) enc28j60: emac_enc28j60_init(1062): vefiry chip ID failed

15:36:52.061 -> E (5146) esp_eth: esp_eth_driver_install(228): init mac failed

15:36:52.061 -> Failed to configure Ethernet using DHCP

15:36:52.061 -> Ethernet shield was not found. Sorry, can't run without hardware. :frowning:

Reviewed the pin configuration and I have the default. MOSI 23, MISO 19, SCK 18 and CS 5.

Any idea what might be wrong now? BTW I did not have msg before.

It looks like you check for version of the chip ENC28J60 .

/**
 * @brief Verify chip revision ID
 */
static esp_err_t enc28j60_verify_id(emac_enc28j60_t *emac)
{
    esp_err_t ret = ESP_OK;
    MAC_CHECK(enc28j60_register_read(emac, ENC28J60_EREVID, (uint8_t *)&emac->revision) == ESP_OK,
              "read EREVID failed", out, ESP_FAIL);
    ESP_LOGI(TAG, "revision: %d", emac->revision);
    MAC_CHECK(emac->revision >= ENC28J60_REV_B1 && emac->revision <= ENC28J60_REV_B7, "wrong chip ID", out, ESP_ERR_INVALID_VERSION);
out:
    return ret;
}

Where I can see the version?

all currently existing revisions are supported.
do you power it with 3.3 V or 5 V? this one should be powered with 3.3 V.
I always use modules powered with 5 V and on-board 5 V to 3.3 V conversion.

I am powering with 3.3 from the esp32 module. I am meassuring the current and it says 230 ma (both modules)

is your esp32 a classic esp32 or some of C or S series?

Can you tell from the picture?

This is from the compilation

esptool.py v4.6
Serial port COM3
Connecting....
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
WARNING: Detected crystal freq 41.01MHz is quite different to normalized freq 40MHz. Unsupported crystal in use?
Crystal is 40MHz
MAC: ec:62:60:93:ac:a4
Uploading stub...
Running stub...
Stub running...
Configuring flash size...

it is WROOM a classic esp32 module.
try lower CPU frequency 80 MHz

No change.

check the wiring again. you could try EthernetENC with a static IP but I guess you have some hardware/wiring problem

Went back to static IP (using EhternetENC library) , but this time when I added the hardware check lines ,got he same hardware message ....... I had omited those lines when tested static IP..........( intersting though that ethernet.begin did not complain).....So the module was not working with dynamic and static, regardless of library.
Replaced the ESP and with your library is working perfect. Thank you for all your support!!!!!

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