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.

I2C problem in TM4C123

Other Parts Discussed in Thread: LDC1614

Hello, I am Sky.

I am struggling with implementing I2C interface on TM4C123.

In my circuit, LDC1614 chip is connected to I2C1 SDA, SCL pins.

In I2C reading function, it hangs on I2CMasterBusy function.

Could you find a problem in my code?

Here is my code:

void InitI2C(void)
{
    /* I2C Init */

	/////////////////////////////////////////////////////////////////////////
	// I2C0
	/////////////////////////////////////////////////////////////////////////
    /* Enable the peripheral */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

    /* Configure the appropriate pins to be I2C instead of GPIO. */
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

    // Initialize Master and Slave
    I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), true); //bFase: True(400khz), False(100khz)
    /////////////////////////////////////////////////////////////////////////
	// I2C1
	/////////////////////////////////////////////////////////////////////////
    /* Enable the peripheral */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);

    /* Configure the appropriate pins to be I2C instead of GPIO. */
    GPIOPinConfigure(GPIO_PA6_I2C1SCL);
    GPIOPinConfigure(GPIO_PA7_I2C1SDA);
    GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
    GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);

    I2CMasterInitExpClk(I2C1_BASE, SysCtlClockGet(), true); //bFase: True(400khz), False(100khz)
	/////////////////////////////////////////////////////////////////////////
	// I2C2
	/////////////////////////////////////////////////////////////////////////
    /* Enable the peripheral */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2);

    /* Configure the appropriate pins to be I2C instead of GPIO. */
    GPIOPinConfigure(GPIO_PE4_I2C2SCL);
    GPIOPinConfigure(GPIO_PE5_I2C2SDA);
    GPIOPinTypeI2CSCL(GPIO_PORTE_BASE, GPIO_PIN_4);
    GPIOPinTypeI2C(GPIO_PORTE_BASE, GPIO_PIN_5);

    I2CMasterInitExpClk(I2C2_BASE, SysCtlClockGet(), true); //bFase: True(400khz), False(100khz)

    I2C_init();
}

bool I2CRead(uint32_t i2cHandle, uint8_t E2ROM_I2C_ADDRESS, uint8_t addr, uint32_t* data, uint8_t len)
{
    I2CMasterSlaveAddrSet(i2cHandle, E2ROM_I2C_ADDRESS, true);
    I2CMasterDataPut(i2cHandle, addr);
    I2CMasterControl(i2cHandle, I2C_MASTER_CMD_BURST_SEND_START);
    while(I2CMasterBusy(i2cHandle));

	bool status = I2CMasterErr(i2cHandle) == I2C_MASTER_ERR_NONE;
	if (status)
	{
		I2CMasterSlaveAddrSet(i2cHandle, E2ROM_I2C_ADDRESS, true);
		I2CMasterControl(i2cHandle, I2C_MASTER_CMD_SINGLE_RECEIVE);
		while(I2CMasterBusy(i2cHandle));
		uint32_t test = I2CMasterDataGet(i2cHandle);
		return I2CMasterErr(i2cHandle) == I2C_MASTER_ERR_NONE;
	}
	else
		return false;
}

void main()
{
  //...

  InitI2C();  
  uint32_t retValue;
  I2CRead(I2C1_BASE, 0x2A, 0x7F, retValue, 1); //0x2A=slave addr, 0x7E=device ID
}

Thanks in advance.

-Sky