Tool/software: TI-RTOS
Hi,
I need to read and write to external EEPROM through I2C0 master before BIOS_start(). Below is my code snippet for read and write operation. External EEPROM has the value 0x03 in location 0x0000 . But the read value is always zero.
How to do EEPROM read and write before BIOS_start() ?
#define EPPROM_DEVICE_ADDRESS 0xAE
#define EEPROM_ADDRESS (EPPROM_DEVICE_ADDRESS >> 1)
void EepromRead(uint16_t address_u16, uint8_t *rxdata, uint8_t rxdataLen)
{
uint8_t ret = 0;
uint8_t address_u8;
I2CMasterSlaveAddrSet(I2C0_BASE, EPPROM_DEVICE_ADDRESS, false);
while(I2CMasterBusy(I2C0_BASE)) {}
SysCtlDelay(1000);
I2CMasterDataPut(I2C0_BASE, 0x00); //READ
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C0_BASE)) {}
SysCtlDelay(1000);
address_u8 = (uint8_t) (address_u16 >> 8);
I2CMasterDataPut(I2C0_BASE, address_u8); //First Word Address
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
while(I2CMasterBusy(I2C0_BASE)) {}
SysCtlDelay(1000);
address_u8 = (uint8_t) (address_u16);
I2CMasterDataPut(I2C0_BASE, address_u8); //Second Word Address
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C0_BASE)) {}
SysCtlDelay(1000);
I2CMasterSlaveAddrSet(I2C0_BASE, EPPROM_DEVICE_ADDRESS, true);
while(I2CMasterBusy(I2C0_BASE)) {}
SysCtlDelay(1000);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE );
while(I2CMasterBusy(I2C0_BASE)) {}
SysCtlDelay(1000);
ret = I2CMasterDataGet(I2C0_BASE) & 0xFF;
rxdata[0] = ret;
}
Void main()
{
uint8_t rxBuff[1];
EepromRead(0x0000, rxBuff, 1);
System_printf("Data Read %x\n", rxBuff[0]);
}