Autodrone
Multi-Domain Vehicle
mpu6000.h File Reference

This file contains all the functions to initalize and read data from the MPU-6000. More...

Go to the source code of this file.

Macros

#define MPU6000_PRODUCT_ID   0x68
 
#define MPU6000_SMPLRT_DIV   0x19
 
#define MPU6000_GYRO_CONFIG   0x1B
 
#define MPU6000_ACCEL_CONFIG   0x1C
 
#define MPU6000_FIFO_EN   0x23
 
#define MPU6000_INT_PIN_CFG   0x37
 
#define MPU6000_INT_ENABLE   0x38
 
#define MPU6000_INT_STATUS   0x3A
 
#define MPU6000_ACCEL_XOUT_H   0x3B
 
#define MPU6000_ACCEL_XOUT_L   0x3C
 
#define MPU6000_ACCEL_YOUT_H   0x3D
 
#define MPU6000_ACCEL_YOUT_L   0x3E
 
#define MPU6000_ACCEL_ZOUT_H   0x3F
 
#define MPU6000_ACCEL_ZOUT_L   0x40
 
#define MPU6000_TEMP_OUT_H   0x41
 
#define MPU6000_TEMP_OUT_L   0x42
 
#define MPU6000_GYRO_XOUT_H   0x43
 
#define MPU6000_GYRO_XOUT_L   0x44
 
#define MPU6000_GYRO_YOUT_H   0x45
 
#define MPU6000_GYRO_YOUT_L   0x46
 
#define MPU6000_GYRO_ZOUT_H   0x47
 
#define MPU6000_GYRO_ZOUT_L   0x48
 
#define MPU6000_SIGNAL_PATH_RESET   0x68
 
#define MPU6000_USER_CTRL   0x6A
 
#define MPU6000_PWR_MGMT_1   0x6B
 
#define MPU6000_PWR_MGMT_2   0x6C
 
#define MPU6000_FIFO_COUNTH   0x72
 
#define MPU6000_FIFO_COUNTL   0x73
 
#define MPU6000_FIFO_R_W   0x74
 
#define MPU6000_WHOAMI   0x75
 
#define BIT_SLEEP   0x40
 
#define BIT_H_RESET   0x80
 
#define BITS_CLKSEL   0x07
 
#define MPU_CLK_SEL_PLLGYROX   0x01
 
#define MPU_CLK_SEL_PLLGYROZ   0x03
 
#define MPU_EXT_SYNC_GYROX   0x02
 
#define BITS_FS_250DPS   0x00
 
#define BITS_FS_500DPS   0x08
 
#define BITS_FS_1000DPS   0x10
 
#define BITS_FS_2000DPS   0x18
 
#define BITS_FS_2G   0x00
 
#define BITS_FS_4G   0x08
 
#define BITS_FS_8G   0x10
 
#define BITS_FS_16G   0x18
 
#define BITS_FS_MASK   0x18
 
#define BITS_DLPF_CFG_20HZ   0x04
 
#define BITS_DLPF_CFG_10HZ   0x05
 
#define BITS_DLPF_CFG_5HZ   0x06
 
#define BITS_DLPF_CFG_2100HZ_NOLPF   0x07
 
#define BITS_DLPF_CFG_MASK   0x07
 
#define BIT_INT_ANYRD_2CLEAR   0x10
 
#define BIT_RAW_RDY_EN   0x01
 
#define BIT_I2C_IF_DIS   0x10
 
#define BIT_INT_STATUS_DATA   0x01
 
#define MPU6000_CONFIG   0x1A
 
#define BITS_DLPF_CFG_256HZ   0x00
 
#define BITS_DLPF_CFG_188HZ   0x01
 
#define BITS_DLPF_CFG_98HZ   0x02
 
#define BITS_DLPF_CFG_42HZ   0x03
 
#define DISABLE_MPU6000   GPIOA->BSRR |= GPIO_BSRR_BS4
 
#define ENABLE_MPU6000   GPIOA->BSRR |= GPIO_BSRR_BR4
 
#define GYRO_SCALE_FACTOR   0.000532632f
 
#define ACCEL_SCALE_FACTOR   0.004788403f
 

Functions

bool mpu6000Init (void)
 MPU-6000 initialization sequence. More...
 
void readMPU6000 (void)
 Reads MPU-6000 raw data and packs accel, gyro, temp data into variables. More...
 
void computeMPU6000RTData (void)
 Computes IMU runtime data to find gyro bias. More...
 
void computeMPU6000TCBias (void)
 Calculates the IMU temperature bias. More...
 

Variables

uint8_t rawData [16]
 
float accelOneG
 
float accelTCBias [3]
 
int32_t accelSum100Hz [3]
 
int32_t accelSum500Hz [3]
 
int32_t accelSummedSamples100Hz [3]
 
