Part Number:MSP430FR2433
I am using a MSP-EXP430FR2433 as a USB serial to I2C Master device.
Sometimes when I start, it hangs in the EUSCI_B_I2C_masterSendMultiByteStart() library function.
void EUSCI_B_I2C_masterSendMultiByteStart (uint16_t baseAddress, uint8_t txData ) { //Store current transmit interrupt enable uint16_t txieStatus = HWREG16(baseAddress + OFS_UCBxIE) & UCTXIE; //Disable transmit interrupt enable HWREG16(baseAddress + OFS_UCBxIE) &= ~(UCTXIE); //Send start condition. HWREG16(baseAddress + OFS_UCBxCTLW0) |= UCTR + UCTXSTT; //Poll for transmit interrupt flag. poll_loop = 0; masterSendMultiByteStart_fail = false; while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG)) { poll_loop++; if (poll_loop > poll_loop_longest) poll_loop_longest = poll_loop; if (poll_loop > POLL_LOOP_ABORT) { masterSendMultiByteStart_fail = true; break; } } //Send single byte data. HWREG16(baseAddress + OFS_UCBxTXBUF) = txData; //Reinstate transmit interrupt enable HWREG16(baseAddress + OFS_UCBxIE) |= txieStatus; }
the original while was
while (!(HWREG16(baseAddress + OFS_UCBxIFG) & UCTXIFG));
I added the counts to give me an idea how long it will hang. I gave up when the pool_loop number hit 4,000,000.
Sometimes this will run for hours without a problem.
However I took it apart put it back together and it hangs on that while. I have not completely figured out the pattern to get it working again but after fiddling with the reboot enough times on the slave, the master, and the serial program on a PC, it will start working.
I am beginning to think it is the slave not responding to the start and address with a ack.
How do I debug this?
Is there some sequence to put the I2C lines in a known state like if it was reset?
Unfortunately it was working at the office, when I went to the customer's 200 miles away, and tried to start it up it would not start. And I do not have all my tools here that I have at my office.
Any suggestions?
Kip