logo elektroda
logo elektroda
X
logo elektroda

ESP32 with ENC28J60 Ethernet Module: SPI Pin Configuration and CS Connection

madiz08 3576 13
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18296590
    madiz08
    Level 14  
    Hello
    Has any colleague perhaps managed to connect the ESP to the local network, but not over WiFi but over Ethernet? I have two enc28j60 ethernet modules. The only source I have found is the website:
    https://esp32.com/viewtopic.php?t=3994
    I downloaded the library and uploaded the code given on this page, connecting the enc28j60 module to the SPI pins (miso, mosi, sck), but unfortunately it doesn't work. I don't quite know what the CS (chip select) connector is. I tried permanently connecting this pin to ground, then to 3.3V, but that didn't do anything either.
  • ADVERTISEMENT
  • Helpful post
    #2 18296667
    khoam
    Level 42  
    Have you browsed this website: https://github.com/8-DK/EtherCard

    madiz08 wrote:
    I don't quite know what the CS (chip select) connector is.
    .
    Where to connect the CS is also described on this page.
  • #3 18297354
    madiz08
    Level 14  
    Great, it works!!! Earlier I was suggesting to connect the pins at all like in the screengrab above. Everything is working, also I am working on. Thank you

    Added after 22 [minutes]: .

    The only thing I changed was as supply voltage not 5V, but 3.3V for the module. At 5V it was getting terribly hot, at 3.3V the chip is just warm, and ethernet communication works fine
  • ADVERTISEMENT
  • Helpful post
    #4 18297521
    khoam
    Level 42  
    madiz08 wrote:
    The only thing I changed was as supply voltage not 5V, but 3.3V for the module. At 5V it got terribly hot, at 3.3V the chip is just warm and the ethernet communication works fine
    .
    Although the SPI pins on the ENC28J60 module tolerate 5V, the SPI pins on the ESP32 do not necessarily :) .
    When supplying the ENC28J60 module with 3V3 it will be OK.
  • #5 18300310
    madiz08
    Level 14  
    And I would still have a question, would it be possible to solve the EEPROM.h compilation problem?
    Code: C / C++
    Log in, to see the code
    .
    The code above is exactly what is given on the library page for the ESP32. However, if we uncomment the first line of code, thereby inserting the EEPROM.h library, compilation errors occur.
    What I mean is that through a separate application I can load the contents of IPs, subnets and others into EEPROM, then at the start of the microcontroller all these addresses are just fetched from EEPROM.
    This works for me on the UNO with the Ethernet module, on the ESP32 using WiFi, while using the enc28j60 with the ESP32, I cannot compile the project properly.
  • #6 18300316
    khoam
    Level 42  
    madiz08 wrote:
    However, if we uncomment the first line of code, thereby inserting the EEPROM.h library, compilation errors occur.
    .
    What specifically are these compilation errors?
  • #7 18300319
    madiz08
    Level 14  
    Below I send compilation errors caused by the addition of EEPROM.h
    Code: C / C++
    Log in, to see the code
  • ADVERTISEMENT
  • Helpful post
    #8 18300329
    khoam
    Level 42  
    It looks like the EEPROM.{h,cpp} files are in two places, in the libraries and the libraries of the EtherCard-master.
    You need to decide on one, and delete the other :) .
  • #9 18300336
    madiz08
    Level 14  
    Exactly right. It turns out that I had to temporarily remove Wifi.h and Wifi.cpp from the location:
  • #10 19302785
    martii
    Level 12  
    Well I also decided to play with this module and I have this symptom:

    Restarting...
    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:D IO, clock div:2
    load:0x3fff0018,len:4
    load:0x3fff001c,len:1044
    load:0x40078000,len:8896
    load:0x40080400,len:5828
    entry 0x400806ac
    Trying to get an IP...
    MAC: 74:69:69:2D:30:31
    Failed to initialise EEPROM
    Restarting...

    Code basically from the website - only thing is I'm using Visual Studio Code from PlatformIO - but the library is the same.
  • ADVERTISEMENT
  • #11 19302876
    khoam
    Level 42  
    martii wrote:
    Code basically from the site - only this I use Visual Studio Code from PlatformIO - but the library is the same.
    .
    Which code from which website? Which library?
  • #12 19303037
    martii
    Level 12  
    Exactly like this (I'm using the kind of mini-test board you promote in the posts) ESP-WROOM-32 - pins connected as in the documentation to EtherCard [github 8-DK] - all in all, I don't know if I'm not doing an uphill job because the ESP32 seems to have ethernet built in somehow?

    #include <Arduino.h>
    #include <EtherCard.h>
    #define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)

    // mac address
    static byte mymac[] = {0x74, 0x69, 0x69, 0x2D, 0x30, 0x31};
    // ethernet interface ip address
    static byte myip[] = {192, 168, 90, 200};
    // gateway ip address
    static byte gwip[] = {192, 168, 90, 1};

    // LED to control output
    int ledPin10 = 9;

    byte Ethernet::buffer[700];

    char const page[] PROGMEM =
    "HTTP/1.0 503 Service Unavailable".
    "Content-Type: text/html".
    "Retry-After: 600"
    "}"
    "<html>"
    "<head> <title>"
    "Service Temporarily Unavailable"
    "</title> </head>"
    "<body>"
    "<h3>This page is used behind the scene</h3>"
    "<p><em>"
    "Commands to control LED are transferred to Arduino.<br />"
    "The syntax: http://192.168.0.XX/?LED10=OFF or ON"
    "</em> </p>"
    "</body>"
    "</html>";

    void blinkLed()
    {
    while (true)
    {
    digitalWrite(ledPin10, HIGH);
    delay(500);
    digitalWrite(ledPin10, LOW);
    delay(500);
    }
    }

    void setup()
    {
    pinMode(ledPin10, OUTPUT);

    Serial.begin(115200);
    Serial.println("Trying to get an IP...");

    Serial.print("MAC: ");
    for (byte i = 0; i < 6; ++i)
    {
    Serial.print(mymac , HEX);
    if (i < 5)
    Serial.print(':');
    }
    Serial.println();

    if (ether.begin(sizeof Ethernet::buffer, mymac, 15) == 0)
    {
    Serial.println("Failed to access Ethernet controller;)
    }
    else
    {
    Serial.println("Ethernet controller access: OK");
    };

    #if STATIC
    Serial.println("Getting static IP.");
    if (!ether.staticSetup(myip, gwip))
    {
    Serial.println("could not get a static IP");
    blinkLed(); // blink forever to indicate a problem
    }
    #else

    Serial.println("Setting up DHCP");
    if (!ether.dhcpSetup())
    {
    Serial.println("DHCP failed");
    blinkLed(); // blink forever to indicate a problem
    }
    #endif

    ether.printIp("My IP: ", ether.myip);
    ether.printIp("Netmask: ", ether.netmask);
    ether.printIp("GW IP: ", ether.gwip);
    ether.printIp("DNS IP: ", ether.dnsip);
    }

    void loop()
    {

    word len = ether.packetReceive();
    word pos = ether.packetLoop(len);

    // IF LED10=ON turn it ON
    if (strstr((char *)Ethernet::buffer + pos, "GET /?LED10=ON") != 0)
    {
    Serial.println("Received ON command");
    digitalWrite(ledPin10, HIGH);
    }

    // IF LED10=OFF turn it OFF
    if (strstr((char *)Ethernet::buffer + pos, "GET /?LED10=OFF") != 0)
    {
    Serial.println("Received OFF command");
    digitalWrite(ledPin10, LOW);
    }

    // show some data to the user
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);
    }
    .
  • #13 19303443
    khoam
    Level 42  
    I assume you are using the EtherCard library from this page: Link .
    This library contains its own support for emulated EEPROM and is already outdated . The files in question are EtherCard/src/EEPROM.h and EtherCard/src/EEPROM.cpp .

    You should use a different, newer version of these files supplied with the Arduino Core for ESP32 ( Link ), To start, simply delete the EEPROM.h and EEPROM.h files from the EtherCard library you have installed into your project and try recompiling the program - the files from the Core should be used.

    martii wrote:
    because the ESP32 seems to have ethernet built in somehow?
    .
    It has built-in support for the Ethernet protocol (the physical interface has to be attached anyway), but there is no support for the ENC28J60 in the Core for ESP32.
  • #14 19303601
    martii
    Level 12  
    EDIT:

    Alright - I've replaced what I wrote below and all occurrences of EEPROM.eeprom_read_byte with EEPROM.readByte and now it compiles, but something is still messed up because even the uplink doesn't pick up - if I give power alone it's OK - uplink in green - if I put code in - sneezing darkness on the port.

    ----------------------------------

    I've already tried deleting these files of course - but I don't know why it doesn't download from Core and compile spitting errors :( .
    Even replacing in 3 library files #include "EEPROM.h" with #include <EEPROM.h> didn't help :( .

    lib/EtherCard-master/src/bufferfiller.cpp: In member function 'void BufferFiller::emit_p(const char*, ...)':
    lib/EtherCard-master/src/bufferfiller.cpp:62:30: error: 'class EEPROMClass' has no member named 'eeprom_read_byte'
    while ((d=EEPROM.eeprom_read_byte(*s++)) != 0)
    ^
    lib/EtherCard-master/src/stash.cpp: In static member function 'static void Stash::prepare(const char*, ...)':
    lib/EtherCard-master/src/stash.cpp:179:36: error: 'class EEPROMClass' has no member named 'eeprom_read_byte'
    while ((d = EEPROM.eeprom_read_byte(*s++)) != 0)
    ^
    lib/EtherCard-master/src/stash.cpp: In static member function 'static void Stash::extract(uint16_t, uint16_t, void*)':
    lib/EtherCard-master/src/stash.cpp:258:24: error: 'class EEPROMClass' has no member named 'eeprom_read_byte'.
    c = EEPROM.eeprom_read_byte(*ptr++);
    ^
    lib/EtherCard-master/src/enc28j60.cpp:275:13: warning: 'void xferSPI(byte)' defined but not used [-Wunused-function].
    static void xferSPI (byte data) {.
    ^

Topic summary

The discussion revolves around connecting the ESP32 microcontroller to a local network using the ENC28J60 Ethernet module via SPI. The main issue raised was the confusion regarding the Chip Select (CS) pin connection, which was resolved by referring to a GitHub resource. Users shared their experiences, noting that powering the ENC28J60 with 3.3V instead of 5V prevented overheating and allowed successful Ethernet communication. Additionally, a compilation problem related to the EEPROM library was addressed, with suggestions to remove conflicting library files to resolve multiple definition errors. The conversation highlighted the importance of using compatible libraries and proper voltage levels for successful integration.
Summary generated by the language model.
ADVERTISEMENT