Part Number: MSP430F5529
Other Parts Discussed in Thread: MSP430WARE
Tool/software: Code Composer Studio
Hi
I use a function from this library to recieve bytes from a slave device.
Here is the original code:
uint8_t USCI_B_I2C_masterReceiveMultiByteFinish (uint16_t baseAddress)
{
uint8_t receiveData;
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
//Capture data from receive buffer after setting stop bit due to
//MSP430 I2C critical timing.
receiveData = HWREG8(baseAddress + OFS_UCBxRXBUF);
//Wait for Stop to finish
while (HWREG8(baseAddress + OFS_UCBxCTL1) & UCTXSTP);
//Wait for RX buffer
while (!(HWREG8(baseAddress + OFS_UCBxIFG) & UCRXIFG));
return receiveData;
}
This code didn't work for my device. However, when I move the data recieve line to the bottom of the code it worked. Am I doing something wrong or is this a bug. My understading is that the processor should recieve the RXIFG interrupt before reading the data not after.
Here is how I modified the code:
uint8_t USCI_B_I2C_masterReceiveMultiByteFinish (uint16_t baseAddress)
{
uint8_t receiveData;
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
//Wait for Stop to finish
while (HWREG8(baseAddress + OFS_UCBxCTL1) & UCTXSTP);
//Wait for RX buffer
while (!(HWREG8(baseAddress + OFS_UCBxIFG) & UCRXIFG));
//Capture data from receive buffer after setting stop bit due to
//MSP430 I2C critical timing.
receiveData = HWREG8(baseAddress + OFS_UCBxRXBUF);
return receiveData;
}