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.
addr7bit
implies they want the 7-bit I2C address (which doesn't include the W/R bit), and the library code will take care of shifting and inserting the W/R bit depending on the requested operation. \$\endgroup\$