User manual

I2C API reference
62 © 2007-2010 Analytica GmbH
Description
The I2CWriteEEPROM function writes data to an I2C EEPROM.
Of course all access to the memory of an EEPROM is done by standard I2C read or write commands. So,
when writing to the memory only the matching slave address, the memory offset address and the data has
to be sent to the I2C bus.
I2CWriteEEPROM translates the given memory address on the chip by means of the sub address and
the addressing mode of the present EEPROM type. The slave address of the EEPROM is automatically
determined and not mandatory for the fucntion call.
Tip
It is important to note that an EEPROM is divided into memory pages, and that a single write
command can only program data within a page. Users of I2CWriteEEPROM must ensure
to do not write across page limits. The page size depends on the EEEPOM type.
See the following example for writing data to a ST24C1024.
#include <AnaGateDllSPI.h>
int main()
{
char cBufferPage[256];
int hHandle = 0;
int nRC = 0;
unsigned short nSubAddress = 0;
1
unsigned int nOffsetFormat = 0x10|0x0F;
2
int nRC = I2COpenDevice(&hHandle, 400000, "192.168.0.254", 5000);
if ( nRC == 0 )
{
memset(cBufferPage,0,256); // clear page buffer
for (int i=0; i<512;i++)
{
I2CWriteEEPROM( hHandle, nSubAddress, i*256, cBufferPage, 256, nOffsetFormat );
3
}
I2CCloseDevice(hHandle);
}
return 0;
}
1
It is possible to address 4 individual ST24C1024 on a single I2C bus. By selection of subaddress 0
the control pins E2 and E1 have to be LOW.
2
17 address bits are used to address the 128KB of a ST24C1024. 16 bits are set via the address bytes of
the write command: 16=0x0F. The address bit A16 is set via the E0 bit of the Chip Enable Address,
therefore addressing mode 1 (E2-E1-A0) must be set: 0x10.
3
The page size of a ST24C1024 is 256 byte, every page is programmed full within the for-loop.
See also
I2CReadEEPROM