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 
21 #ifndef MPU9150_H
22 #define MPU9150_H
23 
24 #include "periph/i2c.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
34 #define MPU9150_MIN_SAMPLE_RATE (4)
35 #define MPU9150_MAX_SAMPLE_RATE (1000)
36 #define MPU9150_DEFAULT_SAMPLE_RATE (50)
37 #define MPU9150_MIN_COMP_SMPL_RATE (1)
38 #define MPU9150_MAX_COMP_SMPL_RATE (100)
39 
45 #define MPU9150_PWR_WAKEUP (0x00)
46 #define MPU9150_PWR_PLL (0x01)
47 #define MPU9150_PWR_RESET (0x80)
48 
54 #define MPU9150_PWR_GYRO (0x07)
55 #define MPU9150_PWR_ACCEL (0x38)
56 
62 #define MPU9150_COMP_MODE_SLEEP_US (1000)
63 #define MPU9150_BYPASS_SLEEP_US (3000)
64 #define MPU9150_PWR_CHANGE_SLEEP_US (50000)
65 #define MPU9150_RESET_SLEEP_US (100000)
66 
72 #define MPU9150_COMP_POWER_DOWN (0x00)
73 #define MPU9150_COMP_SINGLE_MEASURE (0x01)
74 #define MPU9150_COMP_SELF_TEST (0x08)
75 #define MPU9150_COMP_FUSE_ROM (0x0F)
76 #define MPU9150_COMP_WHOAMI_ANSWER (0x48)
77 
82 typedef enum {
83  MPU9150_SENSOR_PWR_OFF = 0x00,
84  MPU9150_SENSOR_PWR_ON = 0x01,
86 
90 typedef enum {
91  MPU9150_HW_ADDR_HEX_68 = 0x68,
92  MPU9150_HW_ADDR_HEX_69 = 0x69,
94 
98 typedef enum {
99  MPU9150_COMP_ADDR_HEX_0C = 0x0C,
100  MPU9150_COMP_ADDR_HEX_0D = 0x0D,
101  MPU9150_COMP_ADDR_HEX_0E = 0x0E,
102  MPU9150_COMP_ADDR_HEX_0F = 0x0F,
104 
108 typedef enum {
109  MPU9150_GYRO_FSR_250DPS = 0x00,
110  MPU9150_GYRO_FSR_500DPS = 0x01,
111  MPU9150_GYRO_FSR_1000DPS = 0x02,
112  MPU9150_GYRO_FSR_2000DPS = 0x03,
114 
118 typedef enum {
119  MPU9150_ACCEL_FSR_2G = 0x00,
120  MPU9150_ACCEL_FSR_4G = 0x01,
121  MPU9150_ACCEL_FSR_8G = 0x02,
122  MPU9150_ACCEL_FSR_16G = 0x03,
124 
128 typedef enum {
129  MPU9150_FILTER_188HZ = 0x01,
130  MPU9150_FILTER_98HZ = 0x02,
131  MPU9150_FILTER_42HZ = 0x03,
132  MPU9150_FILTER_20HZ = 0x04,
133  MPU9150_FILTER_10HZ = 0x05,
134  MPU9150_FILTER_5HZ = 0x06,
135 } mpu9150_lpf_t;
136 
140 typedef struct {
141  int16_t x_axis;
142  int16_t y_axis;
143  int16_t z_axis;
145 
149 typedef struct {
155  uint16_t sample_rate;
157  uint8_t compass_x_adj;
158  uint8_t compass_y_adj;
159  uint8_t compass_z_adj;
161 
165 typedef struct {
167  uint8_t addr;
168  uint8_t comp_addr;
169  uint16_t sample_rate;
171 
175 typedef struct {
178 } mpu9150_t;
179 
189 int mpu9150_init(mpu9150_t *dev, const mpu9150_params_t *params);
190 
201 
212 
223 
237 int mpu9150_read_gyro(const mpu9150_t *dev, mpu9150_results_t *output);
238 
252 int mpu9150_read_accel(const mpu9150_t *dev, mpu9150_results_t *output);
253 
266 int mpu9150_read_compass(const mpu9150_t *dev, mpu9150_results_t *output);
267 
281 int mpu9150_read_temperature(const mpu9150_t *dev, int32_t *output);
282 
294 
306 
321 int mpu9150_set_sample_rate(mpu9150_t *dev, uint16_t rate);
322 
338 int mpu9150_set_compass_sample_rate(mpu9150_t *dev, uint8_t rate);
339 
340 #ifdef __cplusplus
341 }
342 #endif
343 
344 #endif /* MPU9150_H */
345 
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:151
int16_t x_axis
X-Axis measurement result.
Definition: mpu9150.h:141
uint8_t compass_z_adj
Compass Z-Axis sensitivity adjustment value.
Definition: mpu9150.h:159
uint16_t sample_rate
Sample rate.
Definition: mpu9150.h:169
mpu9150_gyro_ranges_t gyro_fsr
Configured gyro full-scale range.
Definition: mpu9150.h:153
uint16_t sample_rate
Configured sample rate for accel and gyro.
Definition: mpu9150.h:155
mpu9150_hw_addr_t
Possible MPU-9150 hardware addresses (wiring specific)
Definition: mpu9150.h:90
int16_t y_axis
Y-Axis measurement result.
Definition: mpu9150.h:142
uint8_t comp_addr
Address of the MPU-9150s compass.
Definition: mpu9150.h:168
uint8_t compass_sample_rate
Configured compass sample rate.
Definition: mpu9150.h:156
i2c_t i2c
I2C device which is used.
Definition: mpu9150.h:166
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:108
uint8_t addr
Hardware address of the MPU-9150.
Definition: mpu9150.h:167
mpu9150_gyro_ranges_t
Possible full scale ranges for the gyroscope.
Definition: mpu9150.h:108
mpu9150_params_t params
Device initialization parameters.
Definition: mpu9150.h:176
mpu9150_pwr_t
Power enum values.
Definition: mpu9150.h:82
Configuration struct for the MPU-9150 sensor.
Definition: mpu9150.h:149
Device descriptor for the MPU-9150 sensor.
Definition: mpu9150.h:175
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:152
MPU-9150 result vector struct.
Definition: mpu9150.h:140
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:158
mpu9150_pwr_t accel_pwr
Accel power status (on/off)
Definition: mpu9150.h:150
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:98
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:118
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:143
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:177
uint8_t compass_x_adj
Compass X-Axis sensitivity adjustment value.
Definition: mpu9150.h:157
Device initialization parameters.
Definition: mpu9150.h:165
mpu9150_lpf_t
Possible low pass filter values.
Definition: mpu9150.h:128
mpu9150_accel_ranges_t accel_fsr
Configured accel full-scale range.
Definition: mpu9150.h:154
Low-level I2C peripheral driver interface definition.