Last active
November 19, 2020 21:48
-
-
Save njh/9463299 to your computer and use it in GitHub Desktop.
Arduino sketch to read the MAC address from a AT24MAC402
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Arduino Sketch that demonstrates reading the factory-programmed | |
EUI-48 MAC Address from a AT24MAC402 / AT24MAC602 Serial EEPROM | |
over TWI / I2C. | |
Product page: http://www.atmel.com/devices/AT24MAC402.aspx | |
Datasheet: http://www.atmel.com/images/atmel-8807-seeprom-at24mac402-602-datasheet.pdf | |
*/ | |
#include <Wire.h> | |
// This will be filled in with the actual MAC address | |
static byte mymac[] = { 0x00,0x00,0x00,0x00,0x00,0x00 }; | |
void setup() { | |
// Start serial communication | |
Serial.begin(9600); | |
Serial.println("Going to read MAC..."); | |
// Start I2C communication | |
Wire.begin(); | |
// Read the MAC address parts from the EEPROM into mymac | |
readMacAddress(0x0, mymac); | |
// Display the result | |
Serial.print("MAC: "); | |
for (byte i = 0; i < 6; ++i) { | |
Serial.print(mymac[i], HEX); | |
if (i < 5) | |
Serial.print(':'); | |
} | |
Serial.println(); | |
} | |
void loop() { | |
} | |
// Function to read the MAC address from a AT24MAC402 EEPROM | |
// | |
// address: the 3-bit address assinged to the EEPROM (using the A0 A1 A2 pins) | |
// macaddr: a pointer to 6 bytes of memory | |
// | |
void readMacAddress(byte address, byte macaddr[]) { | |
int i2c_address = 0x58 | address; | |
// Tell the EEPROM where we would like to read from | |
Wire.beginTransmission(i2c_address); | |
Wire.write(0x9A); // Location of the EUI-48 | |
Wire.endTransmission(); | |
// Now read 6 bytes from that memory address | |
Wire.requestFrom(i2c_address, 6); | |
for(byte i=0; i<6; i++) { | |
macaddr[i] = Wire.read(); | |
} | |
} |
Hi, May be just replace the Disaplay code section, to read the MAC numbers on 2 Digits each :
// Display the result
Serial.print("MAC: ");
for (byte i = 0; i < 6; ++i) {
if (mymac[i] < 16) {Serial.print("0");} // Met sur 2 digits
Serial.print(mymac[i], HEX);
if (i < 5)
Serial.print(':');
}
Serial.println();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello njh I got one of these chip. Does it Actually have a Real mac address on the Chip or Is it so i can Store mac addresses on it?
Joseph