Demo for the RawEthernet library: ENC28J60 ethernet controller optimized for speed. TCP/IP overhead is removed. Only plain Ethernet frames are used for communication.

Dependencies:   RawEthernet mbed

Revision:
0:f1193d5dfe26
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Aug 20 11:47:11 2018 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+#include "RawEthernet.h"
+
+#define BUF_SIZE 100
+
+uint8_t  len;
+uint8_t  buf[BUF_SIZE];
+
+// Ethernet settings
+uint8_t  myMac[6] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};     // MAC address of this slave device
+uint8_t  myIp[4] = {192, 168, 1, 191};                        // Dummy IP used to tell LAN switches about the existence of this device
+uint8_t  remoteMac[6] = {0x52, 0x4f, 0x47, 0x49, 0x45, 0x52}; // MAC oddress of the master PC
+
+DigitalOut  led1(LED1);
+RawEthernet rawEthernet(PB_5, PB_4, PB_3, PB_6, myMac, myIp); // mosi, miso, sck, cs
+
+int main()
+{
+    rawEthernet.linkTo(remoteMac);
+
+    while (true) {
+        len = rawEthernet.receive(buf, BUF_SIZE);
+        if (len != 0) {
+            // toggle LED to acknowledge reception of data
+            led1 = !led1;
+            
+            // do some stuff with data
+
+            // in this test echo the received data to the sender           
+            rawEthernet.send(buf, len);
+        }
+    }
+}
+