Dear all,
I have been trying to interface 24C series EEPROM with I2C1 module with TM4C launchpad with the following:
PA6 ---> SCL of EEPROM
PA7----> SDA of EEPROM
The configuration of the I2C module is done as:
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
SysCtlDelay(10); // wastes 5 clock cycle to enable activation of the peripheral
GPIOPinConfigure(GPIO_PA6_I2C1SCL);
GPIOPinConfigure(GPIO_PA7_I2C1SDA);
SysCtlDelay(10);
GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
SysCtlDelay(10);
I2CMasterInitExpClk(I2C1_BASE, SysCtlClockGet(), false); // have the slow mode = 100KHz
SysCtlDelay(10);
The code that has been done for writing a data to I2C Slave eeprom with Addr = 1010111 at location 0x02 inside it with the data being = 'Q' as shown below:
void I2C_SEND_CHAR()
{
I2CMasterSlaveAddrSet(I2C1_BASE, 0x57, false);
I2CMasterDataPut(I2C1_BASE, 0x02);
I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusBusy(I2C1_BASE))
{
// do nothing
}
I2CMasterDataPut(I2C1_BASE, 'Q');
I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusBusy(I2C1_BASE))
{
// do nothing
}
Now, after some time gap, I want to read back the same data from the same location of the EEPROM using the random read method of the eeprom that involves a dummy write (for setting address pointer = 0x02) and then reading the data from the location. This has been done as given below:
void I2C_RECV_CHAR()
{
I2CMasterSlaveAddrSet(I2C1_BASE, 0x57, false);
I2CMasterDataPut(I2C1_BASE, 0x02); // dummy write of address = 0x02
I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusBusy(I2C1_BASE))
{
}
I2CMasterSlaveAddrSet(I2C1_BASE, 0x57, true);
data_read = I2CMasterDataGet(I2C1_BASE); // data_read declared as ungined int 32 bit before
I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
while(I2CMasterBusBusy(I2C1_BASE))
{
}
I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
while(I2CMasterBusBusy(I2C1_BASE))
{
}
}
But the problem is that I cannot read back the data from the location. It is always coming as 0xFF from the read location which is the default value written from factory. Where could be the problem? Please help