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