MBot Software Library  v1.0
An API documentation to mbot_firmware repository
mpu_defs.h
1 /*
2 See MPU-9250 Register Map and Descriptions, Revision 4.0,
3 RM-MPU-9250A-00, Rev. 1.4, 9/9/2013 for registers not listed in
4 above document; the MPU9250 and MPU9150 are virtually
5 identical but the latter has a different register map
6 */
7 
8 #ifndef RC_MPU_DEFS
9 #define RC_MPU_DEFS
10 
11 
12 // internal DMP sample rate limits
13 #define DMP_MAX_RATE 200
14 #define DMP_MIN_RATE 4
15 #define IMU_POLL_TIMEOUT 300 // milliseconds
16 
17 
18 /******************************************************************
19 * register offsets
20 ******************************************************************/
21 #define SELF_TEST_X_GYRO 0x00
22 #define SELF_TEST_Y_GYRO 0x01
23 #define SELF_TEST_Z_GYRO 0x02
24 #define X_FINE_GAIN 0x03
25 #define Y_FINE_GAIN 0x04
26 #define Z_FINE_GAIN 0x05
27 #define SELF_TEST_X_ACCEL 0x0D
28 #define SELF_TEST_Y_ACCEL 0x0E
29 #define SELF_TEST_Z_ACCEL 0x0F
30 #define SELF_TEST_A 0x10
31 #define XG_OFFSET_H 0x13
32 #define XG_OFFSET_L 0x14
33 #define YG_OFFSET_H 0x15
34 #define YG_OFFSET_L 0x16
35 #define ZG_OFFSET_H 0x17
36 #define ZG_OFFSET_L 0x18
37 #define SMPLRT_DIV 0x19
38 #define CONFIG 0x1A
39 #define GYRO_CONFIG 0x1B
40 #define ACCEL_CONFIG 0x1C
41 #define ACCEL_CONFIG_2 0x1D
42 #define LP_ACCEL_ODR 0x1E
43 #define WOM_THR 0x1F
44 #define MOT_DUR 0x20
45 #define ZMOT_THR 0x21
46 #define ZRMOT_DUR 0x22
47 #define FIFO_EN 0x23
48 #define I2C_MST_CTRL 0x24
49 #define I2C_SLV0_ADDR 0x25
50 #define I2C_SLV0_REG 0x26
51 #define I2C_SLV0_CTRL 0x27
52 #define I2C_SLV1_ADDR 0x28
53 #define I2C_SLV1_REG 0x29
54 #define I2C_SLV1_CTRL 0x2A
55 #define I2C_SLV2_ADDR 0x2B
56 #define I2C_SLV2_REG 0x2C
57 #define I2C_SLV2_CTRL 0x2D
58 #define I2C_SLV3_ADDR 0x2E
59 #define I2C_SLV3_REG 0x2F
60 #define I2C_SLV3_CTRL 0x30
61 #define I2C_SLV4_ADDR 0x31
62 #define I2C_SLV4_REG 0x32
63 #define I2C_SLV4_DO 0x33
64 #define I2C_SLV4_CTRL 0x34
65 #define I2C_SLV4_DI 0x35
66 #define I2C_MST_STATUS 0x36
67 #define INT_PIN_CFG 0x37
68 #define INT_ENABLE 0x38
69 #define DMP_INT_STATUS 0x39
70 #define INT_STATUS 0x3A
71 #define ACCEL_XOUT_H 0x3B
72 #define ACCEL_XOUT_L 0x3C
73 #define ACCEL_YOUT_H 0x3D
74 #define ACCEL_YOUT_L 0x3E
75 #define ACCEL_ZOUT_H 0x3F
76 #define ACCEL_ZOUT_L 0x40
77 #define TEMP_OUT_H 0x41
78 #define TEMP_OUT_L 0x42
79 #define GYRO_XOUT_H 0x43
80 #define GYRO_XOUT_L 0x44
81 #define GYRO_YOUT_H 0x45
82 #define GYRO_YOUT_L 0x46
83 #define GYRO_ZOUT_H 0x47
84 #define GYRO_ZOUT_L 0x48
85 #define EXT_SENS_DATA_00 0x49
86 #define EXT_SENS_DATA_01 0x4A
87 #define EXT_SENS_DATA_02 0x4B
88 #define EXT_SENS_DATA_03 0x4C
89 #define EXT_SENS_DATA_04 0x4D
90 #define EXT_SENS_DATA_05 0x4E
91 #define EXT_SENS_DATA_06 0x4F
92 #define EXT_SENS_DATA_07 0x50
93 #define EXT_SENS_DATA_08 0x51
94 #define EXT_SENS_DATA_09 0x52
95 #define EXT_SENS_DATA_10 0x53
96 #define EXT_SENS_DATA_11 0x54
97 #define EXT_SENS_DATA_12 0x55
98 #define EXT_SENS_DATA_13 0x56
99 #define EXT_SENS_DATA_14 0x57
100 #define EXT_SENS_DATA_15 0x58
101 #define EXT_SENS_DATA_16 0x59
102 #define EXT_SENS_DATA_17 0x5A
103 #define EXT_SENS_DATA_18 0x5B
104 #define EXT_SENS_DATA_19 0x5C
105 #define EXT_SENS_DATA_20 0x5D
106 #define EXT_SENS_DATA_21 0x5E
107 #define EXT_SENS_DATA_22 0x5F
108 #define EXT_SENS_DATA_23 0x60
109 #define MOT_DETECT_STATUS 0x61
110 #define I2C_SLV0_DO 0x63
111 #define I2C_SLV1_DO 0x64
112 #define I2C_SLV2_DO 0x65
113 #define I2C_SLV3_DO 0x66
114 #define I2C_MST_DELAY_CTRL 0x67
115 #define SIGNAL_PATH_RESET 0x68
116 #define MOT_DETECT_CTRL 0x69
117 #define USER_CTRL 0x6A
118 #define PWR_MGMT_1 0x6B
119 #define PWR_MGMT_2 0x6C
120 #define DMP_BANK 0x6D
121 #define DMP_RW_PNT 0x6E
122 #define DMP_REG 0x6F
123 #define DMP_REG_1 0x70
124 #define DMP_REG_2 0x71
125 #define FIFO_COUNTH 0x72
126 #define FIFO_COUNTL 0x73
127 #define FIFO_R_W 0x74
128 #define WHO_AM_I_MPU9250 0x75 // Should return 0x71
129 #define XA_OFFSET_H 0x77
130 #define XA_OFFSET_L 0x78
131 #define YA_OFFSET_H 0x7A
132 #define YA_OFFSET_L 0x7B
133 #define ZA_OFFSET_H 0x7D
134 #define ZA_OFFSET_L 0x7E
135 
136 
137 
138 
139 /*******************************************************************
140 * CONFIG register bits
141 *******************************************************************/
142 #define FIFO_MODE_REPLACE_OLD 0
143 #define FIFO_MODE_KEEP_OLD 0x01<<6
144 #define EXT_SYNC_SET_DISABLE 0
145 
146 
147 /*******************************************************************
148 * GYRO_CONFIG register bits
149 *******************************************************************/
150 #define XGYRO_CTEN 0x01<<7
151 #define YGYRO_CTEN 0x01<<6
152 #define ZGYRO_CTEN 0x01<<5
153 #define GYRO_FSR_CFG_250 0x00<<3
154 #define GYRO_FSR_CFG_500 0x01<<3
155 #define GYRO_FSR_CFG_1000 0x02<<3
156 #define GYRO_FSR_CFG_2000 0x03<<3
157 #define FCHOICE_B_DLPF_EN 0x00
158 #define FCHOICE_B_DLPF_DISABLE 0x01
159 
160 /*******************************************************************
161 * ACCEL_CONFIG register bits
162 *******************************************************************/
163 #define AX_ST_EN 0x01<<7
164 #define AY_ST_EN 0x01<<6
165 #define AZ_ST_EN 0x01<<5
166 #define ACCEL_FSR_CFG_2G 0x00<<3
167 #define ACCEL_FSR_CFG_4G 0x01<<3
168 #define ACCEL_FSR_CFG_8G 0x02<<3
169 #define ACCEL_FSR_CFG_16G 0x03<<3
170 
171 /*******************************************************************
172 * ACCEL_CONFIG2 register bits
173 *******************************************************************/
174 #define ACCEL_FCHOICE_1KHZ 0x00<<3
175 #define ACCEL_FCHOICE_4KHZ 0x01<<3
176 
177 
178 /*******************************************************************
179 * INT_PIN_CFG
180 *******************************************************************/
181 #define ACTL_ACTIVE_LOW 0x01<<7
182 #define ACTL_ACTIVE_HIGH 0
183 #define INT_OPEN_DRAIN 0
184 #define INT_PUSH_PULL 0x00<<6
185 #define LATCH_INT_EN 0x01<<5
186 #define INT_ANYRD_CLEAR 0x01<<4
187 #define ACTL_FSYNC_ACTIVE_LOW 0x01<<3
188 #define ACTL_FSYNC_ACTIVE_HIGH 0x00<<3
189 #define FSYNC_INT_MODE_EN 0x01<<2
190 #define FSYNC_INT_MODE_DIS 0x00<<2
191 #define BYPASS_EN 0x01<<1
192 
193 
194 /*******************************************************************
195 *INT_ENABLE register settings
196 *******************************************************************/
197 #define WOM_EN 0x01<<6
198 #define WOM_DIS 0x00<<6
199 #define FIFO_OVERFLOW_EN 0x01<<4
200 #define FIFO_OVERFLOW_DIS 0x00<<4
201 #define FSYNC_INT_EN 0x01<<3
202 #define FSYNC_INT_DIS 0x00<<3
203 #define RAW_RDY_EN 0x01
204 #define RAW_RDY_DIS 0x00
205 
206 /*******************************************************************
207 * FIFO_EN register settings
208 *******************************************************************/
209 #define FIFO_TEMP_EN 0x01<<7
210 #define FIFO_GYRO_X_EN 0x01<<6
211 #define FIFO_GYRO_Y_EN 0x01<<5
212 #define FIFO_GYRO_Z_EN 0x01<<4
213 #define FIFO_ACCEL_EN 0x01<<3
214 #define FIFO_SLV2_EN 0x01<<2
215 #define FIFO_SLV1_EN 0x01<<1
216 #define FIFO_SLV0_EN 0x01
217 
218 
219 /*******************************************************************
220 * PWR_MGMT_1 register settings
221 *******************************************************************/
222 #define H_RESET 0x01<<7
223 #define MPU_SLEEP 0x01<<6
224 #define MPU_CYCLE 0x01<<5
225 
226 
227 /*******************************************************************
228 * temperature reading constants
229 *******************************************************************/
230 #define ROOM_TEMP_OFFSET 0x00
231 #define TEMP_SENSITIVITY 333.87 // degC/LSB
232 
233 
234 /*******************************************************************
235 * USER_CTRL settings bits
236 *******************************************************************/
237 #define FIFO_EN_BIT 0x01<<6
238 #define I2C_MST_EN 0x01<<5
239 #define I2C_IF_DIS 0x01<<4
240 #define FIFO_RST 0x01<<2
241 #define I2C_MST_RST 0x01<<1
242 #define SIG_COND_RST 0x01
243 
244 /******************************************************************
245 * Magnetometer Registers
246 ******************************************************************/
247 #define AK8963_ADDR 0x0C
248 #define WHO_AM_I_AK8963 0x00 // should return 0x48
249 #define INFO 0x01
250 #define AK8963_ST1 0x02 // data ready status
251 #define AK8963_XOUT_L 0x03 // data
252 #define AK8963_XOUT_H 0x04
253 #define AK8963_YOUT_L 0x05
254 #define AK8963_YOUT_H 0x06
255 #define AK8963_ZOUT_L 0x07
256 #define AK8963_ZOUT_H 0x08
257 #define AK8963_ST2 0x09
258 #define AK8963_CNTL 0x0A // main mode control register
259 #define AK8963_ASTC 0x0C // Self test control
260 #define AK8963_I2CDIS 0x0F // I2C disable
261 #define AK8963_ASAX 0x10 // x-axis sensitivity adjustment value
262 #define AK8963_ASAY 0x11 // y-axis sensitivity adjustment value
263 #define AK8963_ASAZ 0x12 // z-axis sensitivity adjustment value
264 
265 /******************************************************************
266 * Magnetometer AK8963_CNTL register Settings
267 ******************************************************************/
268 #define MAG_POWER_DN 0x00 // power down magnetometer
269 #define MAG_SINGLE_MES 0x01 // powers down after 1 measurement
270 #define MAG_CONT_MES_1 0x02 // 8hz continuous self-sampling
271 #define MAG_CONT_MES_2 0x06 // 100hz continuous self-sampling
272 #define MAG_EXT_TRIG 0x04 // external trigger mode
273 #define MAG_SELF_TEST 0x08 // self test mode
274 #define MAG_FUSE_ROM 0x0F // ROM read only mode
275 #define MSCALE_16 0x01<<4
276 #define MSCALE_14 0x00
277 
278 /******************************************************************
279 * Magnetometer AK8963_ST2 register definitions
280 ******************************************************************/
281 #define MAGNETOMETER_SATURATION 0x01<<3
282 
283 /******************************************************************
284 * Magnetometer AK8963_ST1 register definitions
285 ******************************************************************/
286 #define MAG_DATA_READY 0x01
287 
288 /******************************************************************
289 * Magnetometer sensitivity in micro Teslas to LSB
290 ******************************************************************/
291 #define MAG_RAW_TO_uT (4912.0/32760.0)
292 
293 
294 #define BIT_I2C_MST_VDDIO (0x80)
295 #define BIT_FIFO_EN (0x40)
296 #define BIT_DMP_EN (0x80)
297 #define BIT_FIFO_RST (0x04)
298 #define BIT_DMP_RST (0x08)
299 #define BIT_FIFO_OVERFLOW (0x10)
300 #define BIT_DATA_RDY_EN (0x01)
301 #define BIT_DMP_INT_EN (0x02)
302 #define BIT_MOT_INT_EN (0x40)
303 #define BITS_FSR (0x18)
304 #define BITS_LPF (0x07)
305 #define BITS_HPF (0x07)
306 #define BITS_CLK (0x07)
307 #define BIT_FIFO_SIZE_1024 (0x40)
308 #define BIT_FIFO_SIZE_2048 (0x80)
309 #define BIT_FIFO_SIZE_4096 (0xC0)
310 #define BIT_RESET (0x80)
311 #define BIT_SLEEP (0x40)
312 #define BIT_S0_DELAY_EN (0x01)
313 #define BIT_S2_DELAY_EN (0x04)
314 #define BITS_SLAVE_LENGTH (0x0F)
315 #define BIT_SLAVE_BYTE_SW (0x40)
316 #define BIT_SLAVE_GROUP (0x10)
317 #define BIT_SLAVE_EN (0x80)
318 #define BIT_I2C_READ (0x80)
319 #define BITS_I2C_MASTER_DLY (0x1F)
320 #define BIT_AUX_IF_EN (0x20)
321 #define BIT_ACTL (0x80)
322 #define BIT_LATCH_EN (0x20)
323 #define BIT_ANY_RD_CLR (0x10)
324 #define BIT_BYPASS_EN (0x02)
325 #define BITS_WOM_EN (0xC0)
326 #define BIT_LPA_CYCLE (0x20)
327 #define BIT_STBY_XA (0x20)
328 #define BIT_STBY_YA (0x10)
329 #define BIT_STBY_ZA (0x08)
330 #define BIT_STBY_XG (0x04)
331 #define BIT_STBY_YG (0x02)
332 #define BIT_STBY_ZG (0x01)
333 #define BIT_STBY_XYZA (BIT_STBY_XA | BIT_STBY_YA | BIT_STBY_ZA)
334 #define BIT_STBY_XYZG (BIT_STBY_XG | BIT_STBY_YG | BIT_STBY_ZG)
335 
336 //#define GYRO_SF (46850825LL * 200 / DMP_SAMPLE_RATE)
337 #define GYRO_SF (46850825LL)
338 
339 #define DMP_FEATURE_TAP (0x001)
340 #define DMP_FEATURE_ANDROID_ORIENT (0x002)
341 #define DMP_FEATURE_LP_QUAT (0x004)
342 #define DMP_FEATURE_PEDOMETER (0x008)
343 #define DMP_FEATURE_6X_LP_QUAT (0x010)
344 #define DMP_FEATURE_GYRO_CAL (0x020)
345 #define DMP_FEATURE_SEND_RAW_ACCEL (0x040)
346 #define DMP_FEATURE_SEND_RAW_GYRO (0x080)
347 #define DMP_FEATURE_SEND_CAL_GYRO (0x100)
348 #define DMP_FEATURE_SEND_ANY_GYRO (DMP_FEATURE_SEND_RAW_GYRO | \
349  DMP_FEATURE_SEND_CAL_GYRO)
350 
351 #define INT_SRC_TAP (0x01)
352 #define INT_SRC_ANDROID_ORIENT (0x08)
353 
354 #define TAP_X (0x01)
355 #define TAP_Y (0x02)
356 #define TAP_Z (0x04)
357 #define TAP_XYZ (0x07)
358 
359 #define TAP_X_UP (0x01)
360 #define TAP_X_DOWN (0x02)
361 #define TAP_Y_UP (0x03)
362 #define TAP_Y_DOWN (0x04)
363 #define TAP_Z_UP (0x05)
364 #define TAP_Z_DOWN (0x06)
365 
366 #define ANDROID_ORIENT_PORTRAIT (0x00)
367 #define ANDROID_ORIENT_LANDSCAPE (0x01)
368 #define ANDROID_ORIENT_REVERSE_PORTRAIT (0x02)
369 #define ANDROID_ORIENT_REVERSE_LANDSCAPE (0x03)
370 
371 #define INV_WXYZ_QUAT (0x100)
372 
373 
374 
375 #endif