i2c newbie -- need help understanding

So I bought a couple of the Microchip 24AA02E i2c Serial EEPROM with mac address (EUI-48 Node Identity) -- datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/22124D.pdf

I'm trying to figure out how to read just the mac address section of this chip using i2c... anyone have any ideas? I tried using wire library however it needs an address, etc.

// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device
// Refer to the "Wire Slave Sender" example for use with this

// Created 29 March 2006
#define I2C_ADDRESS 0x00
#include <Wire.h>

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
 
  Serial.begin(115200);  // start serial for output
 Serial.println("begin.");
}

void loop()
{
  char myself = readRegister(0xFA);
  Serial.print(myself);
  delay(1000);
}

unsigned char readRegister(unsigned char r)
{
  unsigned char v;
  Wire.beginTransmission(I2C_ADDRESS);
  Wire.send(r);  // register to read
  Wire.endTransmission();

  Wire.requestFrom(I2C_ADDRESS, 1); // read a byte
  while(!Wire.available())
  {
    // waiting
  }
  v = Wire.receive();
  return v;
}

Does nothing...

Danny

#define I2C_ADDRESS 0x00

Are you sure that the I2C address of the chip is 0x00?

Try the address 0x50

I've tried everything, 0x50 too... Do I need to connect the pull up resistor (1k) on the SDA line? Haven't tried that yet.

You need 4K7 pull ups on both the SDA and the clock line.
What are you getting back?
From that code you posted you should be reading back zero.
Reading other registers should give you:-
Register Contents
0xFB 0x04
0xFC 0xA3
These are fixed, the following should be unique to the device, the data sheet has:-
0xFD 0x12
0xFE 0x34
0xFF 0x56

For an address of 00-04-A3-12-34-56

using no resistors and using i2c address 0x50 or 0x51 and reading register 0xFB, I get back 255. I will try adding 4K7 pull ups to both clock and SDA and report back.

Ok. I put a 4.7k ohm pull up resister on both the SDA and SCL lines and still, I only get 255 using this code:

#include <Wire.h>
#define EEPROM_ADDR 0x50          // I2C Buss address of 24LC256 256K EEPROM


void setup(){
  Wire.begin();                    // join I2C bus (address optional for master)
  Serial.begin(115200);
  
  delay(500);
  Serial.println("Reading Test:");
 
    Serial.print(i2c_eeprom_read_byte(EEPROM_ADDR, 0xFC),DEC);
    Serial.print(" ");
  
}

void loop(){
}

void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
  int rdata = data;
  Wire.beginTransmission(deviceaddress);
  Wire.send((int)(eeaddress >> 8));    // Address High Byte
  Wire.send((int)(eeaddress & 0xFF));  // Address Low Byte
  Wire.send(rdata);
  Wire.endTransmission();
}

// Address is a page address, 6-bit (63). More and end will wrap around
// But data can be maximum of 28 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
  Wire.beginTransmission(deviceaddress);
  Wire.send((int)(eeaddresspage >> 8)); // Address High Byte
  Wire.send((int)(eeaddresspage & 0xFF)); // Address Low Byte
  byte c;
  for ( c = 0; c < length; c++)
    Wire.send(data[c]);
  Wire.endTransmission();
  delay(10);                           // need some delay
}

byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
  byte rdata = 0xFF;
  Wire.beginTransmission(deviceaddress);
  Wire.send((int)(eeaddress >> 8));    // Address High Byte
  Wire.send((int)(eeaddress & 0xFF));  // Address Low Byte
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,1);
  if (Wire.available()) rdata = Wire.receive();
  return rdata;
}

Anything else I need to do to get i2c working with the 24AA line of EEPROMs?

DOH! I figured it out... works.

Thanks,
Danny

Here is the code that pulls the mac address from a Microchip 24AA02E48:

#define I2C_ADDRESS 0x50
#include <Wire.h>

static uint8_t mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(115200);  // start serial for output
  Serial.println("Getting MAC: ");
  
  mac[0] = readRegister(0xFA);
  mac[1] = readRegister(0xFB);
  mac[2] = readRegister(0xFC);
  mac[3] = readRegister(0xFD);
  mac[4] = readRegister(0xFE);
  mac[5] = readRegister(0xFF);
  
  char tmpBuf[17];
  sprintf(tmpBuf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  Serial.println(tmpBuf);
}

void loop()
{
 
  
}

byte readRegister(byte r)
{
  unsigned char v;
  Wire.beginTransmission(I2C_ADDRESS);
  Wire.send(r);  // register to read
  Wire.endTransmission();

  Wire.requestFrom(I2C_ADDRESS, 1); // read a byte
  while(!Wire.available())
  {
    // waiting
  }
  v = Wire.receive();
  return v;
}