Re: w5500 and be sure module works in any time.
Posted: Fri Jun 09, 2023 4:54 pm
Was led here via an Espressif support rep, but had a lot of issues getting this to work. Even the claim of the code snippet from ESP_ondrej doesn't make sense, as that code doesn't appear anywhere in any example within any version of the IDF that I could find. But even using that code within the example he pointed out (Ethernet basic), that code snippet doesn't work. This is because W5500_REG_PHYCFGR is in a header file that's inaccessible because it's in a src directory within the IDF (4.3.2). After a ton of work, I came up with this, and it works great:
Code: Select all
esp_eth_mac_t *mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
esp_eth_phy_t *phy = esp_eth_phy_new_w5500(&phy_config);
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
esp_eth_handle_t eth_handle = NULL;
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
//check PHY register to see if the w5500 exists on SPI bus
uint32_t regPosition = 0x002E << 16 | 0x00 << 3;
esp_eth_mediator_t *ethMediator = (esp_eth_mediator_t *)eth_handle;
uint8_t val = 0;
ethMediator->phy_reg_read(ethMediator, 0, regPosition, (uint32_t *)(&val));
ESP_LOGI(TAG, "W5500_REG_PHYCFGR val = 0x%x, i=%i", val, val);
if (val == 0xff)
{
//w5500 ethernet does not exist/respond
}