Arduino AT24C08 EEPROM Driver

By | January 15, 2014

Unlike some other I2C EEPROM IC drivers, AT24C08 / AT24C08A need their 2 MSB address bits sent in the first device address byte.

This assumes the A2 pin is connected to ground:


void write_byte(unsigned int eeaddress, byte data) {
int rdata = data;
byte addr = (byte)(_deviceaddress | ((eeaddress >> 8) & 0x03));
Wire.beginTransmission(addr);
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(rdata);
Wire.endTransmission();
delay(5);
}

byte read_byte(unsigned int eeaddress) {
byte rdata = 0xFF;
byte addr = (byte)(_deviceaddress | ((eeaddress >> 8) & 0x03));
Wire.beginTransmission(addr);
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(addr, 1);
if (Wire.available()) {
rdata = Wire.read();
}
return rdata;
}

Leave a Reply

Your email address will not be published.