Zoltan Hudak / Mbed 2 deprecated RawEthernet_Hello

Dependencies:   RawEthernet mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "RawEthernet.h"
00003 
00004 #define BUF_SIZE 100
00005 
00006 uint8_t  len;
00007 uint8_t  buf[BUF_SIZE];
00008 
00009 // Ethernet settings
00010 uint8_t  myMac[6] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};     // MAC address of this slave device
00011 uint8_t  myIp[4] = {192, 168, 1, 191};                        // Dummy IP used to tell LAN switches about the existence of this device
00012 uint8_t  remoteMac[6] = {0x52, 0x4f, 0x47, 0x49, 0x45, 0x52}; // MAC oddress of the master PC
00013 
00014 DigitalOut  led1(LED1);
00015 RawEthernet rawEthernet(PB_5, PB_4, PB_3, PB_6, myMac, myIp); // mosi, miso, sck, cs
00016 
00017 int main()
00018 {
00019     rawEthernet.linkTo(remoteMac);
00020 
00021     while (true) {
00022         len = rawEthernet.receive(buf, BUF_SIZE);
00023         if (len != 0) {
00024             // toggle LED to acknowledge reception of data
00025             led1 = !led1;
00026             
00027             // do some stuff with data
00028 
00029             // in this test echo the received data to the sender           
00030             rawEthernet.send(buf, len);
00031         }
00032     }
00033 }
00034