ESP32 + LAN8720 need help

Hi!

Help is required to connect the LAN8720AI-CP-TR to the ESP32 . MY SCHEME
I built a scheme where LAN8720 is required, I took the Olimex ESP32-POE solution as a basis and read the information in the LAN8720 Datasheet . The final scheme is shown here. I ordered the board on jlcpcb, then I flashed it with ESPhome, but the Ethernet does not work ! :thinking: At that time WI-FI works very well. I think that I have an error in the scheme, but I do not know where. Please, help me find the mistake in the scheme. :innocent:

The ESPHome settings are as follows:

esphome:
  name: arthome_module_lan
  platform: ESP32
  board: esp-wrover-kit

ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0
  power_pin: GPIO12

  # Optional manual IP
  manual_ip:
    static_ip: 192.168.1.52
    gateway: 192.168.1.1
    subnet: 255.255.255.0

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

web_server:
  port: 80

Serial ports shows that:

Using 'COM4' as serial port.
Showing logs:
[11:46:56][W][ethernet:043]: Connecting via ethernet failed! Re-connecting...
[11:46:57][D][esp-idf:000]: E (16098) emac: Timed out waiting for PHY register 0x2 to have value 0x0007(mask 0xffff). Current value 0xffff
[11:46:57]
[11:46:58][D][esp-idf:000]: E (17099) emac: Timed out waiting for PHY register 0x3 to have value 0xc0f0(mask 0xfff0). Current value 0xffff
[11:46:58]
[11:46:58][D][esp-idf:000]: E (17101) emac: Initialise PHY device Timeout
[11:46:58]
[11:46:58][E][ethernet:127]: ETH enable error: -1
[11:46:58][E][component:092]: Component was marked as failed.
[11:47:35]

Olimex ESP32-POE
Datasheet LAN8720

Did you solve the issue @Artem_Vladimirov?
I have the same issue after flashing the board after few months

There was a hardware mistake in my scheme. I didn’t connect EP pin to ground. So maybe you have a hardware issue.

Hello,
I connected LAN8720 to the ESP32 according to this scheme


and I flashed it with ESPHome. My settings are:

esphome:
  name: lan8720
  friendly_name: lan8720

esp32:
  board: esp32dev
  framework:
    type: arduino

ethernet:
  id: eth
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 1

  manual_ip:
    static_ip: 192.168.1.200
    gateway: 192.168.1.1
    subnet: 255.255.255.0

  
# Enable logging
logger:
  level: VERBOSE

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxxxxxxxxxxxx"

ota:
  password: "xxxxxxxxxxxxxxxx"

web_server:
  port: 80  

sensor:
  - platform: uptime
    name: "LAN uptime"
    filters:
      - lambda: return x;

The green LED on the module is on, the green LED is blinking, but ESP32 does not connect to the network. Serial ports shows that:

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_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:2
load:0x3fff0030,len:1184
load:0x40078000,len:13132
load:0x40080400,len:3036
entry 0x400805e4
[     6][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
[I][logger:258]: Log initialized
[V][esp32.preferences:058]: nvs_get_blob('233825507'): ESP_ERR_NVS_NOT_FOUND - the key might not be set yet
[C][ota:469]: There have been 0 suspected unsuccessful boot attempts.
[D][esp32.preferences:113]: Saving 1 preferences to flash...
[V][esp32.preferences:162]: nvs_get_blob('233825507'): ESP_ERR_NVS_NOT_FOUND - the key might not be set yet
[V][esp32.preferences:125]: sync: key: 233825507, len: 4
[D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[I][app:029]: Running through setup()...
[V][app:030]: Sorting components by setup priority...
[C][ethernet:028]: Setting up Ethernet...
[V][ethernet:211]: [Ethernet event] ETH started (num=0)
[I][ethernet:109]: Starting ethernet connection
[V][ethernet:246]: DHCP Client Status: 0
[W][ethernet:126]: Connecting via ethernet failed! Re-connecting...
[V][ethernet:246]: DHCP Client Status: 2
[W][ethernet:126]: Connecting via ethernet failed! Re-connecting...
[V][ethernet:246]: DHCP Client Status: 2
[V][sensor:076]: 'LAN uptime': Received new state 35.799999
[D][sensor:127]: 'LAN uptime': Sending state 35.80000 s with 0 decimals of accuracy
[W][ethernet:126]: Connecting via ethernet failed! Re-connecting...
[V][ethernet:246]: DHCP Client Status: 2
[W][ethernet:126]: Connecting via ethernet failed! Re-connecting...
[V][ethernet:246]: DHCP Client Status: 2

Unfortunately, I don’t have enough knowledge, and now I have no idea what I’m doing wrong.
My LAN8720 module looks like this:


Thanks for your interest in my problem and help!

Hi, you need to modify LAN8720 module to solve problem with clock. See Ethernet on ESP32 using LAN8720. My configuration with this modification is:

ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO0_IN
  phy_addr: 1
  power_pin: GPIO17

Your ESPHome code uses clk_mode: GPIO17_OUT, but the wiring diagram wants clk_mode: GPIO0_IN.

I’ve had issues using GPIO0_IN so I switched to GPIO17_OUT by not jumping the NC pin to the oscillator and connecting IO17 to nINT/REFLCK instead of IO0. I also removed the pullup and pulldown resistors, but these might(?) still be needed.

# wiring guide
# ESP32   | NC | 22  | 19  | 21    | 26  | 25  | 27  | 17          | 23  | 18   | GND | 3V3
# LAN8720 | NC | TX1 | TX0 | TX_EN | RX1 | RX0 | CRS | nINT/REFCLK | MDC | MDIO | GND | VCC
ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 1 # 0 or 1 for LAN8720

For reference, the QuinLED-ESP32 ethernet board uses GPIO17_OUT. (I don’t know if that board includes the pullup/down resistors)

2 Likes

Hello everyone,
After several attempts and reading the diagrams of the ESP32-POE and Kincony A8 models using this LAN8720 chip I understood that they did not use an external oscillator like on our “waveshare” card. So I tried to modify this edge more simply by removing on resistor 33ohm and mouve an other. It works perfectly with GPIO0 or 17 connected on nINT/REFCLK pin !

ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT #or GPIO0_OUT, connected to nINT/REFCLK pin
  phy_addr: 1

Original ESP32-poe schematic :

Original Waveshare schematic :

After modification (disconnect onboard oscillator, use ESP32 GPIO0, 16 or 17 OUT) :

4 Likes

Very nice and documented problem solving, congrats @Alois !

hi thanks for posting such use full information, can u please share your full wiring diagram esp32 to lan8720 it will really help

Thanks alot.
please share your full shematic.

i hv tried this one it works… but it break ping after some time continuously, after every 10-20 pings 1 or 2 ping. how to solve that

@muhammadayub

I had the same problem on my Lolin32 board.

Simply solder the Enable pad of the 50MHz oscillator to the NC Pin or Ground.
Then ground NC pin, this will effectively disable the 50MHz oscillator on the LAN8720 board. Alternatively you could de-solder the oscillator all together.

I then used GPIO17_OUT and no pull up or pull down resisters.

1 Like

i am doing same but i am facing ping break issue

@muhammadayub

What board are you using?

You could also try a different power source, network cable / Switch.

hi i am using this board

@muhammadayub
I meant the microcontroller board.

But I have a different ethernet board to you.

My board is this one.
image

i hv this one tooo, i am trying to use it with di-mini, esp32 mini and esp2-wroom-32 but i dont know everytime i got ping break issue. After 10-20 pings 1 or 2 ping

I used this method and this is working fine and without any packet loss such below:

Check these steps:

1- Change the node’s IP . in dhcp server may occure ip conflict.
2- Did you add the node to Home Assistant through API? (It should connect)
3- Check your wireing and isolate it more as you can.
4- Check the resistor between GPIO17 of ESP and XTAL1/CLKIN of Lan8720, it should be 33ohm.
5- change your network cable with a shorter one.

I have modified one of the no name boards and it is working fine so far. The circuit for the oscillator is the same as in the post by [Alois].


1 Like

Hi all,
I have just order one LAN8720 Ethernet Board and trying to understand how I have to connect it to my Sparkfun ESP32 Thing board.

On the ESP32 I have GPIO12, GPIO27, GPIO26, GPIO4, GPIO17, GPIO16, GPIO05 and GPIO02 free. What I have read I shouldn’t use GPIO05 and GPIO02 on this board because they are strapping pins.

In esphome only 3 pins get defined? where do I define all the other pins? (Tx, Rx…)

Thanks!

BR