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.

MSP430F5659: I2C Master reads one byte more than needed

Part Number: MSP430F5659

Hi,

I'm using the MSP430F5659 as an I2C master and I'm currently trying to perform a clean read command via I2C interrupts. The slave sends the data as expected, but the master seems to ACK the last needed byte instead of sending a NACK/STOP, so the slave sends another byte (one more than needed), and only then does the MSP sends the NACK/STOP.

Here is a sample of my code done in the interrupt:

switch (__even_in_range(UCB2IV, USCI_I2C_UCTXIFG))

/* ... Some other code ... */

  case USCI_I2C_UCRXIFG: // Data received

    count++;

    if (count == nBytesToRead) // No more actions required for this transaction
    {
      //Send stop condition.
      UCB2CTL1 |= UCTXSTP;
    }

    // Here, we read the UCBxRXBUF after the stop is sent and count is incremented so that the stop is generated immediately
    buf[count-1] = UCB2RXBUF; // Get data from buffer


    break;

/* ... Some other code ... */

}

 

The I2C datasheet (slau412e) states that "Setting the UCTXSTP bit generates a STOP condition. After setting UCTXSTP, a NACK followed by a STOP condition is generated after reception of the data from the slave, or immediately if the USCI module is currently waiting for UCBxRXBUF to be read."

I am trying to achieve the second part of the sentence, i.e. reading UCBxRXBUF after sending a STOP so the STOP is immediate. What I get instead is the first part of that sentence, i.e. the STOP is only sent after the next byte is received.

So, to recap: I intend to receive 2 bytes by I2C master interrupt, but I receive 3 instead.

Any idea as to why this is happening?

Thank you,

Fred

  • Hi,

    When receiving bytes in I2C master mode on an MSP430, the master needs to set the UCTXSTP bit at the N-1 byte received. For example, when trying to receive two bytes, the UCTXSTP but should be set when the first byte is received. If the master is trying to receive one byte, the master needs to send the start condition, wait for it to be sent, then set the UCTXSTP bit.

    Finally, please take a look at the I2C section of Solutions to Common eUSCI and USCI Serial Communication Issues on MSP430 MCUs. This details many of the common issues experienced when developing serial communication including the issue you describe here.

    Best regards, 

    Caleb Overbay

  • Hi Caleb,

    Thank you for your answer. However, I tried it and the master now does not seem to send a proper stop, or it's really delayed. Here are 2 figures to explain what I mean:

    1- Setting UCTXSTP after receiving the second byte

    2- Setting UCTXSTP before receiving the second byte

    As you see on the first figure, the STOP is immediately sent after receiving the third byte. However, on the second figure, the second byte is acknowledged instead of NACK + STOP, and then the lines are held LOW. Also, the time that the lines are held LOW seem to be the time at which the third byte would be received (see figure 1). Any ideas as to why this is happening?

    Thank you,

    Fred

  • Hi Caleb,

    Please disregard my last message, it was a coding error on my part. It's now working as intended, thank you!

**Attention** This is a public forum