Reading and Writing Serial EEPROMs
Higher Capacity EEPROMs
So what if the thing that we want to store is bigger than complete text of the Ghostbusters theme as written and performed by Ray Parker Jr? As it happens, you can get EEPROM devices with much larger storage. For instance, the Microchip 24LC1025 can store up to 1025 Kbits! That's 128KB, enough space to have some real fun with!
Using the Microchip 24LC1025 is almost exactly like using the smaller EEPROM devices but with one minor tweak. Because the memory space is so much larger, two bytes is no longer enough to represent the memory address that we want to modify. To get around this problem, the 24LC1025 splits up the memory addresses into two separate blocks. When you address the chip, you send the block selector for the block that you want to manipulate in place of where you'd usually send the first bit of the chip address. Because of this, pin A2 on the EEPROM isn't used and needs to be tied to 5V in order for the device to work. You'll notice that we've already tied A2 to 5V in our previous example, so you could use the same example circuit to hook it up!
Arduino Sketch Example Write Something in a Higher Capacity EEPROM
Along with that change to our Arduino hookup, we'll also need to add to our code in order to switch the block select when we reach above a certain memory address. Here's what that operation looks like when we're writing:
language:c
void writeEEPROM(long eeAddress, byte data)
{
if (eeAddress < 65536)
{
Wire.beginTransmission(EEPROM_ADR_LOW_BLOCK);
eeAddress &= 0xFFFF; //Erase the first 16 bits of the long variable
}
else
{
Wire.beginTransmission(EEPROM_ADR_HIGH_BLOCK);
}
Wire.write((int)(eeAddress >> 8)); // MSB
Wire.write((int)(eeAddress & 0xFF)); // LSB
Wire.write(data);
Wire.endTransmission();
}
Arduino Sketch Example Read Something in a Higher Capacity EEPROM
...and here it is when we're reading:
language:c
byte readEEPROM(long eeaddress)
{
if (eeaddress < 65536)
Wire.beginTransmission(EEPROM_ADR_LOW_BLOCK);
else
Wire.beginTransmission(EEPROM_ADR_HIGH_BLOCK);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
if (eeaddress < 65536)
Wire.requestFrom(EEPROM_ADR_LOW_BLOCK, 1);
else
Wire.requestFrom(EEPROM_ADR_HIGH_BLOCK, 1);
byte rdata = 0xFF;
if (Wire.available()) rdata = Wire.read();
return rdata;
}
It's just that easy! You can get the complete Arduino example sketches here if you want to play with it yourself: