Hello out there,
I'm using a TM4C1292NCPDT and I've got several problems with I2C.
First of all I realized the Busy-Flag in I2CMCS doesn't seem to be stable right after executing I2CMasterControl() function. I solved this problem by waiting a few clock cycles before waiting on the busy flag with I2CMasterBusy(). But maybe there is an other possibility. Has anyone had similar problems? How did you solve it?
The other issue I have is related to the error flags by reading the I2CMCS with I2CMasterErr(). The function always returns 0, although there was no address acknoledge. Am I doing something wrong?
The function I use for transmitting via I2C looks like this:
/**
****************************************************************************
*
\b Name: Bi_I2CTransmit
*
* \brief transmits a defined number of bytes via I2C instance and don't check for errors
*
* \param I2CName => typedef enum ::i2cID (see 'Bi_I2C.h')
* \param SlaveAddr => I2C address of desired slave device
* \param DataPtr => pointer to data to transmit
* \param NumBytes => number of bytes to transmit
*
* \return returns the number of transmitted bytes
*
* \remark
* - function used waits until data is transmitted
* - I2C errors are ignored
*
****************************************************************************/
U32 Bi_I2CTransmit(const i2cID I2CName, const U8 SlaveAddr, const U8 *DataPtr, const U32 NumBytes)
{
U32 I2CBase = I2CGetBase(I2CName);
U32 ErrState = 0;
U32 Bytes = 0;
if (I2CBase != 0)
{
// Wait for I2C controller to be idle
while ( I2CMasterBusy(I2CBase) );
// Prepare write to slave address
I2CMasterSlaveAddrSet(I2CBase, SlaveAddr, false);
// Whait until I2C bus is not busy
while ( I2CMasterBusBusy(I2CBase) );
while ( (Bytes < NumBytes)&&(ErrState==0) )
{
// Tranfer nex byte to I2C hardware and wait for idle state
I2CMasterDataPut(I2CBase, DataPtr[Bytes]);
while ( I2CMasterBusy(I2CBase) );
// Single byte send requested
if (NumBytes == 1)
{
// Initiate single send
I2CMasterControl(I2CBase, I2C_MASTER_CMD_SINGLE_SEND);
}
// First byte to transmit
else if ( Bytes == 0 )
{
// Initiate start
I2CMasterControl(I2CBase, I2C_MASTER_CMD_BURST_SEND_START);
}
// Last byte to transmit
else if ( Bytes == NumBytes-1 )
{
// Initiate stop
I2CMasterControl(I2CBase, I2C_MASTER_CMD_BURST_SEND_FINISH);
}
// All other bytes
else
{
I2CMasterControl(I2CBase, I2C_MASTER_CMD_BURST_SEND_CONT);
}
// Wait a few cycles then wait for I2C controller to be idle
for (U32 Wait=15; Wait>0; Wait--);
while ( I2CMasterBusy(I2CBase) );
// Check for I2C Errors
ErrState = I2CMasterErr(I2CBase);
if (ErrState == 0)
{
Bytes++;
}
}
}
return Bytes;
}


