8.1.1. MPU6050 (InvenSense) Introduction

The MPU-60X0 is a 6-axis MotionTracking device that combines a 3-axis gyroscope, 3-axis accelerometer, and a Digital Motion Processor (DMP) all in a small 4x4x0.9mm package. With its dedicated I2C sensor bus, it directly accepts inputs from an external 3-axis compass to provide a complete 9-axis MotionFusion output.

The MPU-60X0 features three 16-bit analog-to-digital converters (ADCs) for digitizing the gyroscope outputs and three 16-bit ADCs for digitizing the accelerometer outputs. For precision tracking of both fast and slow motions, the parts feature a user-programmable gyroscope full-scale range of ±250, ±500, ±1000, and ±2000°/sec (dps) and a user-programmable accelerometer full-scale range of ±2g, ±4g, ±8g, and ±16g. Applications

In smartphones, it finds use in applications such as gesture commands for applications and phone control, enhanced gaming, augmented reality, panoramic photo capture and viewing, and pedestrian and vehicle navigation. With its ability to precisely and accurately track user motions, MotionTracking technology can convert handsets and tablets into powerful 3D intelligent devices that can be used in applications ranging from health and fitness monitoring to location-based services.

Other applications include:

  • Motion-based game controllers
  • 3D remote controls for Internet connected DTVs and set top boxes, 3D mice
  • Wearable sensors for health, fitness and sports
  • Toys Resources Platform Integration

The sensor can be enabled by defining compile-time flag PLTFRM_MPU6050_SENSOR_ENA. Functions

PLTFRM_sts_t MPU6050_init(UINT8_t devId)

Initializes the device. If compile-time flag MPU6050_UT is defined, function performs a series of unit tests on the device.

  • devId – Identity of the device.

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Possible errors are PLTFRM_STS_INV_DEV_ID, PLTFRM_STS_DEV_MISSING, PLTFRM_STS_INV_PARAM and PLTFRM_STS_I2C_BUS_WR_ERROR.

PLTFRM_sts_t MPU6050_getTempData(UINT8_t devId, SINT32_t *tempData_p)

Get temperature from the device.

  • devId – Identity of the device.
  • tempData_p – Points to location where temperature value is returned. Unit of temperature is centi celsius.

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Possible errors are PLTFRM_STS_INV_DEV_ID and PLTFRM_STS_I2C_BUS_RD_ERROR.

PLTFRM_sts_t MPU6050_getAccelData(UINT8_t devId, axis_t axis, SINT16_t *accelData_p)

Get accelerometer reading from the sensor in the specified axis.

  • devId – Identity of the device.
  • axis – The axis in which the value is desired. This can be x, y or z axis.
  • accelData_p – Points to location where sensor data is returned. Value can be negative.

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. One possible error is PLTFRM_STS_I2C_BUS_RD_ERROR. Macros

 * I2C Address is 110100X where X determined by the logic on pin AD0.
#define MPU6050_I2C_ADDR_PREFIX  0x68    // 0 1101 00X  (7 bit address)

#define MPU6050_SELF_TEST_X_REG_ADDR   0xd
#define MPU6050_SELF_TEST_Y_REG_ADDR   0xe
#define MPU6050_SELF_TEST_Z_REG_ADDR   0xf
#define MPU6050_SELF_TEST_A_REG_ADDR   0x10

 * This register specifies the divider from the gyroscope output
 * rate used to generate the Sample Rate for the MPU-60X0. The
 * sensor register output, FIFO output, and DMP sampling are all
 * based on the Sample Rate.
 * Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)
#define MPU6050_SMPLRT_DIV_REG_ADDR    0x19

 * This register configures the external Frame Synchronization (FSYNC) pin
 * sampling and the Digital Low Pass Filter (DLPF) setting for both the
 * gyroscopes and accelerometers.
#define MPU6050_CONFIG_REG_ADDR         0x1a

 * This register is used to trigger accelerometer self test and configure
 * the accelerometer full scale range. This register also configures the
 * Digital High Pass Filter (DHPF).
#define MPU6050_ACCEL_CONFIG_REG_ADDR   0x1c

 * This register determines which sensor measurements are loaded into the
 * FIFO buffer.
#define MPU6050_FIFO_EN_REG_ADDR          0x23

#define MPU6050_I2C_MST_CTRL_REG_ADDR     0x24

#define MPU6050_I2C_PIN_CFG_REG_ADDR      0x37

#define MPU6050_I2C_ENABLE_REG_ADDR       0x38

#define MPU6050_I2C_INT_STATUS_REG_ADDR   0x39

 * Accelerometer Measurements (X, Y and Z)
 * These registers store the most recent accelerometer measurements.
 * Accelerometer measurements are written to these registers at the Sample Rate
 * as defined in Register 25.
#define MPU6050_ACCEL_XOUT_H_REG_ADDR     0x3b

#define MPU6050_ACCEL_XOUT_L_REG_ADDR     0x3c

#define MPU6050_ACCEL_YOUT_H_REG_ADDR     0x3d

#define MPU6050_ACCEL_YOUT_L_REG_ADDR     0x3e

#define MPU6050_ACCEL_ZOUT_H_REG_ADDR     0x3f

#define MPU6050_ACCEL_ZOUT_L_REG_ADDR     0x40

 * These registers store the most recent temperature sensor measurement.
 * Temperature measurements are written to these registers at the Sample Rate
 * as defined in Register 25.
#define MPU6050_TEMP_OUT_H_REG_ADDR       0x41

#define MPU6050_TEMP_OUT_L_REG_ADDR       0x42

#define MPU6050_USER_CTRL_REG_ADDR        0x6a

#define MPU6050_PWR_MGMT_1_REG_ADDR       0x6b

#define MPU6050_PWR_MGMT_2_REG_ADDR       0x6c

#define MPU6050_FIFO_COUNT_H_REG_ADDR     0x72

#define MPU6050_FIFO_COUNT_L_REG_ADDR     0x73

#define MPU6050_FIFO_R_W_REG_ADDR         0x74

 * This register is used to verify the identity of the device. The contents of
 * WHO_AM_I are the upper 6 bits of the MPU-60X0's 7-bit I2C address. The least
 * significant bit of the MPU-60X0's I2C address is determined by the value of
 * the AD0 pin. The value of the AD0 pin is not reflected in this register.
 * The default value of the register is 0x68. Bits 0 and 7 are reserved. (Hard
 * coded to 0)
#define MPU6050_WHO_AM_I_REG_ADDR         0x75
#define MPU6050_WHO_AM_I_REG_VAL          0x68

// Power Management 1 Register
#define MPU6050_PWR_MGMT_REG_1_SLEEP_BM     (BIT6)
#define MPU6050_PWR_MGMT_REG_1_CYCLE_BM     (BIT5)
#define MPU6050_PWR_MGMT_REG_1_TEMP_DIS_BM  (BIT3)
#define MPU6050_PWR_MGMT_REG_1_CLKSEL_BM    (BIT0 | BIT1 | BIT2)

// Acceleration config register
#define MPU6050_ACCEL_CFG_REG_AFS_SEL_BM   (BIT3 | BIT4)

#define MPU6050_ACCEL_ABS_FSR_2G    0x0   // +/- 2g
#define MPU6050_ACCEL_ABS_FSR_4G    0x1   // +/- 4g
#define MPU6050_ACCEL_ABS_FSR_8G    0x2   // +/- 8g
#define MPU6050_ACCEL_ABS_FSR_16G   0x3   // +/- 16g Type Definitions

typedef struct
   UINT8_t devId;
} MPU6050_cntxt_s;