Tool/software: TI-RTOS
Hi,
I'm using I2C APIs of TI-RTOS (v2.16) to access an external EEPROM 24C256 on my Tiva-C launchpad . The program executes normally in CCS V6.1.2, but the data read from EEPROM is not equal to the data written. The data read from 24C256 are all '0'. I'm pretty sure that the I2C0 configuration and I install 2.2K ohm resistor on the PB2 and PB3 pins.
I wonder how "I2C_transfer()" knows if the EEPROM is 1-byte memory address or 2-byte address since I can't find any parameters to specify this. I don't have the chance to try 1-byte address EEPROM like 24C02 and besides my project needs to use 24C256.
I list both the write and read routines below ( They are copied from TI-RTOS example with slight modifications. Any help will be appreciated and thanks in advance.
Eric
void Task_Write_24C256( uint8_t *data_ptr, uint16_t transfer_cnt ) // declared as a task in CCS
{
unsigned int i = 0;
I2C_Handle handle;
I2C_Params i2cparams;
I2C_Transaction i2c;
I2C_Params_init(&i2cparams);
i2cparams.bitRate = I2C_400kHz;
//i2cparams.transferMode = I2C_MODE_BLOCKING;
//i2cparams.transferCallbackFxn = NULL;
handle = I2C_open( Board_I2C0, &i2cparams );
if (handle == NULL)
System_abort("I2C was not opened");
i2c.slaveAddress = I2C_SLAVE_ADDR_FRAM;
i2c.readCount = 0; // clear read-parameters when not read access
i2c.readBuf = NULL;
i2c.writeBuf = data_ptr; // set valid write-parameters for write access
i2c.writeCount = transfer_cnt;
if (!I2C_transfer(handle, &i2c))
{
System_printf("Bad I2C transfer !");
System_flush();
System_abort("Bad I2C transfer !");
}
I2C_close( handle);
}
void Task_Read_24C256( uint8_t *data_ptr, uint16_t transfer_cnt ) // declared as a task in CCS
{
unsigned int i = 0;
I2C_Handle handle;
I2C_Params i2cparams;
I2C_Transaction i2c;
I2C_Params_init(&i2cparams);
i2cparams.bitRate = I2C_400kHz;
//i2cparams.transferMode = I2C_MODE_BLOCKING;
//i2cparams.transferCallbackFxn = NULL;
handle = I2C_open( Board_I2C0, &i2cparams );
if (handle == NULL)
System_abort("I2C was not opened");
i2c.slaveAddress = I2C_SLAVE_ADDR_FRAM;
i2c.readCount = transfer_cnt; // set valid read-parameters for read access
i2c.readBuf = data_ptr ;
i2c.writeBuf = NULL; // clear write-parameters when not write access
i2c.writeCount = 0;
if (!I2C_transfer(handle, &i2c))
{
System_printf("Bad I2C transfer !");
System_flush();
System_abort("Bad I2C transfer !");
}
I2C_close( handle);
}