This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/TM4C123GH6ZRB: TCA9535 access using I2C before the BIOS start

Part Number: TM4C123GH6ZRB
Other Parts Discussed in Thread: TCA9535

Tool/software: TI-RTOS

Hi,

I am accessing a slave device TCA9535 using I2C0 master before the BIOS start. This works well in debug mode but not in release mode.

Workbench used : IAR Embedded Workbench IDE

Below is my code snippet.

void init()

{

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

// The I2C0 peripheral must be enabled before use.
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

// Configure the pin muxing for I2C0 functions on port B2 and B3.
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);

GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_8MA_SC, GPIO_DIR_MODE_HW | GPIO_PIN_TYPE_OD);
// Enable the I2C0 Master module
I2CMasterEnable(I2C0_BASE);

I2C_init();

}

void TCA9535_access(uint8_t *txData, uint8_t txdataLen, uint8_t *rxdata, uint8_t rxdataLen)
{
uint8_t ret = 0;
uint8_t txdataIndex = 0, rxdataIndex = 0;

I2CMasterSlaveAddrSet(I2C0_BASE, TCA9535_ADDRESS, false);
while(I2CMasterBusy(I2C0_BASE)) {}

if(txdataLen != 0)
{
if(txdataLen == 1)
{
I2CMasterDataPut(I2C0_BASE, txData[txdataIndex]);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_BASE)) {}
}
else
{
I2CMasterDataPut(I2C0_BASE, txData[txdataIndex]);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C0_BASE)) {}

for(txdataIndex = 1; txdataIndex < (txdataLen - 1) ; txdataIndex++)
{
I2CMasterDataPut(I2C0_BASE, txData[txdataIndex]);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
while(I2CMasterBusy(I2C0_BASE)) {}
}

I2CMasterDataPut(I2C0_BASE, txData[txdataIndex]);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C0_BASE)) {}
}
}


if(rxdataLen != 0)
{
I2CMasterSlaveAddrSet(I2C0_BASE, TCA9535_ADDRESS, true);
while(I2CMasterBusy(I2C0_BASE)) {}

if(rxdataLen == 1)
{
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
while(I2CMasterBusy(I2C0_BASE)) {}

ret = I2CMasterDataGet(I2C0_BASE) & 0xFF;
rxdata[rxdataIndex] = ret;
}
else
{
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
while(I2CMasterBusy(I2C0_BASE)) {}

ret = I2CMasterDataGet(I2C0_BASE) & 0xFF;
rxdata[rxdataIndex] = ret;

for(rxdataIndex = 1; rxdataIndex < (rxdataLen - 1) ; rxdataIndex++)
{
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
while(I2CMasterBusy(I2C0_BASE)) {}

ret = I2CMasterDataGet(I2C0_BASE) & 0xFF;
rxdata[rxdataIndex] = ret;
}

I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
while(I2CMasterBusy(I2C0_BASE)) {}

ret = I2CMasterDataGet(I2C0_BASE) & 0xFF;
rxdata[rxdataIndex] = ret;
}
}
}

Please provide your information.

  • Gowtham R said:

    GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_8MA_SC, GPIO_DIR_MODE_HW | GPIO_PIN_TYPE_OD);

    I am almost certain that this function proves "harmful" to your earlier use of,   "GPIOPinType() & GPIOPinConfigure()"  -  especially when I2C is employed.

    Removing that "PadConfig" call should prove quick & easy - and I suspect will succeed...

  • Do you have different optimization between debug mode and the release mode?