Issue: Unable to Get MAC Address in ESP32+W5500 Ethernet Code

Pratik_dongale
Posts: 1
Joined: Thu Mar 27, 2025 11:33 am

Issue: Unable to Get MAC Address in ESP32+W5500 Ethernet Code

Postby Pratik_dongale » Thu Mar 27, 2025 11:52 am

void ethernet_init(void)
{
ESP_ERROR_CHECK(esp_event_loop_create_default());
ESP_ERROR_CHECK(esp_netif_init());

// Create Ethernet interface
esp_netif_config_t netif_config = ESP_NETIF_DEFAULT_ETH();
esp_netif_t *eth_netif = esp_netif_new(&netif_config);

esp_eth_handle_t *eth_handle = NULL;
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default common MAC configuration


eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY configuration
phy_config.reset_gpio_num = RSTn;

// Install GPIO interrupt service (as the SPI-Ethernet module is interrupt-driven)
gpio_set_direction(INTn, GPIO_MODE_INPUT);
gpio_set_intr_type(INTn, GPIO_INTR_POSEDGE);
gpio_install_isr_service(0);

spi_bus_config_t buscfg = {
.miso_io_num = MISO_ETH,
.mosi_io_num = MOSI_ETH,
.sclk_io_num = SCLK_ETH,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 4096, // Important for safe transactions
};
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO ));

// SPI Configuration
static spi_device_interface_config_t spi_devcfg = {
.command_bits = 0,
.address_bits = 0,
.dummy_bits = 0,
.mode = 0, // SPI mode 0
.clock_speed_hz = 40 * 1000 * 1000, // 8MHz
.spics_io_num = CS, // Chip select pin
.queue_size = 20
};

//eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(SPI3_HOST,&spi_devcfg);
static eth_w5500_config_t w5500_config=
{
.int_gpio_num = GPIO_NUM_10,
.poll_period_ms = 0,
.spi_host_id = SPI3_HOST,
.spi_devcfg = &spi_devcfg,
.custom_spi_driver = ETH_DEFAULT_SPI,
};

// Create MAC and PHY instances
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);


// Ethernet driver configuration
esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy);
esp_err_t ret = esp_eth_driver_install(&eth_config, &eth_handle);
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "Failed to install Ethernet driver: %s", esp_err_to_name(ret));
return;
}
// Enable DHCP on the Ethernet interface
esp_netif_dhcpc_start(eth_netif);

// Attach Ethernet interface
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));

// register Ethernet event handler (to deal with user-specific stuff when events like link up/down happened)
esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &eth_event_handler, NULL);
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));
ESP_LOGI(TAG, "IP event handler registered successfully!");

// Start Ethernet
ESP_ERROR_CHECK(esp_eth_start(eth_handle));

ESP_LOGI(TAG, "Ethernet initialized successfully");
}

In the code below, I am not getting the correct MAC address. The output log is as follows:

I (342) main_task: Calling app_main()
I (372) esp_eth.netif.netif_glue: 00:00:00:00:00:00
I (372) esp_eth.netif.netif_glue: ethernet attached to netif
I (372) eth_example: IP event handler registered successfully!
I (382) eth_example: Ethernet initialized successfully
I (382) eth_example: Ethernet Started
I (2382) eth_example: Ethernet Connected
I (2382) eth_example: Ethernet HW Addr 00:00:00:00:00:00

ondrej
Espressif staff
Espressif staff
Posts: 227
Joined: Fri May 07, 2021 10:35 am

Re: Issue: Unable to Get MAC Address in ESP32+W5500 Ethernet Code

Postby ondrej » Wed Apr 09, 2025 5:39 am


Who is online

Users browsing this forum: No registered users and 8 guests