ESP32-EVB relais ethernet hiccups

Started by ech0, August 16, 2021, 10:21:00 PM

Previous topic - Next topic

ech0

Hi everyone,

I've been experiencing network issues with my EVB boards when triggering the relais. Sometimes (although not deterministically), the network interface looses its connection.

When artifically provoking the issue, I can observe the following error via the Serial interface:
E (1013) emac: Timed out waiting for PHY register 0x2 to have value 0x0007(mask 0xffff). Current value 0xffff
E (2014) emac: Timed out waiting for PHY register 0x3 to have value 0xc0f0(mask 0xfff0). Current value 0xffff
E (2015) emac: Initialise PHY device Timeout
[E][ETH.cpp:105] begin(): esp_eth_enable error: -1

I've read through multiple posts here and on GitHub that feature the same error, but none of the proposed solutions work for me. I can also rule out the hardware revision of the board, as I've tested revisions G, H, and I.

Most recently I tried to create a minimal working example to showcase the issue. I started with the example code provided in https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/ETH_LAN8720/ETH_LAN8720.ino and modified it to call the ESP.restart() function after the delay in the loop function. This code works without any issues. However, triggering one of the relais in the loop is enough to eventually produce the error shown above.

void setup()
{
  pinMode(32, OUTPUT);
  Serial.begin(115200);
  WiFi.onEvent(WiFiEvent);
  ETH.begin();
}


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

  digitalWrite(32, HIGH);
  delay(1000);
  digitalWrite(32, LOW);

  ESP.restart();
}

Any help would be greatly appreciated! :)

LubOlimex

Why exactly do you need ESP.restart(); ?
Technical support and documentation manager at Olimex

ech0

I've added the ESP.restart() to artificially provoke the described issue. Even with out the restart, the board will eventually loose network connectivity and the software restart performed by ESP.restart() is not enough to reset the fault, requiring a hardware reset by power cycling the board or pulling the ESP's enable pin to GND.

Without the artificial restart, the issue usually surfaces after a few days or a few activations of the relay. For a while we actually hooked one of the board's power supply up to a timer switch, to restart it a few times a day, which worked quite well, but inevitably leads to availability issues, which is not so desirable.

LubOlimex

I think there are two issues. One is that the board hangs from the relay switching and the second is that the Ethernet doesn't start after software reset. These two issues might be interconnected - e.g. the relay issue causes reset of the board it and the Ethernet doesn't start of the reset. So the main goal would be to stop the relay from hanging the board. About the relay causing hangs - might be some typical electro-mechanical relay issue, there are couple of things you might do check this thread and the links in my post:

https://www.olimex.com/forum/index.php?topic=7695.msg28853#msg28853
Technical support and documentation manager at Olimex

SejnyM

LAN87xx Phy must be propertly clocked/initialised. See some investigation here: https://github.com/espressif/esp-idf/issues/6821

I believe problem afer ESP.restart(); is caused by improper PHY initialisation.

My recomendation for olimex: remove PHY power switch and route PHY PWR signal to PHY Nrst pin as here: https://drive.google.com/file/d/14sBLe0T18CDpCG41r_yOZWLeWLBQvtnW/view?usp=sharing

This is necessary for correct PHY initialisation at any time.


LubOlimex

We've done this in other designs like ESP32-GATEWAY, ESP32-POE, ESP32-POE-ISO, etc.

However, it is impossible to do in ESP32-EVB design since it requires a free GPIO pin. We have no free pins in ESP32-EVB, we would need to drop a relay for example to make that work.
Technical support and documentation manager at Olimex

ech0

#6
Sorry for the delayed response. I also suspected the inductive load at the relay to be an issue and hence added a snubber circuit to the load, which didn't improve the issue. This was the main reason for writing my original post. I suspected the issue to be related to the EVB board's design as I did not notice such issues with other boards and external relays. Which the two of you now confirmed :)

However, after going through the resources you linked and some additional research on how to properly design an RC snubber circuit, I discovered a rookie mistake on my side. I added the capacitor/resistor in series to the load and the relay and not in parallel to the relay. I think I've read somewhere that both variants should work, but my theoretical education in electrical engineering is very basic and was too long ago to really understand the physics. With the snubber circuit wired up correctly, I was unable to reproduce the issue.

Thank you very much for your help and also the clarification on the board's design! :)