Tool/software: Code Composer Studio
Good afternoon,
I'm using the I2C Bus of the Tiva to communicate with a bunch of different plug-in sensor modules on my board. It's working great. The problem I'm having is that on some occasions, one of the sensors could be missing (unplugged). When this happens, my code gets stuck in the I2C routine. Can anyone suggest a proper way to escape and return 0 or FF in this situation? I'd prefer to avoid using a timer. Is there a flag that I could check for to see that the slave didn't respond?
Thanks!
uint32_t I2C3Receive1(uint32_t slave_addr, uint8_t reg)
{
//specify that we are writing (a register address) to the
//slave device
I2CMasterSlaveAddrSet(I2C3_BASE, slave_addr, false);
//specify register to be read
I2CMasterDataPut(I2C3_BASE, reg);
//send control byte and register address byte to slave device
I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_START);
//wait for MCU to finish transaction
while(!I2CMasterBusy(I2C3_BASE));
while(I2CMasterBusy(I2C3_BASE));
//specify that we are going to read from slave device
I2CMasterSlaveAddrSet(I2C3_BASE, slave_addr, true);
//send control byte and read from the register we
//specified
I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
//wait for MCU to finish transaction
while(!I2CMasterBusy(I2C3_BASE));
while(I2CMasterBusy(I2C3_BASE));
//return data pulled from the specified register
return I2CMasterDataGet(I2C3_BASE);
}