AT24C32 I2C EEPROM as found on Tiny RTC DS1307 board

If you have one of those ebay boards and want to use the extra memory on board here is how to do it. The memory is apparently good for 1 million write cycles and 100 years! Much better than the 1024 bytes EEPROM on the Atmega328 and much more plentiful - 32K bytes!

Here are the routines to use it, hope they are useful to someone, as I had to search high a low to try to understand how the thing works. The code is self explanatory - I have hardcoded a retry count of 10 which has passed my read/write test.

#define AT24C32_I2C_ADDRESS 0x50  // the I2C address of Tiny RTC AT24C32 EEPROM

void Tiny_RTC_DS1307_24C32::EEPROM_write_byte( unsigned int uiAddress, byte bData ) 
{
	int iCount=0;
	do
	{
		Wire.beginTransmission(AT24C32_I2C_ADDRESS);
		Wire.write((byte)(uiAddress >> 8)); // MSB
		Wire.write((byte)uiAddress); // LSB
		Wire.write(bData);
	} while (Wire.endTransmission()!=0 && ++iCount<10);
}

void Tiny_RTC_DS1307_24C32::EEPROM_read_byte( unsigned int uiAddress, byte *pbData ) 
{
	int iCount=0;
	do
	{
		Wire.beginTransmission(AT24C32_I2C_ADDRESS);
		Wire.write((byte)(uiAddress >> 8)); // MSB
		Wire.write((byte)uiAddress); // LSB
	} while (Wire.endTransmission()!=0 && ++iCount<10);
	Wire.requestFrom(AT24C32_I2C_ADDRESS,1);
	*pbData = Wire.read(); 
}
1 Like

Hi, how do I address the individual bytes on the EEPROM? Could you give an example where you write a string from the beginning of the EEPROM?

Thanks

Paai