mpu9150.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
24 #ifndef MPU9150_H
25 #define MPU9150_H
26 
27 #include "periph/i2c.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
37 #define MPU9150_MIN_SAMPLE_RATE (4)
38 #define MPU9150_MAX_SAMPLE_RATE (1000)
39 #define MPU9150_DEFAULT_SAMPLE_RATE (50)
40 #define MPU9150_MIN_COMP_SMPL_RATE (1)
41 #define MPU9150_MAX_COMP_SMPL_RATE (100)
42 
48 #define MPU9150_PWR_WAKEUP (0x00)
49 #define MPU9150_PWR_PLL (0x01)
50 #define MPU9150_PWR_RESET (0x80)
51 
57 #define MPU9150_PWR_GYRO (0x07)
58 #define MPU9150_PWR_ACCEL (0x38)
59 
65 #define MPU9150_COMP_MODE_SLEEP_US (1000)
66 #define MPU9150_BYPASS_SLEEP_US (3000)
67 #define MPU9150_PWR_CHANGE_SLEEP_US (50000)
68 #define MPU9150_RESET_SLEEP_US (100000)
69 
75 #define MPU9150_COMP_POWER_DOWN (0x00)
76 #define MPU9150_COMP_SINGLE_MEASURE (0x01)
77 #define MPU9150_COMP_SELF_TEST (0x08)
78 #define MPU9150_COMP_FUSE_ROM (0x0F)
79 #define MPU9150_COMP_WHOAMI_ANSWER (0x48)
80 
85 typedef enum {
86  MPU9150_SENSOR_PWR_OFF = 0x00,
87  MPU9150_SENSOR_PWR_ON = 0x01,
89 
93 typedef enum {
94  MPU9150_HW_ADDR_HEX_68 = 0x68,
95  MPU9150_HW_ADDR_HEX_69 = 0x69,
97 
101 typedef enum {
102  MPU9150_COMP_ADDR_HEX_0C = 0x0C,
103  MPU9150_COMP_ADDR_HEX_0D = 0x0D,
104  MPU9150_COMP_ADDR_HEX_0E = 0x0E,
105  MPU9150_COMP_ADDR_HEX_0F = 0x0F,
107 
111 typedef enum {
112  MPU9150_GYRO_FSR_250DPS = 0x00,
113  MPU9150_GYRO_FSR_500DPS = 0x01,
114  MPU9150_GYRO_FSR_1000DPS = 0x02,
115  MPU9150_GYRO_FSR_2000DPS = 0x03,
117 
121 typedef enum {
122  MPU9150_ACCEL_FSR_2G = 0x00,
123  MPU9150_ACCEL_FSR_4G = 0x01,
124  MPU9150_ACCEL_FSR_8G = 0x02,
125  MPU9150_ACCEL_FSR_16G = 0x03,
127 
131 typedef enum {
132  MPU9150_FILTER_188HZ = 0x01,
133  MPU9150_FILTER_98HZ = 0x02,
134  MPU9150_FILTER_42HZ = 0x03,
135  MPU9150_FILTER_20HZ = 0x04,
136  MPU9150_FILTER_10HZ = 0x05,
137  MPU9150_FILTER_5HZ = 0x06,
138 } mpu9150_lpf_t;
139 
143 typedef struct {
144  int16_t x_axis;
145  int16_t y_axis;
146  int16_t z_axis;
148 
152 typedef struct {
158  uint16_t sample_rate;
160  uint8_t compass_x_adj;
161  uint8_t compass_y_adj;
162  uint8_t compass_z_adj;
164 
168 typedef struct {
170  uint8_t addr;
171  uint8_t comp_addr;
172  uint16_t sample_rate;
174 
178 typedef struct {
181 } mpu9150_t;
182 
192 int mpu9150_init(mpu9150_t *dev, const mpu9150_params_t *params);
193 
204 
215 
226 
240 int mpu9150_read_gyro(const mpu9150_t *dev, mpu9150_results_t *output);
241 
255 int mpu9150_read_accel(const mpu9150_t *dev, mpu9150_results_t *output);
256 
269 int mpu9150_read_compass(const mpu9150_t *dev, mpu9150_results_t *output);
270 
284 int mpu9150_read_temperature(const mpu9150_t *dev, int32_t *output);
285 
297 
309 
324 int mpu9150_set_sample_rate(mpu9150_t *dev, uint16_t rate);
325 
341 int mpu9150_set_compass_sample_rate(mpu9150_t *dev, uint8_t rate);
342 
343 #ifdef __cplusplus
344 }
345 #endif
346 
347 #endif /* MPU9150_H */
348 
int mpu9150_set_accel_fsr(mpu9150_t *dev, mpu9150_accel_ranges_t fsr)
Set the full-scale range for raw accelerometer data.
mpu9150_pwr_t gyro_pwr
Gyro power status (on/off)
Definition: mpu9150.h:154
int16_t x_axis
X-Axis measurement result.
Definition: mpu9150.h:144
uint8_t compass_z_adj
Compass Z-Axis sensitivity adjustment value.
Definition: mpu9150.h:162
uint16_t sample_rate
Sample rate.
Definition: mpu9150.h:172
mpu9150_gyro_ranges_t gyro_fsr
Configured gyro full-scale range.
Definition: mpu9150.h:156
uint16_t sample_rate
Configured sample rate for accel and gyro.
Definition: mpu9150.h:158
mpu9150_hw_addr_t
Possible MPU-9150 hardware addresses (wiring specific)
Definition: mpu9150.h:93
int16_t y_axis
Y-Axis measurement result.
Definition: mpu9150.h:145
uint8_t comp_addr
Address of the MPU-9150s compass.
Definition: mpu9150.h:171
uint8_t compass_sample_rate
Configured compass sample rate.
Definition: mpu9150.h:159
i2c_t i2c
I2C device which is used.
Definition: mpu9150.h:169
int mpu9150_set_accel_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
Enable or disable accelerometer power.
int mpu9150_set_compass_sample_rate(mpu9150_t *dev, uint8_t rate)
Set the rate at which the compass data is sampled.
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:157
uint8_t addr
Hardware address of the MPU-9150.
Definition: mpu9150.h:170
mpu9150_gyro_ranges_t
Possible full scale ranges for the gyroscope.
Definition: mpu9150.h:111
mpu9150_params_t params
Device initialization parameters.
Definition: mpu9150.h:179
mpu9150_pwr_t
Power enum values.
Definition: mpu9150.h:85
Configuration struct for the MPU-9150 sensor.
Definition: mpu9150.h:152
Device descriptor for the MPU-9150 sensor.
Definition: mpu9150.h:178
int mpu9150_read_temperature(const mpu9150_t *dev, int32_t *output)
Read temperature value from the given MPU9150 device, returned in m°C.
int mpu9150_read_compass(const mpu9150_t *dev, mpu9150_results_t *output)
Read magnetic field values from the given MPU9150 device, returned in mikroT.
mpu9150_pwr_t compass_pwr
Compass power status (on/off)
Definition: mpu9150.h:155
MPU-9150 result vector struct.
Definition: mpu9150.h:143
int mpu9150_set_compass_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
Enable or disable compass power.
int mpu9150_init(mpu9150_t *dev, const mpu9150_params_t *params)
Initialize the given MPU9150 device.
uint8_t compass_y_adj
Compass Y-Axis sensitivity adjustment value.
Definition: mpu9150.h:161
mpu9150_pwr_t accel_pwr
Accel power status (on/off)
Definition: mpu9150.h:153
int mpu9150_set_sample_rate(mpu9150_t *dev, uint16_t rate)
Set the rate at which the gyroscope and accelerometer data is sampled.
mpu9150_comp_addr_t
Possible compass addresses (wiring specific)
Definition: mpu9150.h:101
int mpu9150_set_gyro_power(mpu9150_t *dev, mpu9150_pwr_t pwr_conf)
Enable or disable gyroscope power.
mpu9150_accel_ranges_t
Possible full scale ranges for the accelerometer.
Definition: mpu9150.h:121
int mpu9150_read_accel(const mpu9150_t *dev, mpu9150_results_t *output)
Read acceleration values from the given MPU9150 device, returned in mG.
int mpu9150_set_gyro_fsr(mpu9150_t *dev, mpu9150_gyro_ranges_t fsr)
Set the full-scale range for raw gyroscope data.
int16_t z_axis
Z-Axis measurement result.
Definition: mpu9150.h:146
int mpu9150_read_gyro(const mpu9150_t *dev, mpu9150_results_t *output)
Read angular speed values from the given MPU9150 device, returned in dps.
mpu9150_status_t conf
Device configuration.
Definition: mpu9150.h:180
uint8_t compass_x_adj
Compass X-Axis sensitivity adjustment value.
Definition: mpu9150.h:160
Device initialization parameters.
Definition: mpu9150.h:168
mpu9150_lpf_t
Possible low pass filter values.
Definition: mpu9150.h:131
mpu9150_accel_ranges_t accel_fsr
Configured accel full-scale range.
Definition: mpu9150.h:157
Low-level I2C peripheral driver interface definition.