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

Committer:
hudakz
Date:
Mon Aug 20 11:47:11 2018 +0000
Revision:
0:f1193d5dfe26
Initial release.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:f1193d5dfe26 1 #include "mbed.h"
hudakz 0:f1193d5dfe26 2 #include "RawEthernet.h"
hudakz 0:f1193d5dfe26 3
hudakz 0:f1193d5dfe26 4 #define BUF_SIZE 100
hudakz 0:f1193d5dfe26 5
hudakz 0:f1193d5dfe26 6 uint8_t len;
hudakz 0:f1193d5dfe26 7 uint8_t buf[BUF_SIZE];
hudakz 0:f1193d5dfe26 8
hudakz 0:f1193d5dfe26 9 // Ethernet settings
hudakz 0:f1193d5dfe26 10 uint8_t myMac[6] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; // MAC address of this slave device
hudakz 0:f1193d5dfe26 11 uint8_t myIp[4] = {192, 168, 1, 191}; // Dummy IP used to tell LAN switches about the existence of this device
hudakz 0:f1193d5dfe26 12 uint8_t remoteMac[6] = {0x52, 0x4f, 0x47, 0x49, 0x45, 0x52}; // MAC oddress of the master PC
hudakz 0:f1193d5dfe26 13
hudakz 0:f1193d5dfe26 14 DigitalOut led1(LED1);
hudakz 0:f1193d5dfe26 15 RawEthernet rawEthernet(PB_5, PB_4, PB_3, PB_6, myMac, myIp); // mosi, miso, sck, cs
hudakz 0:f1193d5dfe26 16
hudakz 0:f1193d5dfe26 17 int main()
hudakz 0:f1193d5dfe26 18 {
hudakz 0:f1193d5dfe26 19 rawEthernet.linkTo(remoteMac);
hudakz 0:f1193d5dfe26 20
hudakz 0:f1193d5dfe26 21 while (true) {
hudakz 0:f1193d5dfe26 22 len = rawEthernet.receive(buf, BUF_SIZE);
hudakz 0:f1193d5dfe26 23 if (len != 0) {
hudakz 0:f1193d5dfe26 24 // toggle LED to acknowledge reception of data
hudakz 0:f1193d5dfe26 25 led1 = !led1;
hudakz 0:f1193d5dfe26 26
hudakz 0:f1193d5dfe26 27 // do some stuff with data
hudakz 0:f1193d5dfe26 28
hudakz 0:f1193d5dfe26 29 // in this test echo the received data to the sender
hudakz 0:f1193d5dfe26 30 rawEthernet.send(buf, len);
hudakz 0:f1193d5dfe26 31 }
hudakz 0:f1193d5dfe26 32 }
hudakz 0:f1193d5dfe26 33 }
hudakz 0:f1193d5dfe26 34