Branchement LAN8720 sur ESP32 devkit v1

Bonjour à tous,

je suis en train de faire un montage avec un LAN8720 et un module ESP32 devkit v1.
ESP32 :

Tableau branchement LAN8720 :

GPIO17 - PHY_POWER   : NC - Osc. Enable - 4k7 Pulldown
GPIO22 - EMAC_TXD1   : TX1
GPIO19 - EMAC_TXD0   : TX0
GPIO21 - EMAC_TX_EN  : TX_EN
GPIO26 - EMAC_RXD1   : RX1
GPIO25 - EMAC_RXD0   : RX0
GPIO27 - EMAC_RX_DV  : CRS
GPIO00 - EMAC_TX_CLK : nINT/REFCLK (50MHz) - 4k7 Pullup
GPIO23 - SMI_MDC     : MDC
GPIO18 - SMI_MDIO    : MDIO
GND        : GND
3V3          : VCC

Seulement au moment du branchement, je m'aperçois que sur ma carte il n'y a pas de pin GPIO0.

Par quoi pourrais je le remplacer et comment ?
Est ce que je peux utiliser le GPIO16, car en lisant certaines doc j'ai lu ceci :

"REF_CLK ne peut être sélectionné que parmi GPIO0, GPIO16 ou GPIO17"

Mais va t-il le reconnaitre tout seul ou il va falloir le paramétrer ?

Salut.
La broche GPIO0 existe sur le module ESP32. Elle est reliée au bouton BOOT.

Merci @hbachetti,

C'est bien ce qu'il me semblait.
Mais pour le LAN8720, apparemment je dois me connecter au GPIO0 si ma doc est correct.
Donc est ce que je peux le remplacer par le GPIO16 ?
Et est ce que je suis obligé de faire une configuration spécifique dans mon programme ?

Je crains de ne pouvoir aider sur ce sujet.
Je connais le W5100, qui intègre une stack TCP/IP complète, pas le LAN8720, beaucoup plus bas niveau.

Ok Merci @hbachetti ,

Oui mais j'ai acheté un jour ce module et donc il va bien falloir que je l'utilise un jour.
C'est ça quand on achète sans de réelle compétence !!! :sweat_smile:

Mais apparemment j'ai trouvé quelque chose qui confirme que l'on peut utiliser le GPIO16.

Mes premier essais sont non concluant, j'utilise le programme ci dessous :

/*
    This sketch shows how to configure different external or internal clock sources for the Ethernet PHY
*/

#include <ETH.h>

/* 
   * ETH_CLOCK_GPIO0_IN   - default: external clock from crystal oscillator
   * ETH_CLOCK_GPIO0_OUT  - 50MHz clock from internal APLL output on GPIO0 - possibly an inverter is needed for LAN8720
   * ETH_CLOCK_GPIO16_OUT - 50MHz clock from internal APLL output on GPIO16 - possibly an inverter is needed for LAN8720
   * ETH_CLOCK_GPIO17_OUT - 50MHz clock from internal APLL inverted output on GPIO17 - tested with LAN8720
*/
#define ETH_CLK_MODE    ETH_CLOCK_GPIO16_OUT

// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source)
#define ETH_POWER_PIN   -1

// Type of the Ethernet PHY (LAN8720 or TLK110)
#define ETH_TYPE        ETH_PHY_LAN8720

// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)
#define ETH_ADDR        1

// Pin# of the I²C clock signal for the Ethernet PHY
#define ETH_MDC_PIN     23

// Pin# of the I²C IO signal for the Ethernet PHY
#define ETH_MDIO_PIN    18


static bool eth_connected = false;

void WiFiEvent(WiFiEvent_t event) {
  switch (event) {
    case SYSTEM_EVENT_ETH_START:
      Serial.println("ETH Started");
      //set eth hostname here
      ETH.setHostname("esp32-ethernet");
      break;
    case SYSTEM_EVENT_ETH_CONNECTED:
      Serial.println("ETH Connected");
      break;
    case SYSTEM_EVENT_ETH_GOT_IP:
      Serial.print("ETH MAC: ");
      Serial.print(ETH.macAddress());
      Serial.print(", IPv4: ");
      Serial.print(ETH.localIP());
      if (ETH.fullDuplex()) {
        Serial.print(", FULL_DUPLEX");
      }
      Serial.print(", ");
      Serial.print(ETH.linkSpeed());
      Serial.println("Mbps");
      eth_connected = true;
      break;
    case SYSTEM_EVENT_ETH_DISCONNECTED:
      Serial.println("ETH Disconnected");
      eth_connected = false;
      break;
    case SYSTEM_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);

  WiFiClient 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);
  WiFi.onEvent(WiFiEvent);
  ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE);
}


void loop() {
  if (eth_connected) {
    testClient("google.com", 80);
  }
  delay(10000);
}

Mais j'ai ces erreurs là

G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino:33:6: error: variable or field 'WiFiEvent' declared void
   33 | void WiFiEvent(WiFiEvent_t event) {
      |      ^~~~~~~~~
G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino:33:16: error: 'WiFiEvent_t' was not declared in this scope; did you mean 'wifi_event_t'?
   33 | void WiFiEvent(WiFiEvent_t event) {
      |                ^~~~~~~~~~~
      |                wifi_event_t
G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino:33:6: error: variable or field 'WiFiEvent' declared void
   33 | void WiFiEvent(WiFiEvent_t event) {
      |      ^~~~~~~~~
G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino:33:16: error: 'WiFiEvent_t' was not declared in this scope; did you mean 'wifi_event_t'?
   33 | void WiFiEvent(WiFiEvent_t event) {
      |                ^~~~~~~~~~~
      |                wifi_event_t
G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino: In function 'void testClient(const char*, uint16_t)':
G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino:73:3: error: 'WiFiClient' was not declared in this scope
   73 |   WiFiClient client;
      |   ^~~~~~~~~~
G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino:74:8: error: 'client' was not declared in this scope; did you mean 'Client'?
   74 |   if (!client.connect(host, port)) {
      |        ^~~~~~
      |        Client
G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino:78:3: error: 'client' was not declared in this scope; did you mean 'Client'?
   78 |   client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
      |   ^~~~~~
      |   Client
G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino: In function 'void setup()':
G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino:90:3: error: 'WiFi' was not declared in this scope
   90 |   WiFi.onEvent(WiFiEvent);
      |   ^~~~
G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino:90:16: error: 'WiFiEvent' was not declared in this scope
   90 |   WiFi.onEvent(WiFiEvent);
      |                ^~~~~~~~~
G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino:22:25: error: invalid conversion from 'int' to 'eth_phy_type_t' [-fpermissive]
   22 | #define ETH_ADDR        1
      |                         ^
      |                         |
      |                         int
G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino:91:13: note: in expansion of macro 'ETH_ADDR'
   91 |   ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE);
      |             ^~~~~~~~
In file included from G:\System\Arduino\ESP32\ESP32_LAN8720_b\ESP32_LAN8720_b.ino:5:
C:\Users\treza\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.0-rc1\libraries\Ethernet\src/ETH.h:115:35: note:   initializing argument 1 of 'bool ETHClass::begin(eth_phy_type_t, int32_t, int, int, int, eth_clock_mode_t)'
  115 |         bool begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clk_mode);
      |                    ~~~~~~~~~~~~~~~^~~~

exit status 1

Compilation error: variable or field 'WiFiEvent' declared void

Comme si il manquait la librairie "Wifi.h", mais dans tous les programme que je vois cette librairie n'apparait pas.
Une idée du problème ?

Quelqu'un a t il déjà utilisé le module LAN8720, car j’essaie d'utiliser la librairie Ethernet ou WebServer_WT32_ETH01.
J’essaie avec les exemples, mais rien ne fonctionne, je n'arrive même pas à avoir une compile correct.

Avez vous une idée de quelle librairies installer pour utiliser "ETH.h".

Car j'ai l'impression qu'il y en a plusieurs et donc c'est peut être là ou est mon problème.

Je pourrais ne pas utiliser la bonne librairie ?

une bibliothèque Ethernet est installée d'office avec le 'core ESP32'
Je viens de lancer (sans ajout) par curiosité la compilation de l'exemple ETH_LAN8720.ino fourni avec le core ESP32

Compilation OK.......rien à installer , tout est là à disposition :wink:
image
A l'interieur les fichiers ETH.cpp et ETH.h + 2 exemples

Merci @al1fch pour ton essai.

En fait c'est plus clair j'ai désinstaller et reinstaller l'ide avec ces librairies, et j'ai un peut de mieux.

Le programme :

/*
 This sketch shows how to use lan8720 with esp32 with minimal/standard configuration
 
 You can set the parameter in begin function or at start with define before the import
 of ETH.h file, this way is preferible.
 
 by Renzo Mischianti <mischianti.org>
 */
 
// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)
#define ETH_PHY_ADDR 1                      // DEFAULT VALUE IS 0 YOU CAN OMIT IT
// Type of the Ethernet PHY (LAN8720 or TLK110)
#define ETH_PHY_TYPE ETH_PHY_LAN8720        // DEFAULT VALUE YOU CAN OMIT IT
// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source)
#define ETH_PHY_POWER -1                    // DEFAULT VALUE YOU CAN OMIT IT
// Pin# of the I²C clock signal for the Ethernet PHY
#define ETH_PHY_MDC 23                      // DEFAULT VALUE YOU CAN OMIT IT
// Pin# of the I²C IO signal for the Ethernet PHY
#define ETH_PHY_MDIO 18                     // DEFAULT VALUE YOU CAN OMIT IT
// External clock from crystal oscillator
#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT     // DEFAULT VALUE YOU CAN OMIT IT
 
#include <ETH.h>
 
static bool eth_connected = false;
 
void WiFiEvent(WiFiEvent_t event) {
  Serial.println(event);
    switch (event) {
    case ARDUINO_EVENT_ETH_START:
        Serial.println("ETH Started");
        ETH.setHostname("esp32-mischianti-eth");
        break;
    case ARDUINO_EVENT_ETH_CONNECTED:
        Serial.println("ETH Connected");
        break;
    case ARDUINO_EVENT_ETH_GOT_IP:
        Serial.print("ETH MAC: ");
        Serial.print(ETH.macAddress());
        Serial.print(", IPv4: ");
        Serial.print(ETH.localIP());
        if (ETH.fullDuplex()) {
            Serial.print(", FULL_DUPLEX");
        }
        Serial.print(", ");
        Serial.print(ETH.linkSpeed());
        Serial.println("Mbps");
        eth_connected = true;
        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);
 
    WiFiClient 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);
    WiFi.onEvent(WiFiEvent);
    ETH.begin();
}
 
void loop() {
    if (eth_connected) {
        testClient("mischianti.org", 80);
    }
    delay(10000);
 
}

Par contre j'ai un probleme réseau, le module LAN8720 démarre et voit si le cable ethernet est branché.
Mais il ne se connecte pas au réseau, il ne m'affiche ni l'adresse mac du module, ni ip locale.

Voici le retour console :

17:47:47.931 -> ETH Connected
17:52:12.969 -> ets Jun 8 2016 00:22:57
17:52:12.969 ->
17:52:12.969 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
17:52:12.969 -> configsip: 0, SPIWP:0xee
17:52:12.969 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
17:52:12.969 -> mode:DIO, clock div:1
17:52:12.969 -> load:0x3fff0030,len:1344
17:52:12.969 -> load:0x40078000,len:13964
17:52:12.969 -> load:0x40080400,len:3600
17:52:12.969 -> entry 0x400805f0
17:52:14.731 -> 18
17:52:14.765 -> ETH Started
17:52:14.765 -> 20
17:52:14.765 -> ETH Connected

Pour pouvoir utiliser le GPIO17 et non le GPIO0, j'ai relier la broche enable /disable de l'oscilateur à la masse, comme on peut le voir dans certains tuto, pour désactiver oscillateur du LAN8720.

Encore une fois je reviens vers vous pour savoir ce qui peut clocher

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