Ethernet 10BaseT/100BaseTX
Description
Ethernet functionality is available on the OI-Core module, featuring an embedded Wiznet W5500 chip. This allows for communication over any Ethernet network.
Communication between the micro-controller unit (MCU) and the Ethernet chip is facilitated through an SPI link. Example code for this setup is provided.
The W5500 chip serves as a Hardwired TCP/IP embedded Ethernet controller, simplifying Internet connectivity for embedded systems. It integrates a TCP/IP stack, 10/100 Ethernet MAC, and PHY.
Features of the W5500 chip include:
Support for Hardwired TCP/IP Protocols: TCP, UDP, ICMP, IPv4, ARP, IGMP, PPPoE
Simultaneous support for 8 independent sockets
Power-down mode and Wake on LAN over UDP functionality
Embedded 10BaseT/100BaseTX Ethernet PHY
Auto Negotiation support for full/half duplex and 10/100-based operation
Note
On OI-Core, ethernet does not support auto-MDIX feature. Thus, user should use straight-through cables to connect to other switches or routers and crossover cables to connect to devices such as servers, workstations or another W5500. However, user can use either type of cable to connect to other devices with auto-MDIX enabled, and the interface automatically corrects for any incorrect cabling.
Code examples
The example code below demonstrates how to initialize the Ethernet interface using the W5500 chip and establish a connection. It also includes a simple web server that responds to HTTP requests.
/**
* @file Ethernet.cpp
* @brief Ethernet example
* @author Kevin Lefeuvre (kevin.lefeuvre@openindus.com)
* @copyright (c) [2025] OpenIndus, Inc. All rights reserved.
* @see https://openindus.com
*/
#include "OpenIndus.h"
#include <Arduino.h>
#include <ETH.h>
#include <SPI.h>
#define ETH_PHY_TYPE ETH_PHY_W5500
#define ETH_PHY_ADDR 1
#define ETH_PHY_CS 18
#define ETH_PHY_IRQ -1
#define ETH_PHY_RST -1
// SPI pins
#define ETH_SPI_SCK 17
#define ETH_SPI_MISO 16
#define ETH_SPI_MOSI 15
static bool eth_connected = false;
void onEvent(arduino_event_id_t event, arduino_event_info_t info)
{
switch (event) {
case ARDUINO_EVENT_ETH_START:
Serial.println("ETH Started");
// set eth hostname here
ETH.setHostname("esp32-eth0");
break;
case ARDUINO_EVENT_ETH_CONNECTED:
Serial.println("ETH Connected");
break;
case ARDUINO_EVENT_ETH_GOT_IP:
Serial.printf("ETH Got IP: '%s'\n", esp_netif_get_desc(info.got_ip.esp_netif));
Serial.println(ETH);
eth_connected = true;
break;
case ARDUINO_EVENT_ETH_LOST_IP:
Serial.println("ETH Lost IP");
eth_connected = false;
break;
case ARDUINO_EVENT_ETH_DISCONNECTED:
Serial.println("ETH Disconnected");
eth_connected = false;
break;
case ARDUINO_EVENT_ETH_STOP:
Serial.println("ETH Stopped");
eth_connected = false;
break;
default:
break;
}
}
void testClient(const char *host, uint16_t port)
{
Serial.print("\nconnecting to ");
Serial.println(host);
NetworkClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
return;
}
client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
while (client.connected() && !client.available());
while (client.available()) {
Serial.write(client.read());
}
Serial.println("closing connection\n");
client.stop();
}
void setup(void)
{
Serial.begin(115200);
Network.onEvent(onEvent);
SPI.begin(ETH_SPI_SCK, ETH_SPI_MISO, ETH_SPI_MOSI);
ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, SPI);
}
void loop(void)
{
if (eth_connected) {
testClient("google.com", 80);
}
delay(10000);
}
For a complete list of examples, please check the ethernet library on github.