enc28j60 + esp32 Not getting IP
Posted: Thu Apr 08, 2021 5:38 am
Hello everyone,
I've been trying to connect an enc28j60 ethernet module with esp32, I am using the sample example code from esp-idf.
I am getting "ethernet link is up" but not able to get IP.
As per README from this example: Quote: "ENC28J60 hasn't burned any valid MAC address in the chip, you need to write an unique MAC address into its internal MAC address register before any traffic happened on TX and RX line."
So as per this I'm entering unique MAC ID but still not getting IP.
Attaching code:
xTaskHandle xEciethernetTaskHandle = NULL;
uint8_t mac_addr[6] = {0x9C, 0x47, 0x83, 0xC1, 0xA7, 0xB5}; // MAC address can't be zero
uint8_t mac_addr_set[6] = {0x02, 0x00, 0x00, 0x12, 0x34, 0x56};
/** Event handler for Ethernet events */
static void eth_event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
//uint8_t mac_addr[6] = {0};
/* we can get the ethernet driver handle from event data */
esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;
switch (event_id) {
case ETHERNET_EVENT_CONNECTED:
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
ESP_LOGI(TAG, "Ethernet Link Up");
ESP_LOGI(TAG, "Ethernet HW Addr %02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
break;
case ETHERNET_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "Ethernet Link Down");
break;
case ETHERNET_EVENT_START:
ESP_LOGI(TAG, "Ethernet Started");
break;
case ETHERNET_EVENT_STOP:
ESP_LOGI(TAG, "Ethernet Stopped");
break;
default:
break;
}
}
/** Event handler for IP_EVENT_ETH_GOT_IP */
static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
const esp_netif_ip_info_t *ip_info = &event->ip_info;
ESP_LOGI(TAG, "Ethernet Got IP Address");
ESP_LOGI(TAG, "~~~~~~~~~~~");
ESP_LOGI(TAG, "ETHIP:" IPSTR, IP2STR(&ip_info->ip));
ESP_LOGI(TAG, "ETHMASK:" IPSTR, IP2STR(&ip_info->netmask));
ESP_LOGI(TAG, "ETHGW:" IPSTR, IP2STR(&ip_info->gw));
ESP_LOGI(TAG, "~~~~~~~~~~~");
}
Attaching the logs from the,
13:51:37.290 -> [0;32mI (50) enc28j60: revision: 6 [0m
13:51:37.290 -> [0;32mI (60) esp_eth.netif.glue: 02:00:00:12:34:56 [0m
13:51:37.290 -> [0;32mI (60) esp_eth.netif.glue: ethernet attached to netif [0m
13:51:37.290 -> [0;32mI (639) eth_example: Ethernet Started [0m
13:51:37.430 -> Failed to set AO, expect problems
13:51:37.663 -> Error reading API packet. Error code: 0x3
13:51:37.757 -> Error reading API packet. Error code: 0x1 (This is expected)
13:51:39.293 -> [0;32mI (2639) enc28j60: working in 10Mbps [0m
13:51:39.293 -> [0;32mI (2639) enc28j60: working in half duplex [0m
13:51:39.293 -> [0;32mI (2639) eth_example: Ethernet Link Up [0m
13:51:39.293 -> [0;32mI (2639) eth_example: Ethernet HW Addr 02:00:00:12:34:56 [0m
It would be really appreciable if anyone share sample code or at least an idea.
Thank you for your time..
I've been trying to connect an enc28j60 ethernet module with esp32, I am using the sample example code from esp-idf.
I am getting "ethernet link is up" but not able to get IP.
As per README from this example: Quote: "ENC28J60 hasn't burned any valid MAC address in the chip, you need to write an unique MAC address into its internal MAC address register before any traffic happened on TX and RX line."
So as per this I'm entering unique MAC ID but still not getting IP.
Attaching code:
xTaskHandle xEciethernetTaskHandle = NULL;
uint8_t mac_addr[6] = {0x9C, 0x47, 0x83, 0xC1, 0xA7, 0xB5}; // MAC address can't be zero
uint8_t mac_addr_set[6] = {0x02, 0x00, 0x00, 0x12, 0x34, 0x56};
/** Event handler for Ethernet events */
static void eth_event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
//uint8_t mac_addr[6] = {0};
/* we can get the ethernet driver handle from event data */
esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;
switch (event_id) {
case ETHERNET_EVENT_CONNECTED:
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
ESP_LOGI(TAG, "Ethernet Link Up");
ESP_LOGI(TAG, "Ethernet HW Addr %02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
break;
case ETHERNET_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "Ethernet Link Down");
break;
case ETHERNET_EVENT_START:
ESP_LOGI(TAG, "Ethernet Started");
break;
case ETHERNET_EVENT_STOP:
ESP_LOGI(TAG, "Ethernet Stopped");
break;
default:
break;
}
}
/** Event handler for IP_EVENT_ETH_GOT_IP */
static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
const esp_netif_ip_info_t *ip_info = &event->ip_info;
ESP_LOGI(TAG, "Ethernet Got IP Address");
ESP_LOGI(TAG, "~~~~~~~~~~~");
ESP_LOGI(TAG, "ETHIP:" IPSTR, IP2STR(&ip_info->ip));
ESP_LOGI(TAG, "ETHMASK:" IPSTR, IP2STR(&ip_info->netmask));
ESP_LOGI(TAG, "ETHGW:" IPSTR, IP2STR(&ip_info->gw));
ESP_LOGI(TAG, "~~~~~~~~~~~");
}
Attaching the logs from the,
13:51:37.290 -> [0;32mI (50) enc28j60: revision: 6 [0m
13:51:37.290 -> [0;32mI (60) esp_eth.netif.glue: 02:00:00:12:34:56 [0m
13:51:37.290 -> [0;32mI (60) esp_eth.netif.glue: ethernet attached to netif [0m
13:51:37.290 -> [0;32mI (639) eth_example: Ethernet Started [0m
13:51:37.430 -> Failed to set AO, expect problems
13:51:37.663 -> Error reading API packet. Error code: 0x3
13:51:37.757 -> Error reading API packet. Error code: 0x1 (This is expected)
13:51:39.293 -> [0;32mI (2639) enc28j60: working in 10Mbps [0m
13:51:39.293 -> [0;32mI (2639) enc28j60: working in half duplex [0m
13:51:39.293 -> [0;32mI (2639) eth_example: Ethernet Link Up [0m
13:51:39.293 -> [0;32mI (2639) eth_example: Ethernet HW Addr 02:00:00:12:34:56 [0m
It would be really appreciable if anyone share sample code or at least an idea.
Thank you for your time..