Extremely slow response from MPU6050

Discussion in 'Embedded Systems and Microcontrollers' started by Shagas, Aug 2, 2015.

  1. Shagas

    Thread Starter Active Member

    May 13, 2013
    802
    74
    I'm using an STM32F4 discovery board to read values of an MPU6050 (inertial movement unit) using a library from
    a guy named Tilen Majerle. I've already got it up and running and it works almost fine except of one major issue. The first readAll() function
    takes a reasonable 0.4ms but every subsequent read takes about 200ms!! Does anyone have an idea why this might be?

    For those who have used the library (tm_stm32f4_mpu6050) , I'm using the function TM_MPU6050_ReadAll(&MPU6050_Data0);
    The implementation of the function is as follows:


    Code (C):
    1. TM_MPU6050_Result_t TM_MPU6050_ReadAll(TM_MPU6050_t* DataStruct) {
    2.     uint8_t data[14];
    3.     int16_t temp;
    4.  
    5.     /* Read full raw data, 14bytes */
    6.     TM_I2C_ReadMulti(MPU6050_I2C, DataStruct->Address, MPU6050_ACCEL_XOUT_H, data, 14);
    7.  
    8.     /* Format accelerometer data */
    9.     DataStruct->Accelerometer_X = (int16_t)(data[0] << 8 | data[1]);  
    10.     DataStruct->Accelerometer_Y = (int16_t)(data[2] << 8 | data[3]);
    11.     DataStruct->Accelerometer_Z = (int16_t)(data[4] << 8 | data[5]);
    12.  
    13.     /* Format temperature */
    14.     temp = (data[6] << 8 | data[7]);
    15.     DataStruct->Temperature = (float)((float)((int16_t)temp) / (float)340.0 + (float)36.53);
    16.  
    17.     /* Format gyroscope data */
    18.     DataStruct->Gyroscope_X = (int16_t)(data[8] << 8 | data[9]);
    19.     DataStruct->Gyroscope_Y = (int16_t)(data[10] << 8 | data[11]);
    20.     DataStruct->Gyroscope_Z = (int16_t)(data[12] << 8 | data[13]);
    21.  
    22.     /* Return OK */
    23.     return TM_MPU6050_Result_Ok;
    24. }
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Did you time the ReadMulti() function?

    Do you have the correct clock settings any another such parameters defined for that library?
     
  3. Shagas

    Thread Starter Active Member

    May 13, 2013
    802
    74
    I tried using his individual functions that read the Accelerometer, gyro and temperature separately and it works
    without issue at an update rate of 100Hz. It's strange that the readmulti is causing some sort of issue but I guess that I'm satisfied with the individual reads.
     
Loading...