ethermega mac address

Combining the power of the ATmega2560 MCU with onboard Ethernet, a microSD card slot, an efficient switchmode power supply, and a small prototyping area. [Product page]
Post Reply
mrose17
Posts: 5
Joined: Wed Sep 25, 2013 5:26 pm

ethermega mac address

Post by mrose17 » Wed Sep 25, 2013 5:50 pm

i "get" the part about having to use Ethernet.begin() to tell the chip its mac address.

surely however, the actual MAC address must be known somewhere...

in the future, could this be printed and put either on the board or the box or something?

just a thought!

thanks!

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: ethermega mac address

Post by andrew » Wed Sep 25, 2013 9:59 pm

You make your own MAC address. :) For the benefit of other readers, currently any typical Arduino-Ethernet project defines the MAC address in the sketch. For example, load the "webserver" example sketch in the Ethernet part of examples in the IDE. There is the line with the classic default MAC address that can be changed at whim or as required:

Code: Select all

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
However in the near future our Ethernet-enabled products will have an EEPROM with the MAC address hard-coded as well - which saves users of multiple boards having to select their own MAC and update each sketch for each board. We'll announce these when available.

bernfels
Posts: 19
Joined: Mon Jan 16, 2012 6:09 am
Location: Perth
Contact:

Re: ethermega mac address

Post by bernfels » Sat Oct 05, 2013 5:28 am

[quote="johnb"]You make your own MAC address. :) For the benefit of other readers, currently any typical Arduino-Ethernet project defines the MAC address in the sketch. For example, load the "webserver" example sketch in the Ethernet part of examples in the IDE. There is the line with the classic default MAC address that can be changed at whim or as required:

Code: Select all

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
There is a range of "private" MAC numbers that people should use... otherwise the Ethermega could be mistaken for an iPhone :D

Store the MAC ID in EEPROM and initialise during setup(). Some initialisation extracts from a project:

Code: Select all

/*
 * Network EEPROM values loaded in setup()
 */
byte MAC[6];            // Hardware address of this device
…
void SetupEthernet() {
  /*
     load Ethernet parameters from EEPROM
     and initialise network accordingly
  */
  // fetch MAC from EEPROM
  EEMAC(MAC,MyMAC);
…
  // Decide if DHCP to be done
  char dodhcp = EEPROM.read(MyIPdhcp);
  if ( dodhcp == 'Y' || dodhcp == 'y' ) {
    dodhcp = 'Y';
    if (Ethernet.begin(MAC) == 0) {
      Serial.write("DHCP failed. Trying Static.\n");
      dodhcp = 'N';
    }
  } else {
    dodhcp = 'N';
  }
  if ( dodhcp == 'N' ) {
    IPAddress moi = EEIPAddr(MyIP);
    IPAddress nm  = NMask(MyNetMask);
    IPAddress gw  = EEIPAddr(MyGwIP);
    IPAddress dns = EEIPAddr(MyDnsSrv);
    if ( (nm = NMask(MyNetMask)) == (IPAddress)0UL )
      nm = (255,255,255,0);
  
    if ( dns != 0UL ) {
      //  If DNS preset, set up interface accordingly
      Ethernet.begin(MAC,moi,dns,gw,nm);
    } else {
      //Serial.write("EEPROM network config incomplete. Trying best.\n");
      if ( dns == (IPAddress)0UL )
        Ethernet.begin(MAC,moi);
    }
  }
…
}
…
// Produce a MAC from EEPROM values at offset if checksum OK
void EEMAC(uint8_t *eemac, uint16_t base){
  byte b[] = { EEPROM.read(base),
              EEPROM.read(base+1),
              EEPROM.read(base+2),
              EEPROM.read(base+3),
              EEPROM.read(base+4),
              EEPROM.read(base+5)};
  byte sum = b[0] + b[1]+b[1] + b[2] + b[3]+b[3] + b[4] + b[5]+b[5];
  byte s = EEPROM.read(base+6);
  if ( sum == s ) {
    eemac[0] = b[0]; eemac[1] = b[1]; eemac[2] = b[2];
    eemac[3] = b[3]; eemac[4] = b[4]; eemac[5] = b[5];
  }
}
…
// Initialise EEPROM values to "Factory"
void FactoryDefault(uint16_t base, uint16_t top) {
  /* "PRIVATE" MAC Number OUI
     00-0B-F4    00-0C-53    00-0D-58    00-0D-A7    00-0D-C2
     00-0D-F2    00-0E-17    00-0E-22    00-0E-2A    00-0E-EF
     00-0F-09    00-16-B4 ...
     AC-DE-48
  */
  byte ss = 8;                          // = 9600 / 1200
  byte eemac[] = { 0xAC, 0xDE, 0x48, 0x49, 0x52, 0x10 };
…
}
…
void setup() {
…
  SetupEthernet();
…
}
Note that I store multi-byte EEPROM values with a simple checksum to ensure that I can detect corruption due to incomplete writes when the values were supposed to be written to EEPROM.

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: ethermega mac address

Post by andrew » Mon Oct 07, 2013 9:53 pm


Post Reply