Part Number: MSP430F5529
Other Parts Discussed in Thread: AFE4403EVM, AFE4403
Tool/software: Code Composer Studio
Hello,
I am using the AFE4403EVM watch kit to measure PPG, ACC and GYRO simultaneously. However, I met a problem in reading the data of MPU9150 through the I2C interface.
Below is the code I am using to read the motion data, which I copied directly from the file slaa671a. The yellow part is where the problem is, the program always pauses at these two lines of code (I2C lockup?).I can't get the data anymore.How can I solve this problem?
PS: After I get one data, it will be directly transmitted to the computer via USB.
int8_t HAL_I2C_read_only(uint16_t baseAddress, uint8_t slave_addr, uint8_t reg, uint8_t *data, uint8_t byteCount)
{
uint8_t comres = 0;
//WAIT FOR PREVIOUS TRAFFIC TO CLEAR
while(HWREG8(baseAddress + OFS_UCBxSTAT) & UCBBUSY);
// LOAD THE DEVICE SLAVE ADDRESS
HWREG16(baseAddress + OFS_UCBxI2CSA) = (slave_addr);
// TURN OFF TRANSMIT (ENABLE RECEIVE)
HWREG8(baseAddress + OFS_UCBxCTL1) &= ~UCTR;
// GENERATE START BIT
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTT;
// WAIT FOR START BIT TO COMPLETE
while(HWREG8(baseAddress + OFS_UCBxCTL1) & UCTXSTT);
// CHECK IF SLAVE ACK/NACK
if((HWREG8(baseAddress + OFS_UCBxIFG) & UCNACKIFG))
{
// IF NACK, SET STOP BIT AND EXIT
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
return(USCI_I2C_STATUS_SLAVE_NACK);
}
// NOW READ ONE OR MORE DATA BYTES
while(byteCount)
{
// IF READING 1 BYTE (OR LAST BYTE), GENERATE STOP BIT NOW TO MEET SPEC
if(byteCount-- == 1)
{
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
}
// WAIT FOR NEXT RX INT
while(!(HWREG8(baseAddress + OFS_UCBxIFG) & UCRXIFG));
// READ THE BYTE
*data++ = HWREG8(baseAddress + OFS_UCBxRXBUF);
}
return(comres);
}