int32_t accelSummedSamples500Hz [3]
 
int16andUint8_t rawAccel [3]
 
float nonRotatedAccelData [3]
 
float gyroRTBias [3]
 
float gyroTCBias [3]
 
int32_t gyroSum500Hz [3]
 
int32_t gyroSummedSamples500Hz [3]
 
int16andUint8_t rawGyro [3]
 
float nonRotatedGyroData [3]
 
uint8_t accelCalibrating
 
uint8_t mpu6000Calibrating
 
float mpu6000Temperature
 
int16andUint8_t rawMPU6000Temperature
 

Detailed Description

This file contains all the functions to initalize and read data from the MPU-6000.

Author
Jeremy Wolfe
Date
06 MAR 2022

Macro Definition Documentation

◆ ACCEL_SCALE_FACTOR

#define ACCEL_SCALE_FACTOR   0.004788403f

◆ BIT_H_RESET

#define BIT_H_RESET   0x80

◆ BIT_I2C_IF_DIS

#define BIT_I2C_IF_DIS   0x10

◆ BIT_INT_ANYRD_2CLEAR

#define BIT_INT_ANYRD_2CLEAR   0x10

◆ BIT_INT_STATUS_DATA

#define BIT_INT_STATUS_DATA   0x01

◆ BIT_RAW_RDY_EN

#define BIT_RAW_RDY_EN   0x01

◆ BIT_SLEEP

#define BIT_SLEEP   0x40

◆ BITS_CLKSEL

#define BITS_CLKSEL   0x07

◆ BITS_DLPF_CFG_10HZ

#define BITS_DLPF_CFG_10HZ   0x05

◆ BITS_DLPF_CFG_188HZ

#define BITS_DLPF_CFG_188HZ   0x01

◆ BITS_DLPF_CFG_20HZ

#define BITS_DLPF_CFG_20HZ   0x04

◆ BITS_DLPF_CFG_2100HZ_NOLPF

#define BITS_DLPF_CFG_2100HZ_NOLPF   0x07

◆ BITS_DLPF_CFG_256HZ

#define BITS_DLPF_CFG_256HZ   0x00

◆ BITS_DLPF_CFG_42HZ

#define BITS_DLPF_CFG_42HZ   0x03

◆ BITS_DLPF_CFG_5HZ

#define BITS_DLPF_CFG_5HZ   0x06

◆ BITS_DLPF_CFG_98HZ

#define BITS_DLPF_CFG_98HZ   0x02

◆ BITS_DLPF_CFG_MASK

#define BITS_DLPF_CFG_MASK   0x07

◆ BITS_FS_1000DPS

#define BITS_FS_1000DPS   0x10

◆ BITS_FS_16G

#define BITS_FS_16G   0x18

◆ BITS_FS_2000DPS

#define BITS_FS_2000DPS   0x18

◆ BITS_FS_250DPS

#define BITS_FS_250DPS   0x00

◆ BITS_FS_2G

#define BITS_FS_2G   0x00

◆ BITS_FS_4G

#define BITS_FS_4G   0x08

◆ BITS_FS_500DPS

#define BITS_FS_500DPS   0x08

◆ BITS_FS_8G

#define BITS_FS_8G   0x10

◆ BITS_FS_MASK

#define BITS_FS_MASK   0x18

◆ DISABLE_MPU6000

#define DISABLE_MPU6000   GPIOA->BSRR |= GPIO_BSRR_BS4

◆ ENABLE_MPU6000

#define ENABLE_MPU6000   GPIOA->BSRR |= GPIO_BSRR_BR4

◆ GYRO_SCALE_FACTOR

#define GYRO_SCALE_FACTOR   0.000532632f

◆ MPU6000_ACCEL_CONFIG

#define MPU6000_ACCEL_CONFIG   0x1C

◆ MPU6000_ACCEL_XOUT_H

#define MPU6000_ACCEL_XOUT_H   0x3B

◆ MPU6000_ACCEL_XOUT_L

#define MPU6000_ACCEL_XOUT_L   0x3C

◆ MPU6000_ACCEL_YOUT_H

#define MPU6000_ACCEL_YOUT_H   0x3D

◆ MPU6000_ACCEL_YOUT_L

#define MPU6000_ACCEL_YOUT_L   0x3E

◆ MPU6000_ACCEL_ZOUT_H

#define MPU6000_ACCEL_ZOUT_H   0x3F

◆ MPU6000_ACCEL_ZOUT_L

#define MPU6000_ACCEL_ZOUT_L   0x40

◆ MPU6000_CONFIG

#define MPU6000_CONFIG   0x1A

◆ MPU6000_FIFO_COUNTH

#define MPU6000_FIFO_COUNTH   0x72

◆ MPU6000_FIFO_COUNTL

