Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 62309

Forum Post: How to interpret the code from "i2c_master_rw_repeated_start-master_code" example?

$
0
0
I'm having trouble interpreting the code from TI Resource Explorer - MSP Driver Library - MSP432P4xx - I2C - i2c_master_rw_repeated_start-master_code example project. Does anybody know how to explain the following code from the while loop: /* Send start and the first byte of the transmit buffer. We have to send * two bytes to clean out whatever is in the buffer from a previous * send */ MAP_I2C_masterSendMultiByteStart(EUSCI_B0_BASE, TXData[0]); MAP_I2C_masterSendMultiByteNext(EUSCI_B0_BASE, TXData[0]); I understand the comment, but why would the buffer be filled with something left from a previous transmission? Also, wouldn't two transmissions confuse the slave, as it would be expecting a different byte to receive? Again, the following code from the IRQ handler confuses me: /* Receives bytes into the receive buffer. If we have received all bytes, * send a STOP condition */ if (status & EUSCI_B_I2C_RECEIVE_INTERRUPT0) { if(xferIndex == NUM_OF_REC_BYTES - 2) { MAP_I2C_masterReceiveMultiByteStop(EUSCI_B0_BASE); RXData[xferIndex++] = MAP_I2C_masterReceiveMultiByteNext(EUSCI_B0_BASE); } else if(xferIndex == NUM_OF_REC_BYTES - 1) { RXData[xferIndex++] = MAP_I2C_masterReceiveMultiByteNext(EUSCI_B0_BASE); MAP_I2C_disableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_INTERRUPT0); MAP_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE); xferIndex = 0; stopSent = true; MAP_Interrupt_disableSleepOnIsrExit(); } else { RXData[xferIndex++] = MAP_I2C_masterReceiveMultiByteNext(EUSCI_B0_BASE); } } As I understand, I2C_masterReceiveMultiByteStop needs to be called before the next receive function is called (which receives the last byte). Why does the STOP is sent after receiving the penultimate byte, and not after receiving the last byte (in (xferIndex == NUM_OF_REC_BYTES - 1) branch)? Thank you, Cristian

Viewing all articles
Browse latest Browse all 62309

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>