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

Forum Post: RE: Please help in understanding an i2c program

$
0
0
Thanks Ryan and Su, that was really helpful. I noticed a small mistake which can be easily corrected. In fact, Su had already asked in the 3rd question [quote user="Su Jin"] Q. 3: done just a few lines early, why do it again? A waste or a must? /* Enabling transfer interrupt after stop has been sent */ MAP_I2C_enableInterrupt(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0); [/quote] After Ryan's answer I thought it shouldn't cause any problem if I simply delete one of these lines and I deleted the second one. What I saw was a correct reading in the first loop of the while(1) but after that all the readings were wrong. It took 30 minutes to find the problem (smaller the problem, harder to find). The problem is that the transmit interrupt isn't enabled again after the reading is done. The line enabling it comes after sending the first byte in the while loop. Therefore, it works when transmit interrupt is already enabled before going into the while loop but it does not work anymore as it is disabled later on. Either you should enable it again at the end of reading or you can simply change the position of the specific line as below. By doing so, in the beginning of the while loop it is going to be enabled before sending the TXData. while (1) { //Enable master Transmit interrupt MAP_I2C_enableInterrupt(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0); /* Making sure the last transaction has been completely sent out */ while (MAP_I2C_masterIsStopSent(EUSCI_B0_BASE) == EUSCI_B_I2C_SENDING_STOP); while (MAP_I2C_isBusBusy(EUSCI_B0_BASE) == EUSCI_B_I2C_BUS_BUSY); /* 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); MAP_I2C_masterSendMultiByteNext(EUSCI_B0_BASE, TXData); .... By the way, I have only one byte of TXData. That's why I changed the notation, it has nothing to do with the problem.

Viewing all articles
Browse latest Browse all 66738

Trending Articles



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