Macros | Typedefs | Functions
SensorMpu9250.h File Reference

Detailed Description

Driver for the InvenSense MPU9250 Motion Processing Unit.

Driver include

This header file should be included in an application as follows:

#include "stdint.h"
#include "stdbool.h"

Go to the source code of this file.

Macros

#define ACC_RANGE_2G   0
 
#define ACC_RANGE_4G   1
 
#define ACC_RANGE_8G   2
 
#define ACC_RANGE_16G   3
 
#define ACC_RANGE_INVALID   0xFF
 
#define MPU_AX_GYR   0x07
 
#define MPU_AX_ACC   0x38
 
#define MPU_AX_MAG   0x40
 
#define MPU_AX_ALL   0x7F
 
#define MPU_DATA_READY   0x01
 
#define MPU_MOVEMENT   0x40
 
#define MAG_STATUS_OK   0x00
 
#define MAG_READ_ST_ERR   0x01
 
#define MAG_DATA_NOT_RDY   0x02
 
#define MAG_OVERFLOW   0x03
 
#define MAG_READ_DATA_ERR   0x04
 
#define MAG_BYPASS_FAIL   0x05
 
#define MAG_NO_POWER   0x06
 

Typedefs

typedef void(* SensorMpu9250CallbackFn_t) (void)
 

Functions

bool SensorMpu9250_init (void)
 This function initializes the MPU abstraction layer. More...
 
bool SensorMpu9250_reset (void)
 This function resets the MPU. More...
 
void SensorMpu9250_registerCallback (SensorMpu9250CallbackFn_t pCallback)
 Register an application defined call-back for interrupt processing. More...
 
bool SensorMpu9250_test (void)
 Run a self-test of the gyro/accelerometer component. More...
 
void SensorMpu9250_powerOn (void)
 Applies power to the MPU9250. More...
 
void SensorMpu9250_powerOff (void)
 Remove power to the MPU9250. More...
 
bool SensorMpu9250_powerIsOn (void)
 get the state of the power supply to the MPU9250 More...
 
void SensorMpu9250_enable (uint16_t config)
 Enable data collection. More...
 
bool SensorMpu9250_womEnable (uint8_t threshold)
 Enable Wake On Motion functionality. More...
 
uint8_t SensorMpu9250_irqStatus (void)
 Read interrupt status register. More...
 
bool SensorMpu9250_accSetRange (uint8_t range)
 Set the accelerometer range. More...
 
uint8_t SensorMpu9250_accReadRange (void)
 Read the accelerometer range. More...
 
bool SensorMpu9250_accRead (uint16_t *pData)
 Read data from the accelerometer. More...
 
float SensorMpu9250_accConvert (int16_t data)
 Convert raw data to G units. More...
 
bool SensorMpu9250_gyroRead (uint16_t *pData)
 Read data from the gyroscope. More...
 
float SensorMpu9250_gyroConvert (int16_t data)
 Convert raw data to deg/sec units. More...
 
bool SensorMpu9250_magTest (void)
 Run a magnetometer self test. More...
 
uint8_t SensorMpu9250_magRead (int16_t *pData)
 Read data from the compass - X, Y, Z - 3 words. More...
 
uint8_t SensorMpu9250_magStatus (void)
 Return the magnetometer status. More...
 
void SensorMpu9250_magReset (void)
 Reset the magnetometer. More...
 

Macro Definition Documentation

§ ACC_RANGE_2G

#define ACC_RANGE_2G   0

Accelerometer range +- 2G

§ ACC_RANGE_4G

#define ACC_RANGE_4G   1

Accelerometer range +- 4G

§ ACC_RANGE_8G

#define ACC_RANGE_8G   2

Accelerometer range +- 8G

§ ACC_RANGE_16G

#define ACC_RANGE_16G   3

Accelerometer range +- 16G

§ ACC_RANGE_INVALID

#define ACC_RANGE_INVALID   0xFF

Accelerometer range: not valid

§ MPU_AX_GYR

#define MPU_AX_GYR   0x07

Bitmap of gyro axes (X=0, Y=1, Z=2)

§ MPU_AX_ACC

#define MPU_AX_ACC   0x38

Bitmap of acc. axes (X=4, Y=8, Z=16)

§ MPU_AX_MAG

#define MPU_AX_MAG   0x40

Bitmap of all mag. axes (32)

§ MPU_AX_ALL

#define MPU_AX_ALL   0x7F

Bitmap of all MPU axes

§ MPU_DATA_READY

#define MPU_DATA_READY   0x01

Movement data ready

§ MPU_MOVEMENT

#define MPU_MOVEMENT   0x40

Movement detected (WOM mode)

§ MAG_STATUS_OK

#define MAG_STATUS_OK   0x00

Nor magnetometer error

§ MAG_READ_ST_ERR

#define MAG_READ_ST_ERR   0x01

Magnetometer error

§ MAG_DATA_NOT_RDY

#define MAG_DATA_NOT_RDY   0x02

Magnetometer data not ready

§ MAG_OVERFLOW

#define MAG_OVERFLOW   0x03

Magnetometer data overflow

§ MAG_READ_DATA_ERR

