This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430F5529: Problem with I2C interface between MSP430F5529 and MPU9150

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);
}

  • Hello,

    is this issue only with the MPU9150 and can you access the other sensors with out issues.
    You marked two lines: does this mean that the code hangs sometimes at the first and sometimes at the second location?
    Does this always happen or just on a random basis?

    Regards,
    Stefan
  • Hi Stefan,

    Thanks for your reply.

    First of all, yes, I think this problem is only related to MPU9150, because it works well when I only collect PPG signals. Moreover, according to the file provided by TI, AFE4403 communicates with the PC through SPI interface.

    Second, yes, for the marked two lines, the code hangs sometimes at the first and sometimes at the second location. This issue always happens. I want to continuously measure PPG and motion data for at least 5 minutes. But the issue always happens, so that I cannot collect data for more than 1min.

    My code mainly refers to two files, 'slaa671a' (msp430_wristwatch_project) and 'CES_HRMWatch_PC_EVM_GUI_v2.0-CCS'.

    Sincerely,

    Xiaoshi

  • Hi Xiaoshi,

    for you description i assume are reading data from both sensors when you see the issue.
    Can you reduce your code so that you only read data from the MPU9150 and do not access any other senor via I2C.

    It might be that you access the I2C interface from two different functions at the same time (esp. when working with interrupts).
    So that you start communication from one function and during that access the interface from another functions.

    May you can check your code for that.

    May you can also check the state of the I2C lines are both high during idle mode?

    Regards,
    Stefan
  • Hi Stefan,

    I tried to reduce the code to just read data from MPU9150. But this issue still happens.

    For the state of the I2C lines, I cannot check it because I have no logic analyzer. I'm a beginner in I2C, so I don't know if there's any other way to check it.

    Thank you very much!

    Sincerely,

    Xiaoshi

  • Hi Xiaoshi,

    went through the communication again and there is one more thing where i am not sure if understood or assumed right.
    Is the MPU9150 failing from time to time or does it not at all respond to any I2C message?
    Do you have any other measurement tools available. Oscilloscope would be great or et least measure the voltage level on SDA and SCL before the communication and the in the failing case.

    Regards,
    Stefan
  • Hi Xiaoshi,

    could you solve the issue or do you have further questions regarding this topic?
    If solved, please select "Resolved" for the post that solved your issue so this thread can be closed out. If you have a different question, please select "Ask a related question" or " Ask a new question".
    Thanks a lot!

    Best regards,
    Stefan

**Attention** This is a public forum