How is the correct way to describe and read the EEPROM 27xx256? We have 3 blocks on the I2C bus. Two of them (LM75 and RTC8564) I can read / write without problems. With the 27xx256, on the other hand, written and read data are always different. Have you any idea what I could change?
// Initialize I2Cx, without affecting hardware registers
i2c = Imx7I2c_Init(L"I2C1");
if (i2c == NULL)
printf("Error in I2c_Init()\r\n");
// ====== BusScan ======
i2cScan(i2c);
// Open the i2c port
Imx7I2c_Open(i2c);
// Change configuration as required
Imx7I2c_SetConfigInt(i2c, L"BitRateHz", 400000, StoreVolatile); // Set I2C speed to 400KHz
Imx7I2c_SetConfigInt(i2c, L"SlaveAddrSize", 7, StoreVolatile); // Set 7 bit Slave address
//#rl 0x48:LM75-3 Digital Temperature Sensor
//#rl 0x50:LC256 SEEPROM 256kb(x8)
//#rl 0x51:RTC8564 Real Time Clock
Imx7I2c_SetConfigInt(i2c, L"SlaveAddr", 0x50, StoreVolatile);
//I2C Write
i = 0;
writebuf[i++] = 'T';
writebuf[i++] = 'E';
writebuf[i++] = 'S';
writebuf[i++] = 'T';
writebuf[i++] = '1';
writebuf[i++] = '2';
writebuf[i++] = '3';
writebuf[i] = '4';
// I2C Write EEPROM
if (Imx7I2c_SetConfigInt(i2c, L"RegisterAddrSize", 16, StoreVolatile) == TRUE) // 16bit Register address to send
{
Imx7I2c_SetConfigInt(i2c, L"RegisterAddr", 0, StoreVolatile); // write to adress 0
returnValue = Imx7I2c_Write(i2c, (DWORD*)writebuf, 8); // write 8bytes
if (returnValue != I2C_RW_FAILURE)
printf("\nwrite to EEPROM: %d, %d, %d, %d, %d, %d, %d, %d \r\n", writebuf[0], writebuf[1], writebuf[2], writebuf[3], writebuf[4], writebuf[5], writebuf[6], writebuf[7]);
}
// I2C Read EEPROM
for (i = 0; i < 8; i++)
readbuf[i] = 0;
if (Imx7I2c_SetConfigInt(i2c, L"RegisterAddrSize", 0, StoreVolatile) == TRUE) // No Register address to send
//if (Imx7I2c_SetConfigInt(i2c, L"RegisterAddrSize", 16, StoreVolatile) == TRUE) // 16bit Register address to send
{
Imx7I2c_SetConfigInt(i2c, L"RegisterAddr", 0, StoreVolatile); // read from adress 0
returnValue = Imx7I2c_Read(i2c, (DWORD*)readbuf, 8); // read 8bytes
if (returnValue != I2C_RW_FAILURE)
{
printf("\nread from EEPROM: %d, %d, %d, %d, %d, %d, %d, %d \r\n", readbuf[0], readbuf[1], readbuf[2], readbuf[3], readbuf[4], readbuf[5], readbuf[6], readbuf[7]);
}
}
// Close and deinit I2C port
Imx7I2c_Close(i2c);
Imx7I2c_Deinit(i2c);