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 read not working properly (TM4C129DNCPDT)



Hi,

I've been trying to read temperature values from AD7414 sensor over I2C bus. To read 10-bit temperature value one need to set address register to 0x00. After that two byte read operation is needed to read temperature.

Here's my code:

GPIOPinTypeI2C(TEMP_SDA_PORT, TEMP_SDA_PIN);
GPIOPinTypeI2CSCL(TEMP_SCL_PORT, TEMP_SCL_PIN);
I2CMasterEnable(I2C2_BASE);
I2CMasterInitExpClk(I2C2_BASE, SysCtlClockGet(), false);
I2CRxFIFOConfigSet(I2C2_BASE, I2C_FIFO_CFG_RX_MASTER);
SysCtlDelay(20000);

while(1)
{

	uint8_t i2c_data[8] = {0};
	uint8_t i;

	I2CMasterSlaveAddrSet(I2C2_BASE, TEMP_I2C_ADDRESS, false);
	I2CMasterDataPut(I2C2_BASE, 0x00);
	I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_SINGLE_SEND);
	while(I2CMasterBusy(I2C2_BASE));
	SysCtlDelay(20000);

	I2CMasterSlaveAddrSet(I2C2_BASE, TEMP_I2C_ADDRESS, true);
	I2CMasterBurstLengthSet(I2C2_BASE, 2);
	I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_FIFO_BURST_RECEIVE_START);
	while(I2CMasterBusy(I2C2_BASE));
	I2CMasterControl(I2C2_BASE, I2C_MASTER_CMD_FIFO_BURST_RECEIVE_FINISH);

	for(i = 0; i < 8; i++)
	{
		if(I2CFIFODataGetNonBlocking(I2C2_BASE, &i2c_data[i]) == 0)
		{
			break;
		}
	}


	I2CRxFIFOFlush(I2C2_BASE);

	SysCtlDelay(200000);
}

Obviously it's not working as it should.

Here's what I'm getting on a scope:

There's a garbage read after first NACK indicating end of transmission. I would not be too bad, because values of 0x1C and 0xA0 are read along with those two 0xFFs.

Unfortunately,  many times burst read just does not occur and I read nothing: