Other Parts Discussed in Thread: TMP006
I am working with a Tiva eval board TM4C1294XL using TIRTOS version 2.14.0.10 and CCS 6.1.1. I am evaluating the Tiva CPU as a replacement for the Stallaris CPU I have used in the past so I have got this temperature device to work in the past. I ran into a question regarding I2C. I have an I2C temperature sensor MCP9808 hooked up to the eval board on the Tiva I2C0 interface. As a test, I am reading the manufacture ID from the temperature sensor and the ID is a 2 byte register. The data sheet on the temp sensor is:
http://ww1.microchip.com/downloads/en/DeviceDoc/25095A.pdf
The problem is I have not been able to read the 2 byte data from the temp sensor reliably and I think it has to do with how the function I2CMasterControl() is used when I read 2 bytes from the temperature sensor.
If I use I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); then read the first byte and then do I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); and then read the second byte, a scope with a I2C module shows that sometimes the temp sensor will send two bytes but mostly the scope will only show 1 byte. When 2 bytes are sent the data is read correctly but the two bytes are not always sent so it’s unreliable.
If I use I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); and read the first byte and then use I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT); and read the second byte then do the I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); the scope with the I2C always shows the temperature sensor sending 2 bytes data I read is inconstant.
In general if I want to read a 2 byte register shouldn’t I use I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); and read the first byte and then the I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); and then read the last byte? I assume the burst is used for more than one byte but that assumption may not be correct.
Note, in each case after the is I2CMasterControl() done, I poll the busy and also check for errors using the following:
i2ctmo = 0;
while(I2CMasterBusy(I2C0_BASE))
{
i2ctmo++;
if(i2ctmo > I2CTIMEOUT)
{
return 1;
}
}
errorStatus = I2CMasterErr(I2C0_BASE);
if (errorStatus != I2C_MASTER_ERR_NONE)
{
return 1;
}
//now read the data
dataRead = (unsigned char) ROM_I2CMasterDataGet( I2C0_BASE );