According to the data sheet:
"Transfer Complete Flag
Acknowledges a byte transfer; TCF is set on the completion of a byte transfer. This bit is valid only during
or immediately following a transfer to or from the I2C module. TCF is cleared by reading the I2C data
register in receive mode or by writing to the I2C data register in transmit mode.
0 Transfer in progress
1 Transfer complete"
After I have written to the buffer, the TCF should be set to zero. But that's not the case, the TCF has always been set to one.
My code is here which is not working:
bool I2C_SendByte(uint8_t data)
{
I2C0->D = (uint8_t)data; //Write Byte to the Buffer
while(!(I2C0->S & I2C_S_TCF_MASK)); //Waiting until the TCF Bit is set.
if(I2C0->S & I2C_S_RXAK_MASK) return 1; //acknowledge signal detected
else return 0; //No acknowledge signal detected
}
but if write it like this, it works!
bool I2C_SendByte(uint8_t data)
{
I2C0->D = (uint8_t)data; ///Write Byte to the Buffer
while(!(I2C0->S & I2C_S_IICIF_MASK)); //Waiting until the TCF Bit is set.
I2C0->S |= I2C_S_IICIF_MASK; //Clear the bit by writing to 1
if(I2C0->S & I2C_S_RXAK_MASK) return 1; //acknowledge signal detected
else return 0; //No acknowledge signal detected
}
Could someone help me please why the TCF Bit doesn't work properly?