#define MAG_READ_DATA_ERR   0x04

Error when reading data

§ MAG_BYPASS_FAIL

#define MAG_BYPASS_FAIL   0x05

Magnetometer bypass enable failed

§ MAG_NO_POWER

#define MAG_NO_POWER   0x06

No magnetometer power

Typedef Documentation

§ SensorMpu9250CallbackFn_t

typedef void(* SensorMpu9250CallbackFn_t) (void)

Signature of callback function for handling of MPU interrupts

Function Documentation

§ SensorMpu9250_init()

bool SensorMpu9250_init ( void  )

This function initializes the MPU abstraction layer.

This function must be called before any access to the MMPU9250 can take place. It configures the IO lines connected to the, primarily the power signal. It also make sure that I2C lines are in a safe state also when power to the device is switched off.

Returns
true

§ SensorMpu9250_reset()

bool SensorMpu9250_reset ( void  )

This function resets the MPU.

Returns
true if success

§ SensorMpu9250_registerCallback()

void SensorMpu9250_registerCallback ( SensorMpu9250CallbackFn_t  pCallback)

Register an application defined call-back for interrupt processing.

Parameters
pCallback- the function to be called on interrupt

§ SensorMpu9250_test()

bool SensorMpu9250_test ( void  )

Run a self-test of the gyro/accelerometer component.

Returns
true if passed

§ SensorMpu9250_powerOn()

void SensorMpu9250_powerOn ( void  )

Applies power to the MPU9250.

§ SensorMpu9250_powerOff()

void SensorMpu9250_powerOff ( void  )

Remove power to the MPU9250.

§ SensorMpu9250_powerIsOn()

bool SensorMpu9250_powerIsOn ( void  )

get the state of the power supply to the MPU9250

Returns
true if the device is powered

§ SensorMpu9250_enable()

void SensorMpu9250_enable ( uint16_t  config)

Enable data collection.

Parameters
config- bitmap of axes to be enabled

Enable individual axes of the movement sensor:
Gyro bits [0..2], X = 1, Y = 2, Z = 4. 0 = gyro off
Acc bits [3..5], X = 8, Y = 16, Z = 32. 0 = accelerometer off
MPU bit [6], all axes

§ SensorMpu9250_womEnable()

bool SensorMpu9250_womEnable ( uint8_t  threshold)

Enable Wake On Motion functionality.

Parameters
threshold- wake-up trigger threshold (unit: 4 mg, max 1020mg)

In this mode the gyro is disabled and the accelerometer is running in low power mode. The wake-on-motion interrupt is enabled and the selected wake-up trigger threshold is applied.

Returns
true if success

§ SensorMpu9250_irqStatus()

uint8_t SensorMpu9250_irqStatus ( void  )

Read interrupt status register.

The interrupts used by the application are Data Ready(bit 0) and Movement Detected(bit 6).

Returns
Interrupt status

§ SensorMpu9250_accSetRange()

bool SensorMpu9250_accSetRange ( uint8_t  range)

Set the accelerometer range.

Parameters
rangeACC_RANGE_2G, ACC_RANGE_4G, ACC_RANGE_8G, ACC_RANGE_16G
Returns
true if write succeeded

§ SensorMpu9250_accReadRange()

uint8_t SensorMpu9250_accReadRange ( void  )

Read the accelerometer range.

Returns
range: ACC_RANGE_2G, ACC_RANGE_4G, ACC_RANGE_8G, ACC_RANGE_16G

§ SensorMpu9250_accRead()

bool SensorMpu9250_accRead ( uint16_t *  pData)

Read data from the accelerometer.

Read accelerometer data in the order z, y,z-axis (3 x 16 bits)

Parameters
pData- buffer for raw data from accelerometer
Returns
true if valid data

§ SensorMpu9250_accConvert()

float SensorMpu9250_accConvert ( int16_t  data)

Convert raw data to G units.

Parameters
data- raw data from sensor
Returns
Converted value

§ SensorMpu9250_gyroRead()

bool SensorMpu9250_gyroRead ( uint16_t *  pData)

Read data from the gyroscope.

Read gyroscope data in the order z, y,z-axis (3 x 16 bits)

Parameters
pData- buffer for raw data from gyroscope
Returns
true if valid data

§ SensorMpu9250_gyroConvert()

float SensorMpu9250_gyroConvert ( int16_t  data)

Convert raw data to deg/sec units.

Parameters
data- raw data from sensor
Returns
Converted value

§ SensorMpu9250_magTest()

bool SensorMpu9250_magTest ( void  )

Run a magnetometer self test.

Returns
true if passed

§ SensorMpu9250_magRead()

uint8_t SensorMpu9250_magRead ( int16_t *  pData)

Read data from the compass - X, Y, Z - 3 words.

Parameters
pData- buffer for raw data from magnetometer
Returns
Magnetometer status

§ SensorMpu9250_magStatus()

uint8_t SensorMpu9250_magStatus ( void  )

Return the magnetometer status.

Returns
magnetometer status

§ SensorMpu9250_magReset()

void SensorMpu9250_magReset ( void  )

Reset the magnetometer.

Copyright 2018, Texas Instruments Incorporated