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.

I2C first read empty RX buffer

Other Parts Discussed in Thread: MSP430F5529, MSP430G2553

Hello!

Sorry for my English.

I'm try to build I2C master on MSP430F5529, and slave is MSP430G2553

When I debug this step-by-step, transmit is working ok, but "getData = UCB1RXBUF << 8;" returns previously sended data. UCB1RXBUF register value changes only after this string - "while (!(UCB1IFG & UCRXIFG)) { if (isNack) { break; } };"

BUT! Logic anylizer show that all data is send from slave properly.

unsigned int I2CGetWord(unsigned int reg) {
	getData = 0;
	UCB1TXBUF = 0;
	while (UCB1CTL1 & UCTXSTT);
	UCB1CTL1 |= UCTR;
	UCB1CTL1 |= UCTXSTT;
	while (!(UCB1IFG & UCTXIFG)) { if (isNack) { break; } };
	UCB1TXBUF = reg;
	while (!(UCB1IFG & UCTXIFG)) { if (isNack) { break; } };
	UCB1IFG &= ~UCTXIFG;
	UCB1CTL1 &= ~UCTR;
	UCB1CTL1 |= UCTXSTT;
	while (UCB1CTL1 & UCTXSTT);
	//while (!(UCB1IFG & UCRXIFG)) { if (isNack) { break; } };
	getData = UCB1RXBUF << 8;
	while (!(UCB1IFG & UCRXIFG)) { if (isNack) { break; } };
	UCB1CTL1 |= UCTXSTP;
	getData = getData | UCB1RXBUF;
	while (UCB1CTL1 & UCTXSTP);
	while (!(UCB1IFG & UCRXIFG)) { if (isNack) { break; } };
	UCB1IFG &= ~UCRXIFG;
	return getData;

  • UCRXIFG is the bit that indicates that something has been received, so I see nothing wrong with this behaviour.
  • After allnight debug I see that second UCB1CTL1 |= UCTXSTT; do not set flag. UCSCLLOW and UCBBUSY are set, but UCTXSTT are not.
  • Hi,
    You are try to receive the data in i2c without stop the transmission. Please try to rewrite your code as per the i2c prtocol format.First complete the i2c transmission by make the stop bit as high. Then start receive operation.
  • Yes I try to use stop condition instead of repeated start - the result is the same. In i2c specification using start after start is possible and call "repeated start". But neither I send STOP than wait for stop condition than START, nor sending START does not loading rx buffer with the new data.
  • Put scope on your SCL and SDA lines and check whether you could able to send the data.

  • The first while should wait for UCTXSTP, to ensure that a previous operation is done before you start the next. (For a repeated start this is not required).
    The second while is superfluous: as soon as you set UCTR and UCTXSTT, UCTXIFG is instantly set. If you don't write to TXBUF or set UCTXSTP, the start byte ACK cycle won't complete and no NACK can occur too.
    On the third while, if a NACK occurs, the transfer has failed. So if you break off the while, you shouldn't continue.
    It's better to wait instead for UCTXSTT to clear, then check for UCNACKIFG and exit, if set.
    Don't manually clear UCTXIFG - it clears automatically if you start a read transfer.
    After the repeated start, when TXSTT clears, you may check for a NACK again. However, at this point, no data has been received yet, adn when you read RXBUF, it has not received any new data yet. YOu need to wait for UCRXIFG to be set before you read RXBUF. And you won't get a NACK during receiving, as it is the master who ACKs the received data. The slave has no way to stop the master from continue reading (other than just ignoring the clock until the master finally stops). There is no EOF on I2C.

**Attention** This is a public forum