Electronic – EEPROM Read Operation Always Returns 0xFF

armeepromi2ckeillpc1768

I'm working with a AT24C04 EEPROM which communicates with a LPC1768 MCU on a I2C bus.

I try to write a 8 bit data (0xF0) on the 0x00 Address of the memory but when I want to read the content of this address, EEPROM returns 0xFF instead of 0xF0 which means nothing is written on this address.

It seems I have no problem in reading the EEPROM but there is something wrong with write operation.

My compiler is uVision v5.28 and here is my code:

uint8_t DeviceAddress = 0x50;
uint8_t TxBufferByteWrite[2]={0x00,0xF0};   
uint8_t RxBuffer[1];    

I2C_Init(LPC_I2C1, 100000);
I2C_Cmd(LPC_I2C1, I2C_MASTER_MODE, ENABLE); 

//Byte Write    
I2CTransferConfig.sl_addr7bit = DeviceAddress;
I2CTransferConfig.tx_data = TxBufferByteWrite;
I2CTransferConfig.tx_length = sizeof(TxBufferByteWrite);
I2CTransferConfig.rx_data = NULL;
I2CTransferConfig.rx_length = 0;
I2CTransferConfig.retransmissions_max = 3;
I2C_MasterTransferData(LPC_I2C1, &I2CTransferConfig, I2C_TRANSFER_POLLING);     

//Current Address Read
I2CTransferConfig.sl_addr7bit = DeviceAddress;
I2CTransferConfig.tx_data = NULL;
I2CTransferConfig.tx_length = 0;    
I2CTransferConfig.rx_data = RxBuffer;
I2CTransferConfig.rx_length = sizeof(RxBuffer);
I2CTransferConfig.retransmissions_max = 3;
I2C_MasterTransferData(LPC_I2C1, &I2CTransferConfig, I2C_TRANSFER_POLLING); 

if( RxBuffer[0]==0xF0)
PrintS("Memory Working");

Thanks in advance.

Best Answer

After your write operation, you should check that the EEPROM ACK'ed to be sure the write operation was successful.

Your write operating incremented the EEPROM's address pointer to 0x01. From the Atmel datasheet for your EEPROM:

The internal data word address counter maintains the last address accessed during the last read or write operation, incremented by one.

Therefore, when you do the read operation, you read from address 0x01, not from 0x00 where you just wrote to.

Before your read operation, you should do a one-byte write operation to set the read pointer back to 0x00.

Again from your datasheet:

RANDOM READ: A random read requires a “dummy” byte write sequence to load in the data word address. Once the device address word and data word address are clocked in and acknowledged by the EEPROM, the microcontroller must generate another start condition. The microcontroller now initiates a current address read by sending a device address with the read/write select bit high.