tuxmartin

Arduino read 24AA02E48 (I2C MAC)

Mar 31st, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. //   Arduino read 24AA02E48 (I2C MAC)
  2.  
  3. //  NETESTOVANO   !!!
  4.  
  5. #define I2C_ADDRESS 0x50
  6. #include <Wire.h>
  7.  
  8. static uint8_t mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  9.  
  10. void setup() {
  11.  Wire.begin();        // join i2c bus (address optional for master)
  12.  Serial.begin(9600);  // start serial for output
  13.  
  14.  mac[0] = readRegister(0xFA);
  15.  mac[1] = readRegister(0xFB);
  16.  mac[2] = readRegister(0xFC);
  17.  mac[3] = readRegister(0xFD);
  18.  mac[4] = readRegister(0xFE);
  19.  mac[5] = readRegister(0xFF);
  20. }
  21.  
  22. void loop() {
  23. }
  24.  
  25. byte readRegister(byte r) {
  26.  unsigned char v;
  27.  Wire.beginTransmission(I2C_ADDRESS);
  28.  Wire.write(r);  // register to read
  29.  Wire.endTransmission();
  30.  
  31.  Wire.requestFrom(I2C_ADDRESS, 1); // read a byte
  32.  while (!Wire.available())  {
  33.    // waiting
  34.  }
  35.  v = Wire.read();
  36.  return v;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment