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.

TMS570LC4357: I2C wait for ACK/NACK

Part Number: TMS570LC4357

Hi,

I'm having issues with waiting for ACK/NACK flag in I2CSTR register and by that i mean how do i know the flag status is up-to date(It corresponds to latest operation)? What i'm currently doing is that i'm pushing data into I2CDXR register and i would like to wait and see if the slave did respond with ACK or not - how do i know when to read the register - I cannot read it immediately because it won't be set yet.

Pseudo not working code:

Fullscreen
1
2
3
4
5
6
7
HWREG_WRITE_32(pI2C->DXR, byte);
// Note that this will never evaluate to True....
if (0U != (HWREG_READ_32(pI2C->STR) & (1U << I2C_STR_NACK_POS)))
{
// Nack received
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Psuedo working code:

Fullscreen
1
2
3
4
5
6
7
8
HWREG_WRITE_32(pI2C->DXR, byte);
Delay(100);
if (0U != (HWREG_READ_32(pI2C->STR) & (1U << I2C_STR_NACK_POS)))
{
//Nack received
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The delay method does work but it's far from ideal - any ideas how it can be improved?

Any ideas?

  • Hi,

    The I2C transmitter releases the SDA line (HIGH) during the acknowledge clock pulse. The receiver must pull down the SDA line during the acknowledge clock pulse so that it remains stable LOW during the HIGH period of this clock pulse. 

    I think the NACK bit is set when you start the transfer. Are there proper pull-up resistors on your I2C lines?