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.
§ ACC_RANGE_2G
Accelerometer range +- 2G
§ ACC_RANGE_4G
Accelerometer range +- 4G
§ ACC_RANGE_8G
Accelerometer range +- 8G
§ ACC_RANGE_16G
Accelerometer range +- 16G
§ ACC_RANGE_INVALID
#define ACC_RANGE_INVALID 0xFF |
Accelerometer range: not valid
§ MPU_AX_GYR
Bitmap of gyro axes (X=0, Y=1, Z=2)
§ MPU_AX_ACC
Bitmap of acc. axes (X=4, Y=8, Z=16)
§ MPU_AX_MAG
Bitmap of all mag. axes (32)
§ MPU_AX_ALL
§ MPU_DATA_READY
#define MPU_DATA_READY 0x01 |
§ MPU_MOVEMENT
#define MPU_MOVEMENT 0x40 |
Movement detected (WOM mode)
§ MAG_STATUS_OK
#define MAG_STATUS_OK 0x00 |
§ MAG_READ_ST_ERR
#define MAG_READ_ST_ERR 0x01 |
§ 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 |
§ MAG_BYPASS_FAIL
#define MAG_BYPASS_FAIL 0x05 |
Magnetometer bypass enable failed
§ MAG_NO_POWER
#define MAG_NO_POWER 0x06 |
§ SensorMpu9250CallbackFn_t
typedef void(* SensorMpu9250CallbackFn_t) (void) |
Signature of callback function for handling of MPU interrupts
§ 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()
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
-
range | ACC_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 |
| ) |
|