Part Number: MSP430FR5994
Other Parts Discussed in Thread: MSP430F5529,
Dear MSP430 community,
I've faced a singular issue the past days that i've never faced before. I usually compliment Texas Instruments for their documentation, either for its well organized datasheets or greatly detailed User's Guides. The past couple of weeks thought have been a nightmare because of (what I believe, and please, correct me if I'm wrong) an inaccurate description of eUSCI operation while in I2C mode. User's Guide (SLAU367O) states clearly on section 32.3.5.2.1, page 829 that when on Master-Transmitter mode,
If there is no data loaded to UCBxTXBUF before the acknowledge cycle, the bus is held during the acknowledge cycle with SCL low until data is written into UCBxTXBUF.
The figure 32-12 completes this information with a nice diagram showing SCL held if TXBUF is not written, and then STT bit is cleared as soon as a ACK or NACK is received. Despite that, in my tests, using a logic analyser, I've witnessed that the above statement is not true.
As soon as STT bit is set, eUSCI will send the 7-bit address, R/W bit, and the ACK/NACK cycle, and thus, making it hard to detect when to send a stop or the next byte of data. What would be a simple execution lock in C (after writing to TX buffer):
// Wait until ACK/NACK is received
while(UCB1CTLW0 & UCTXSTT);
if(UCB1IFG & UCNACKIFG) {
// Request stop
// ...
}
Should be now a wait for the next TX write cycle or a stop condition at the same time. Like this:
// Wait for next TX cycle or exit if there was a NACK
while( !(UCB1IFG & UCTXIFG) & !(UCB1IFG & UCNACKIFG) );
if (UCB1IFG & UCNACKIFG) {
// Send stop
// ...
}
I was struggling with this because I've trusted too much TI documentation, and thought that my code was incorrect, which usually is ;). I guess this time it was the other way around.
Hope this helps others MSP430FR59xx users out there.
Edit: Typo