#define MPU6000_FIFO_COUNTL   0x73

◆ MPU6000_FIFO_EN

#define MPU6000_FIFO_EN   0x23

◆ MPU6000_FIFO_R_W

#define MPU6000_FIFO_R_W   0x74

◆ MPU6000_GYRO_CONFIG

#define MPU6000_GYRO_CONFIG   0x1B

◆ MPU6000_GYRO_XOUT_H

#define MPU6000_GYRO_XOUT_H   0x43

◆ MPU6000_GYRO_XOUT_L

#define MPU6000_GYRO_XOUT_L   0x44

◆ MPU6000_GYRO_YOUT_H

#define MPU6000_GYRO_YOUT_H   0x45

◆ MPU6000_GYRO_YOUT_L

#define MPU6000_GYRO_YOUT_L   0x46

◆ MPU6000_GYRO_ZOUT_H

#define MPU6000_GYRO_ZOUT_H   0x47

◆ MPU6000_GYRO_ZOUT_L

#define MPU6000_GYRO_ZOUT_L   0x48

◆ MPU6000_INT_ENABLE

#define MPU6000_INT_ENABLE   0x38

◆ MPU6000_INT_PIN_CFG

#define MPU6000_INT_PIN_CFG   0x37

◆ MPU6000_INT_STATUS

#define MPU6000_INT_STATUS   0x3A

◆ MPU6000_PRODUCT_ID

#define MPU6000_PRODUCT_ID   0x68

◆ MPU6000_PWR_MGMT_1

#define MPU6000_PWR_MGMT_1   0x6B

◆ MPU6000_PWR_MGMT_2

#define MPU6000_PWR_MGMT_2   0x6C

◆ MPU6000_SIGNAL_PATH_RESET

#define MPU6000_SIGNAL_PATH_RESET   0x68

◆ MPU6000_SMPLRT_DIV

#define MPU6000_SMPLRT_DIV   0x19

◆ MPU6000_TEMP_OUT_H

#define MPU6000_TEMP_OUT_H   0x41

◆ MPU6000_TEMP_OUT_L

#define MPU6000_TEMP_OUT_L   0x42

◆ MPU6000_USER_CTRL

#define MPU6000_USER_CTRL   0x6A

◆ MPU6000_WHOAMI

#define MPU6000_WHOAMI   0x75

◆ MPU_CLK_SEL_PLLGYROX

#define MPU_CLK_SEL_PLLGYROX   0x01

◆ MPU_CLK_SEL_PLLGYROZ

#define MPU_CLK_SEL_PLLGYROZ   0x03

◆ MPU_EXT_SYNC_GYROX

#define MPU_EXT_SYNC_GYROX   0x02

Function Documentation

◆ computeMPU6000RTData()

void computeMPU6000RTData ( void  )

Computes IMU runtime data to find gyro bias.

Returns
Void.

◆ computeMPU6000TCBias()

void computeMPU6000TCBias ( void  )

Calculates the IMU temperature bias.

Returns
Void.

◆ mpu6000Init()

bool mpu6000Init ( void  )

MPU-6000 initialization sequence.

Returns
bool True if initialization was successful. False if unsuccessful.

◆ readMPU6000()

void readMPU6000 ( void  )

Reads MPU-6000 raw data and packs accel, gyro, temp data into variables.

Returns
Void.

Variable Documentation

◆ accelCalibrating

uint8_t accelCalibrating
extern

◆ accelOneG

float accelOneG
extern

◆ accelSum100Hz

int32_t accelSum100Hz[3]
extern

◆ accelSum500Hz

int32_t accelSum500Hz[3]
extern

◆ accelSummedSamples100Hz

int32_t accelSummedSamples100Hz[3]
extern

◆ accelSummedSamples500Hz

int32_t accelSummedSamples500Hz[3]
extern

◆ accelTCBias

float accelTCBias[3]
extern

◆ gyroRTBias

float gyroRTBias[3]
extern

◆ gyroSum500Hz

int32_t gyroSum500Hz[3]
extern

◆ gyroSummedSamples500Hz

int32_t gyroSummedSamples500Hz[3]
extern

◆ gyroTCBias

float gyroTCBias[3]
extern

◆ mpu6000Calibrating

uint8_t mpu6000Calibrating
extern

◆ mpu6000Temperature

float mpu6000Temperature
extern

◆ nonRotatedAccelData

float nonRotatedAccelData[3]
extern

◆ nonRotatedGyroData

float nonRotatedGyroData[3]
extern

◆ rawAccel

int16andUint8_t rawAccel[3]
extern

◆ rawData

uint8_t rawData[16]
extern

◆ rawGyro

int16andUint8_t rawGyro[3]
extern

◆ rawMPU6000Temperature

int16andUint8_t rawMPU6000Temperature
extern