I've been able to successfully write and read back to the EEPROM (according to my logic analyzer), but the data I get back on a read is incorrect - for the first byte of the EEPROM I'm getting the address/control byte, and fo rthe second byte read I get the first data byte.
The following code is used for the read
Code: Select all
#define EEPROM_ADDR 0x50
typedef struct _EEPROM_CFG {
BYTE unit_id;
BYTE volume;
} EEPROM_CFG;
static EEPROM_CFG eeprom_cfg;
void ReadEEPROM(void)
{
PBYTE eeprom_ptr;
int i;
eeprom_ptr = (PBYTE) &eeprom_cfg;
I2CInit();
I2CStart(EEPROM_ADDR, I2C_START_WRITE, I2C_RX_TX_TIMEOUT);
I2CSend (0x00); // Send EEPROM address MSB
I2CSend (0x00); // Send EEPROM address LSB
I2CRestart (EEPROM_ADDR, I2C_START_READ, I2C_RX_TX_TIMEOUT); // Send restart to prevent stop bit
for (i=0; i < sizeof (eeprom_cfg); i++) {
I2CRead (eeprom_ptr++);
}
I2CStop();
}
Does anyone see anything wrong with this read sequence? Again, according to my protocol analyzer, the proper data is being returned.