WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

I2C EEPROM

Provides generic support for EEPROM devices accessed over an I2C bus.
Note that these device are often advertised showing the capacity as the number of 'bits' they provide. Such as 512k bits. Since we are dealing in 8 bit bytes then you need to divide this figure by 8. So 512k bits => 64k bytes. Not sure why they are sold that way - maybe its because of 32 bit vs 16 bit vs 8 bit processors?
So why would you need one?
I2C_EEPROM_XXX.jpg
These devices are moderately cheap (say five dollars) and typically come in an 8 pin format and are therefore physically quite small but can store a moderate amount of data - so they are good for storing 'work in progress'. Your processor may come with some 'on board' EEPROM space but typically it will be quite small. So if you need more capacity then here is your solution.
The diagram shows a typical pin out for such a device but you may want to check the data sheet for the device you have purchased.
Besides a Ground and Supply voltage you will also see the SDA and SCL pins which are the heart of the I2C bus.
You will also see a write protect pin, WP, which can be connected to Ground so that the chip is 'writable'.
The only other pins are those labelled A0, A1 and A2.
In 'simple' terms these can be connected to Vcc or Gnd to modify the I2C address of the device starting at its default address of 0xC0 where the resultant address is:
1 1 0 0 a2 a1 a0 0
So "in theory" these 3 bits allow you to connect 8 devices with addresses: 0xC0, 0xC2, 0xC4, 0xC6, 0xC8, 0xCA and 0xCE.
Unfortunately, its not that simple ... although WebbotLib takes care of the complexities for you.
There are a few other things you need to check from the datasheet before you can use the device:
The address size may be 1, 2, 3 or 4 bytes (ie 8, 16, 24 or 32 bits) and is normally dictated by the number of bytes of storage:
However: you may have,say, a 1024 byte EEPROM which therefore needs 10 bits to specify an address. In this case: it uses 1 byte (8 bits) for the memory address and the remaining two bits are placed into A0 and A1 - meaning that each chip has 4 x I2C addresses as if it was 4 separate 256 byte chips. In this case the A0 and A1 pins should be left unconnected.
But don't worry:- the WebbotLib Project Designer will show you examples.
The page size is always a power of 2 - it chops the device up into a number of similar sized pages. A single write to the device must all be in the same page. This value is passed to WebbotLib when creating the device so that your code doesn't have to worry about the restriction - WebbotLib 'just does it'.
Function Summary

Valid XHTML 1.0 Transitional