1 // I2Cdev library collection - MPU6050 I2C device class
2 // Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
3 // 10/3/2011 by Jeff Rowberg <jeff@rowberg.net>
4 // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
7 // ... - ongoing debug release
9 // NOTE: THIS IS ONLY A PARIAL RELEASE. THIS DEVICE CLASS IS CURRENTLY UNDERGOING ACTIVE
10 // DEVELOPMENT AND IS STILL MISSING SOME IMPORTANT FEATURES. PLEASE KEEP THIS IN MIND IF
11 // YOU DECIDE TO USE THIS PARTICULAR CODE FOR ANYTHING.
13 /* ============================================
14 I2Cdev device library code is placed under the MIT license
15 Copyright (c) 2011 Jeff Rowberg
17 Permission is hereby granted, free of charge, to any person obtaining a copy
18 of this software and associated documentation files (the "Software"), to deal
19 in the Software without restriction, including without limitation the rights
20 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21 copies of the Software, and to permit persons to whom the Software is
22 furnished to do so, subject to the following conditions:
24 The above copyright notice and this permission notice shall be included in
25 all copies or substantial portions of the Software.
27 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34 ===============================================
41 #include <avr/pgmspace.h>
43 #define MPU6050_ADDRESS_AD0_LOW 0x68 // address pin low (GND), default for InvenSense evaluation board
44 #define MPU6050_ADDRESS_AD0_HIGH 0x69 // address pin high (VCC)
45 #define MPU6050_DEFAULT_ADDRESS MPU6050_ADDRESS_AD0_LOW
47 #define MPU6050_RA_XG_OFFS_TC 0x00 //[7] PWR_MODE, [6:1] XG_OFFS_TC, [0] OTP_BNK_VLD
48 #define MPU6050_RA_YG_OFFS_TC 0x01 //[7] PWR_MODE, [6:1] YG_OFFS_TC, [0] OTP_BNK_VLD
49 #define MPU6050_RA_ZG_OFFS_TC 0x02 //[7] PWR_MODE, [6:1] ZG_OFFS_TC, [0] OTP_BNK_VLD
50 #define MPU6050_RA_X_FINE_GAIN 0x03 //[7:0] X_FINE_GAIN
51 #define MPU6050_RA_Y_FINE_GAIN 0x04 //[7:0] Y_FINE_GAIN
52 #define MPU6050_RA_Z_FINE_GAIN 0x05 //[7:0] Z_FINE_GAIN
53 #define MPU6050_RA_XA_OFFS_H 0x06 //[15:0] XA_OFFS
54 #define MPU6050_RA_XA_OFFS_L_TC 0x07
55 #define MPU6050_RA_YA_OFFS_H 0x08 //[15:0] YA_OFFS
56 #define MPU6050_RA_YA_OFFS_L_TC 0x09
57 #define MPU6050_RA_ZA_OFFS_H 0x0A //[15:0] ZA_OFFS
58 #define MPU6050_RA_ZA_OFFS_L_TC 0x0B
59 #define MPU6050_RA_XG_OFFS_USRH 0x13 //[15:0] XG_OFFS_USR
60 #define MPU6050_RA_XG_OFFS_USRL 0x14
61 #define MPU6050_RA_YG_OFFS_USRH 0x15 //[15:0] YG_OFFS_USR
62 #define MPU6050_RA_YG_OFFS_USRL 0x16
63 #define MPU6050_RA_ZG_OFFS_USRH 0x17 //[15:0] ZG_OFFS_USR
64 #define MPU6050_RA_ZG_OFFS_USRL 0x18
65 #define MPU6050_RA_SMPLRT_DIV 0x19
66 #define MPU6050_RA_CONFIG 0x1A
67 #define MPU6050_RA_GYRO_CONFIG 0x1B
68 #define MPU6050_RA_ACCEL_CONFIG 0x1C
69 #define MPU6050_RA_FF_THR 0x1D
70 #define MPU6050_RA_FF_DUR 0x1E
71 #define MPU6050_RA_MOT_THR 0x1F
72 #define MPU6050_RA_MOT_DUR 0x20
73 #define MPU6050_RA_ZRMOT_THR 0x21
74 #define MPU6050_RA_ZRMOT_DUR 0x22
75 #define MPU6050_RA_FIFO_EN 0x23
76 #define MPU6050_RA_I2C_MST_CTRL 0x24
77 #define MPU6050_RA_I2C_SLV0_ADDR 0x25
78 #define MPU6050_RA_I2C_SLV0_REG 0x26
79 #define MPU6050_RA_I2C_SLV0_CTRL 0x27
80 #define MPU6050_RA_I2C_SLV1_ADDR 0x28
81 #define MPU6050_RA_I2C_SLV1_REG 0x29
82 #define MPU6050_RA_I2C_SLV1_CTRL 0x2A
83 #define MPU6050_RA_I2C_SLV2_ADDR 0x2B
84 #define MPU6050_RA_I2C_SLV2_REG 0x2C
85 #define MPU6050_RA_I2C_SLV2_CTRL 0x2D
86 #define MPU6050_RA_I2C_SLV3_ADDR 0x2E
87 #define MPU6050_RA_I2C_SLV3_REG 0x2F
88 #define MPU6050_RA_I2C_SLV3_CTRL 0x30
89 #define MPU6050_RA_I2C_SLV4_ADDR 0x31
90 #define MPU6050_RA_I2C_SLV4_REG 0x32
91 #define MPU6050_RA_I2C_SLV4_DO 0x33
92 #define MPU6050_RA_I2C_SLV4_CTRL 0x34
93 #define MPU6050_RA_I2C_SLV4_DI 0x35
94 #define MPU6050_RA_I2C_MST_STATUS 0x36
95 #define MPU6050_RA_INT_PIN_CFG 0x37
96 #define MPU6050_RA_INT_ENABLE 0x38
97 #define MPU6050_RA_DMP_INT_STATUS 0x39
98 #define MPU6050_RA_INT_STATUS 0x3A
99 #define MPU6050_RA_ACCEL_XOUT_H 0x3B
100 #define MPU6050_RA_ACCEL_XOUT_L 0x3C
101 #define MPU6050_RA_ACCEL_YOUT_H 0x3D
102 #define MPU6050_RA_ACCEL_YOUT_L 0x3E
103 #define MPU6050_RA_ACCEL_ZOUT_H 0x3F
104 #define MPU6050_RA_ACCEL_ZOUT_L 0x40
105 #define MPU6050_RA_TEMP_OUT_H 0x41
106 #define MPU6050_RA_TEMP_OUT_L 0x42
107 #define MPU6050_RA_GYRO_XOUT_H 0x43
108 #define MPU6050_RA_GYRO_XOUT_L 0x44
109 #define MPU6050_RA_GYRO_YOUT_H 0x45
110 #define MPU6050_RA_GYRO_YOUT_L 0x46
111 #define MPU6050_RA_GYRO_ZOUT_H 0x47
112 #define MPU6050_RA_GYRO_ZOUT_L 0x48
113 #define MPU6050_RA_EXT_SENS_DATA_00 0x49
114 #define MPU6050_RA_EXT_SENS_DATA_01 0x4A
115 #define MPU6050_RA_EXT_SENS_DATA_02 0x4B
116 #define MPU6050_RA_EXT_SENS_DATA_03 0x4C
117 #define MPU6050_RA_EXT_SENS_DATA_04 0x4D
118 #define MPU6050_RA_EXT_SENS_DATA_05 0x4E
119 #define MPU6050_RA_EXT_SENS_DATA_06 0x4F
120 #define MPU6050_RA_EXT_SENS_DATA_07 0x50
121 #define MPU6050_RA_EXT_SENS_DATA_08 0x51
122 #define MPU6050_RA_EXT_SENS_DATA_09 0x52
123 #define MPU6050_RA_EXT_SENS_DATA_10 0x53
124 #define MPU6050_RA_EXT_SENS_DATA_11 0x54
125 #define MPU6050_RA_EXT_SENS_DATA_12 0x55
126 #define MPU6050_RA_EXT_SENS_DATA_13 0x56
127 #define MPU6050_RA_EXT_SENS_DATA_14 0x57
128 #define MPU6050_RA_EXT_SENS_DATA_15 0x58
129 #define MPU6050_RA_EXT_SENS_DATA_16 0x59
130 #define MPU6050_RA_EXT_SENS_DATA_17 0x5A
131 #define MPU6050_RA_EXT_SENS_DATA_18 0x5B
132 #define MPU6050_RA_EXT_SENS_DATA_19 0x5C
133 #define MPU6050_RA_EXT_SENS_DATA_20 0x5D
134 #define MPU6050_RA_EXT_SENS_DATA_21 0x5E
135 #define MPU6050_RA_EXT_SENS_DATA_22 0x5F
136 #define MPU6050_RA_EXT_SENS_DATA_23 0x60
137 #define MPU6050_RA_MOT_DETECT_STATUS 0x61
138 #define MPU6050_RA_I2C_SLV0_DO 0x63
139 #define MPU6050_RA_I2C_SLV1_DO 0x64
140 #define MPU6050_RA_I2C_SLV2_DO 0x65
141 #define MPU6050_RA_I2C_SLV3_DO 0x66
142 #define MPU6050_RA_I2C_MST_DELAY_CTRL 0x67
143 #define MPU6050_RA_SIGNAL_PATH_RESET 0x68
144 #define MPU6050_RA_MOT_DETECT_CTRL 0x69
145 #define MPU6050_RA_USER_CTRL 0x6A
146 #define MPU6050_RA_PWR_MGMT_1 0x6B
147 #define MPU6050_RA_PWR_MGMT_2 0x6C
148 #define MPU6050_RA_BANK_SEL 0x6D
149 #define MPU6050_RA_MEM_START_ADDR 0x6E
150 #define MPU6050_RA_MEM_R_W 0x6F
151 #define MPU6050_RA_DMP_CFG_1 0x70
152 #define MPU6050_RA_DMP_CFG_2 0x71
153 #define MPU6050_RA_FIFO_COUNTH 0x72
154 #define MPU6050_RA_FIFO_COUNTL 0x73
155 #define MPU6050_RA_FIFO_R_W 0x74
156 #define MPU6050_RA_WHO_AM_I 0x75
158 #define MPU6050_TC_PWR_MODE_BIT 7
159 #define MPU6050_TC_OFFSET_BIT 6
160 #define MPU6050_TC_OFFSET_LENGTH 6
161 #define MPU6050_TC_OTP_BNK_VLD_BIT 0
163 #define MPU6050_VDDIO_LEVEL_VLOGIC 0
164 #define MPU6050_VDDIO_LEVEL_VDD 1
166 #define MPU6050_CFG_EXT_SYNC_SET_BIT 5
167 #define MPU6050_CFG_EXT_SYNC_SET_LENGTH 3
168 #define MPU6050_CFG_DLPF_CFG_BIT 2
169 #define MPU6050_CFG_DLPF_CFG_LENGTH 3
171 #define MPU6050_EXT_SYNC_DISABLED 0x0
172 #define MPU6050_EXT_SYNC_TEMP_OUT_L 0x1
173 #define MPU6050_EXT_SYNC_GYRO_XOUT_L 0x2
174 #define MPU6050_EXT_SYNC_GYRO_YOUT_L 0x3
175 #define MPU6050_EXT_SYNC_GYRO_ZOUT_L 0x4
176 #define MPU6050_EXT_SYNC_ACCEL_XOUT_L 0x5
177 #define MPU6050_EXT_SYNC_ACCEL_YOUT_L 0x6
178 #define MPU6050_EXT_SYNC_ACCEL_ZOUT_L 0x7
180 #define MPU6050_DLPF_BW_256 0x00
181 #define MPU6050_DLPF_BW_188 0x01
182 #define MPU6050_DLPF_BW_98 0x02
183 #define MPU6050_DLPF_BW_42 0x03
184 #define MPU6050_DLPF_BW_20 0x04
185 #define MPU6050_DLPF_BW_10 0x05
186 #define MPU6050_DLPF_BW_5 0x06
188 #define MPU6050_GCONFIG_FS_SEL_BIT 4
189 #define MPU6050_GCONFIG_FS_SEL_LENGTH 2
191 #define MPU6050_GYRO_FS_250 0x00
192 #define MPU6050_GYRO_FS_500 0x01
193 #define MPU6050_GYRO_FS_1000 0x02
194 #define MPU6050_GYRO_FS_2000 0x03
196 #define MPU6050_ACONFIG_XA_ST_BIT 7
197 #define MPU6050_ACONFIG_YA_ST_BIT 6
198 #define MPU6050_ACONFIG_ZA_ST_BIT 5
199 #define MPU6050_ACONFIG_AFS_SEL_BIT 4
200 #define MPU6050_ACONFIG_AFS_SEL_LENGTH 2
201 #define MPU6050_ACONFIG_ACCEL_HPF_BIT 2
202 #define MPU6050_ACONFIG_ACCEL_HPF_LENGTH 3
204 #define MPU6050_ACCEL_FS_2 0x00
205 #define MPU6050_ACCEL_FS_4 0x01
206 #define MPU6050_ACCEL_FS_8 0x02
207 #define MPU6050_ACCEL_FS_16 0x03
209 #define MPU6050_DHPF_RESET 0x00
210 #define MPU6050_DHPF_5 0x01
211 #define MPU6050_DHPF_2P5 0x02
212 #define MPU6050_DHPF_1P25 0x03
213 #define MPU6050_DHPF_0P63 0x04
214 #define MPU6050_DHPF_HOLD 0x07
216 #define MPU6050_TEMP_FIFO_EN_BIT 7
217 #define MPU6050_XG_FIFO_EN_BIT 6
218 #define MPU6050_YG_FIFO_EN_BIT 5
219 #define MPU6050_ZG_FIFO_EN_BIT 4
220 #define MPU6050_ACCEL_FIFO_EN_BIT 3
221 #define MPU6050_SLV2_FIFO_EN_BIT 2
222 #define MPU6050_SLV1_FIFO_EN_BIT 1
223 #define MPU6050_SLV0_FIFO_EN_BIT 0
225 #define MPU6050_MULT_MST_EN_BIT 7
226 #define MPU6050_WAIT_FOR_ES_BIT 6
227 #define MPU6050_SLV_3_FIFO_EN_BIT 5
228 #define MPU6050_I2C_MST_P_NSR_BIT 4
229 #define MPU6050_I2C_MST_CLK_BIT 3
230 #define MPU6050_I2C_MST_CLK_LENGTH 4
232 #define MPU6050_CLOCK_DIV_348 0x0
233 #define MPU6050_CLOCK_DIV_333 0x1
234 #define MPU6050_CLOCK_DIV_320 0x2
235 #define MPU6050_CLOCK_DIV_308 0x3
236 #define MPU6050_CLOCK_DIV_296 0x4
237 #define MPU6050_CLOCK_DIV_286 0x5
238 #define MPU6050_CLOCK_DIV_276 0x6
239 #define MPU6050_CLOCK_DIV_267 0x7
240 #define MPU6050_CLOCK_DIV_258 0x8
241 #define MPU6050_CLOCK_DIV_500 0x9
242 #define MPU6050_CLOCK_DIV_471 0xA
243 #define MPU6050_CLOCK_DIV_444 0xB
244 #define MPU6050_CLOCK_DIV_421 0xC
245 #define MPU6050_CLOCK_DIV_400 0xD
246 #define MPU6050_CLOCK_DIV_381 0xE
247 #define MPU6050_CLOCK_DIV_364 0xF
249 #define MPU6050_I2C_SLV_RW_BIT 7
250 #define MPU6050_I2C_SLV_ADDR_BIT 6
251 #define MPU6050_I2C_SLV_ADDR_LENGTH 7
252 #define MPU6050_I2C_SLV_EN_BIT 7
253 #define MPU6050_I2C_SLV_BYTE_SW_BIT 6
254 #define MPU6050_I2C_SLV_REG_DIS_BIT 5
255 #define MPU6050_I2C_SLV_GRP_BIT 4
256 #define MPU6050_I2C_SLV_LEN_BIT 3
257 #define MPU6050_I2C_SLV_LEN_LENGTH 4
259 #define MPU6050_I2C_SLV4_RW_BIT 7
260 #define MPU6050_I2C_SLV4_ADDR_BIT 6
261 #define MPU6050_I2C_SLV4_ADDR_LENGTH 7
262 #define MPU6050_I2C_SLV4_EN_BIT 7
263 #define MPU6050_I2C_SLV4_INT_EN_BIT 6
264 #define MPU6050_I2C_SLV4_REG_DIS_BIT 5
265 #define MPU6050_I2C_SLV4_MST_DLY_BIT 4
266 #define MPU6050_I2C_SLV4_MST_DLY_LENGTH 5
268 #define MPU6050_MST_PASS_THROUGH_BIT 7
269 #define MPU6050_MST_I2C_SLV4_DONE_BIT 6
270 #define MPU6050_MST_I2C_LOST_ARB_BIT 5
271 #define MPU6050_MST_I2C_SLV4_NACK_BIT 4
272 #define MPU6050_MST_I2C_SLV3_NACK_BIT 3
273 #define MPU6050_MST_I2C_SLV2_NACK_BIT 2
274 #define MPU6050_MST_I2C_SLV1_NACK_BIT 1
275 #define MPU6050_MST_I2C_SLV0_NACK_BIT 0
277 #define MPU6050_INTCFG_INT_LEVEL_BIT 7
278 #define MPU6050_INTCFG_INT_OPEN_BIT 6
279 #define MPU6050_INTCFG_LATCH_INT_EN_BIT 5
280 #define MPU6050_INTCFG_INT_RD_CLEAR_BIT 4
281 #define MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT 3
282 #define MPU6050_INTCFG_FSYNC_INT_EN_BIT 2
283 #define MPU6050_INTCFG_I2C_BYPASS_EN_BIT 1
284 #define MPU6050_INTCFG_CLKOUT_EN_BIT 0
286 #define MPU6050_INTMODE_ACTIVEHIGH 0x00
287 #define MPU6050_INTMODE_ACTIVELOW 0x01
289 #define MPU6050_INTDRV_PUSHPULL 0x00
290 #define MPU6050_INTDRV_OPENDRAIN 0x01
292 #define MPU6050_INTLATCH_50USPULSE 0x00
293 #define MPU6050_INTLATCH_WAITCLEAR 0x01
295 #define MPU6050_INTCLEAR_STATUSREAD 0x00
296 #define MPU6050_INTCLEAR_ANYREAD 0x01
298 #define MPU6050_INTERRUPT_FF_BIT 7
299 #define MPU6050_INTERRUPT_MOT_BIT 6
300 #define MPU6050_INTERRUPT_ZMOT_BIT 5
301 #define MPU6050_INTERRUPT_FIFO_OFLOW_BIT 4
302 #define MPU6050_INTERRUPT_I2C_MST_INT_BIT 3
303 #define MPU6050_INTERRUPT_PLL_RDY_INT_BIT 2
304 #define MPU6050_INTERRUPT_DMP_INT_BIT 1
305 #define MPU6050_INTERRUPT_DATA_RDY_BIT 0
307 // TODO: figure out what these actually do
308 // UMPL source code is not very obivous
309 #define MPU6050_DMPINT_5_BIT 5
310 #define MPU6050_DMPINT_4_BIT 4
311 #define MPU6050_DMPINT_3_BIT 3
312 #define MPU6050_DMPINT_2_BIT 2
313 #define MPU6050_DMPINT_1_BIT 1
314 #define MPU6050_DMPINT_0_BIT 0
316 #define MPU6050_MOTION_MOT_XNEG_BIT 7
317 #define MPU6050_MOTION_MOT_XPOS_BIT 6
318 #define MPU6050_MOTION_MOT_YNEG_BIT 5
319 #define MPU6050_MOTION_MOT_YPOS_BIT 4
320 #define MPU6050_MOTION_MOT_ZNEG_BIT 3
321 #define MPU6050_MOTION_MOT_ZPOS_BIT 2
322 #define MPU6050_MOTION_MOT_ZRMOT_BIT 0
324 #define MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT 7
325 #define MPU6050_DELAYCTRL_I2C_SLV4_DLY_EN_BIT 4
326 #define MPU6050_DELAYCTRL_I2C_SLV3_DLY_EN_BIT 3
327 #define MPU6050_DELAYCTRL_I2C_SLV2_DLY_EN_BIT 2
328 #define MPU6050_DELAYCTRL_I2C_SLV1_DLY_EN_BIT 1
329 #define MPU6050_DELAYCTRL_I2C_SLV0_DLY_EN_BIT 0
331 #define MPU6050_PATHRESET_GYRO_RESET_BIT 2
332 #define MPU6050_PATHRESET_ACCEL_RESET_BIT 1
333 #define MPU6050_PATHRESET_TEMP_RESET_BIT 0
335 #define MPU6050_DETECT_ACCEL_ON_DELAY_BIT 5
336 #define MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH 2
337 #define MPU6050_DETECT_FF_COUNT_BIT 3
338 #define MPU6050_DETECT_FF_COUNT_LENGTH 2
339 #define MPU6050_DETECT_MOT_COUNT_BIT 1
340 #define MPU6050_DETECT_MOT_COUNT_LENGTH 2
342 #define MPU6050_DETECT_DECREMENT_RESET 0x0
343 #define MPU6050_DETECT_DECREMENT_1 0x1
344 #define MPU6050_DETECT_DECREMENT_2 0x2
345 #define MPU6050_DETECT_DECREMENT_4 0x3
347 #define MPU6050_USERCTRL_DMP_EN_BIT 7
348 #define MPU6050_USERCTRL_FIFO_EN_BIT 6
349 #define MPU6050_USERCTRL_I2C_MST_EN_BIT 5
350 #define MPU6050_USERCTRL_I2C_IF_DIS_BIT 4
351 #define MPU6050_USERCTRL_DMP_RESET_BIT 3
352 #define MPU6050_USERCTRL_FIFO_RESET_BIT 2
353 #define MPU6050_USERCTRL_I2C_MST_RESET_BIT 1
354 #define MPU6050_USERCTRL_SIG_COND_RESET_BIT 0
356 #define MPU6050_PWR1_DEVICE_RESET_BIT 7
357 #define MPU6050_PWR1_SLEEP_BIT 6
358 #define MPU6050_PWR1_CYCLE_BIT 5
359 #define MPU6050_PWR1_TEMP_DIS_BIT 3
360 #define MPU6050_PWR1_CLKSEL_BIT 2
361 #define MPU6050_PWR1_CLKSEL_LENGTH 3
363 #define MPU6050_CLOCK_INTERNAL 0x00
364 #define MPU6050_CLOCK_PLL_XGYRO 0x01
365 #define MPU6050_CLOCK_PLL_YGYRO 0x02
366 #define MPU6050_CLOCK_PLL_ZGYRO 0x03
367 #define MPU6050_CLOCK_PLL_EXT32K 0x04
368 #define MPU6050_CLOCK_PLL_EXT19M 0x05
369 #define MPU6050_CLOCK_KEEP_RESET 0x07
371 #define MPU6050_PWR2_LP_WAKE_CTRL_BIT 7
372 #define MPU6050_PWR2_LP_WAKE_CTRL_LENGTH 2
373 #define MPU6050_PWR2_STBY_XA_BIT 5
374 #define MPU6050_PWR2_STBY_YA_BIT 4
375 #define MPU6050_PWR2_STBY_ZA_BIT 3
376 #define MPU6050_PWR2_STBY_XG_BIT 2
377 #define MPU6050_PWR2_STBY_YG_BIT 1
378 #define MPU6050_PWR2_STBY_ZG_BIT 0
380 #define MPU6050_WAKE_FREQ_1P25 0x0
381 #define MPU6050_WAKE_FREQ_2P5 0x1
382 #define MPU6050_WAKE_FREQ_5 0x2
383 #define MPU6050_WAKE_FREQ_10 0x3
385 #define MPU6050_BANKSEL_PRFTCH_EN_BIT 6
386 #define MPU6050_BANKSEL_CFG_USER_BANK_BIT 5
387 #define MPU6050_BANKSEL_MEM_SEL_BIT 4
388 #define MPU6050_BANKSEL_MEM_SEL_LENGTH 5
390 #define MPU6050_WHO_AM_I_BIT 6
391 #define MPU6050_WHO_AM_I_LENGTH 6
393 #define MPU6050_DMP_MEMORY_BANKS 8
394 #define MPU6050_DMP_MEMORY_BANK_SIZE 256
395 #define MPU6050_DMP_MEMORY_CHUNK_SIZE 16
397 // note: DMP code memory blocks defined at end of header file
402 MPU6050(uint8_t address);
405 bool testConnection();
407 // AUX_VDDIO register
408 uint8_t getAuxVDDIOLevel();
409 void setAuxVDDIOLevel(uint8_t level);
411 // SMPLRT_DIV register
413 void setRate(uint8_t rate);
416 uint8_t getExternalFrameSync();
417 void setExternalFrameSync(uint8_t sync);
418 uint8_t getDLPFMode();
419 void setDLPFMode(uint8_t bandwidth);
421 // GYRO_CONFIG register
422 uint8_t getFullScaleGyroRange();
423 void setFullScaleGyroRange(uint8_t range);
425 // ACCEL_CONFIG register
426 bool getAccelXSelfTest();
427 void setAccelXSelfTest(bool enabled);
428 bool getAccelYSelfTest();
429 void setAccelYSelfTest(bool enabled);
430 bool getAccelZSelfTest();
431 void setAccelZSelfTest(bool enabled);
432 uint8_t getFullScaleAccelRange();
433 void setFullScaleAccelRange(uint8_t range);
434 uint8_t getDHPFMode();
435 void setDHPFMode(uint8_t mode);
438 uint8_t getFreefallDetectionThreshold();
439 void setFreefallDetectionThreshold(uint8_t threshold);
442 uint8_t getFreefallDetectionDuration();
443 void setFreefallDetectionDuration(uint8_t duration);
446 uint8_t getMotionDetectionThreshold();
447 void setMotionDetectionThreshold(uint8_t threshold);
450 uint8_t getMotionDetectionDuration();
451 void setMotionDetectionDuration(uint8_t duration);
453 // ZRMOT_THR register
454 uint8_t getZeroMotionDetectionThreshold();
455 void setZeroMotionDetectionThreshold(uint8_t threshold);
457 // ZRMOT_DUR register
458 uint8_t getZeroMotionDetectionDuration();
459 void setZeroMotionDetectionDuration(uint8_t duration);
462 bool getTempFIFOEnabled();
463 void setTempFIFOEnabled(bool enabled);
464 bool getXGyroFIFOEnabled();
465 void setXGyroFIFOEnabled(bool enabled);
466 bool getYGyroFIFOEnabled();
467 void setYGyroFIFOEnabled(bool enabled);
468 bool getZGyroFIFOEnabled();
469 void setZGyroFIFOEnabled(bool enabled);
470 bool getAccelFIFOEnabled();
471 void setAccelFIFOEnabled(bool enabled);
472 bool getSlave2FIFOEnabled();
473 void setSlave2FIFOEnabled(bool enabled);
474 bool getSlave1FIFOEnabled();
475 void setSlave1FIFOEnabled(bool enabled);
476 bool getSlave0FIFOEnabled();
477 void setSlave0FIFOEnabled(bool enabled);
479 // I2C_MST_CTRL register
480 bool getMultiMasterEnabled();
481 void setMultiMasterEnabled(bool enabled);
482 bool getWaitForExternalSensorEnabled();
483 void setWaitForExternalSensorEnabled(bool enabled);
484 bool getSlave3FIFOEnabled();
485 void setSlave3FIFOEnabled(bool enabled);
486 bool getSlaveReadWriteTransitionEnabled();
487 void setSlaveReadWriteTransitionEnabled(bool enabled);
488 uint8_t getMasterClockSpeed();
489 void setMasterClockSpeed(uint8_t speed);
491 // I2C_SLV* registers (Slave 0-3)
492 uint8_t getSlaveAddress(uint8_t num);
493 void setSlaveAddress(uint8_t num, uint8_t address);
494 uint8_t getSlaveRegister(uint8_t num);
495 void setSlaveRegister(uint8_t num, uint8_t reg);
496 bool getSlaveEnabled(uint8_t num);
497 void setSlaveEnabled(uint8_t num, bool enabled);
498 bool getSlaveWordByteSwap(uint8_t num);
499 void setSlaveWordByteSwap(uint8_t num, bool enabled);
500 bool getSlaveWriteMode(uint8_t num);
501 void setSlaveWriteMode(uint8_t num, bool mode);
502 bool getSlaveWordGroupOffset(uint8_t num);
503 void setSlaveWordGroupOffset(uint8_t num, bool enabled);
504 uint8_t getSlaveDataLength(uint8_t num);
505 void setSlaveDataLength(uint8_t num, uint8_t length);
507 // I2C_SLV* registers (Slave 4)
508 uint8_t getSlave4Address();
509 void setSlave4Address(uint8_t address);
510 uint8_t getSlave4Register();
511 void setSlave4Register(uint8_t reg);
512 void setSlave4OutputByte(uint8_t data);
513 bool getSlave4Enabled();
514 void setSlave4Enabled(bool enabled);
515 bool getSlave4InterruptEnabled();
516 void setSlave4InterruptEnabled(bool enabled);
517 bool getSlave4WriteMode();
518 void setSlave4WriteMode(bool mode);
519 uint8_t getSlave4MasterDelay();
520 void setSlave4MasterDelay(uint8_t delay);
521 uint8_t getSlate4InputByte();
523 // I2C_MST_STATUS register
524 bool getPassthroughStatus();
525 bool getSlave4IsDone();
526 bool getLostArbitration();
527 bool getSlave4Nack();
528 bool getSlave3Nack();
529 bool getSlave2Nack();
530 bool getSlave1Nack();
531 bool getSlave0Nack();
533 // INT_PIN_CFG register
534 bool getInterruptMode();
535 void setInterruptMode(bool mode);
536 bool getInterruptDrive();
537 void setInterruptDrive(bool drive);
538 bool getInterruptLatch();
539 void setInterruptLatch(bool latch);
540 bool getInterruptLatchClear();
541 void setInterruptLatchClear(bool clear);
542 bool getFSyncInterruptLevel();
543 void setFSyncInterruptLevel(bool level);
544 bool getFSyncInterruptEnabled();
545 void setFSyncInterruptEnabled(bool enabled);
546 bool getI2CBypassEnabled();
547 void setI2CBypassEnabled(bool enabled);
548 bool getClockOutputEnabled();
549 void setClockOutputEnabled(bool enabled);
551 // INT_ENABLE register
552 bool getIntFreefallEnabled();
553 void setIntFreefallEnabled(bool enabled);
554 bool getIntMotionEnabled();
555 void setIntMotionEnabled(bool enabled);
556 bool getIntZeroMotionEnabled();
557 void setIntZeroMotionEnabled(bool enabled);
558 bool getIntFIFOBufferOverflowEnabled();
559 void setIntFIFOBufferOverflowEnabled(bool enabled);
560 bool getIntI2CMasterEnabled();
561 void setIntI2CMasterEnabled(bool enabled);
562 bool getIntDataReadyEnabled();
563 void setIntDataReadyEnabled(bool enabled);
565 // INT_STATUS register
566 bool getIntFreefallStatus();
567 bool getIntMotionStatus();
568 bool getIntZeroMotionStatus();
569 bool getIntFIFOBufferOverflowStatus();
570 bool getIntI2CMasterStatus();
571 bool getIntDataReadyStatus();
573 // ACCEL_*OUT_* registers
574 void getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz);
575 void getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz);
576 void getAcceleration(int16_t* x, int16_t* y, int16_t* z);
577 int16_t getAccelerationX();
578 int16_t getAccelerationY();
579 int16_t getAccelerationZ();
581 // TEMP_OUT_* registers
582 int16_t getTemperature();
584 // GYRO_*OUT_* registers
585 void getRotation(int16_t* x, int16_t* y, int16_t* z);
586 int16_t getRotationX();
587 int16_t getRotationY();
588 int16_t getRotationZ();
590 // EXT_SENS_DATA_* registers
591 uint8_t getExternalSensorByte(int position);
592 uint16_t getExternalSensorWord(int position);
593 uint32_t getExternalSensorDWord(int position);
595 // MOT_DETECT_STATUS register
596 bool getXNegMotionDetected();
597 bool getXPosMotionDetected();
598 bool getYNegMotionDetected();
599 bool getYPosMotionDetected();
600 bool getZNegMotionDetected();
601 bool getZPosMotionDetected();
602 bool getZeroMotionDetected();
604 // I2C_SLV*_DO register
605 void setSlaveOutputByte(uint8_t num, uint8_t data);
607 // I2C_MST_DELAY_CTRL register
608 bool getExternalShadowDelayEnabled();
609 void setExternalShadowDelayEnabled(bool enabled);
610 bool getSlaveDelayEnabled(uint8_t num);
611 void setSlaveDelayEnabled(uint8_t num, bool enabled);
613 // SIGNAL_PATH_RESET register
614 void resetGyroscopePath();
615 void resetAccelerometerPath();
616 void resetTemperaturePath();
618 // MOT_DETECT_CTRL register
619 uint8_t getAccelerometerPowerOnDelay();
620 void setAccelerometerPowerOnDelay(uint8_t delay);
621 uint8_t getFreefallDetectionCounterDecrement();
622 void setFreefallDetectionCounterDecrement(uint8_t decrement);
623 uint8_t getMotionDetectionCounterDecrement();
624 void setMotionDetectionCounterDecrement(uint8_t decrement);
626 // USER_CTRL register
627 bool getFIFOEnabled();
628 void setFIFOEnabled(bool enabled);
629 bool getI2CMasterModeEnabled();
630 void setI2CMasterModeEnabled(bool enabled);
631 void switchSPIEnabled(bool enabled);
633 void resetI2CMaster();
636 // PWR_MGMT_1 register
638 bool getSleepEnabled();
639 void setSleepEnabled(bool enabled);
640 bool getWakeCycleEnabled();
641 void setWakeCycleEnabled(bool enabled);
642 bool getTempSensorEnabled();
643 void setTempSensorEnabled(bool enabled);
644 uint8_t getClockSource();
645 void setClockSource(uint8_t source);
647 // PWR_MGMT_2 register
648 uint8_t getWakeFrequency();
649 void setWakeFrequency(uint8_t frequency);
650 bool getStandbyXAccelEnabled();
651 void setStandbyXAccelEnabled(bool enabled);
652 bool getStandbyYAccelEnabled();
653 void setStandbyYAccelEnabled(bool enabled);
654 bool getStandbyZAccelEnabled();
655 void setStandbyZAccelEnabled(bool enabled);
656 bool getStandbyXGyroEnabled();
657 void setStandbyXGyroEnabled(bool enabled);
658 bool getStandbyYGyroEnabled();
659 void setStandbyYGyroEnabled(bool enabled);
660 bool getStandbyZGyroEnabled();
661 void setStandbyZGyroEnabled(bool enabled);
663 // FIFO_COUNT_* registers
664 uint16_t getFIFOCount();
667 uint8_t getFIFOByte();
668 void setFIFOByte(uint8_t data);
671 uint8_t getDeviceID();
672 void setDeviceID(uint8_t id);
674 // ======== UNDOCUMENTED/DMP REGISTERS/METHODS ========
676 // XG_OFFS_TC register
677 int8_t getXGyroOffset();
678 void setXGyroOffset(int8_t offset);
680 // YG_OFFS_TC register
681 int8_t getYGyroOffset();
682 void setYGyroOffset(int8_t offset);
684 // ZG_OFFS_TC register
685 int8_t getZGyroOffset();
686 void setZGyroOffset(int8_t offset);
688 // X_FINE_GAIN register
689 int8_t getXFineGain();
690 void setXFineGain(int8_t gain);
692 // Y_FINE_GAIN register
693 int8_t getYFineGain();
694 void setYFineGain(int8_t gain);
696 // Z_FINE_GAIN register
697 int8_t getZFineGain();
698 void setZFineGain(int8_t gain);
700 // XA_OFFS_* registers
701 int16_t getXAccelOffset();
702 void setXAccelOffset(int16_t offset);
704 // YA_OFFS_* register
705 int16_t getYAccelOffset();
706 void setYAccelOffset(int16_t offset);
708 // ZA_OFFS_* register
709 int16_t getZAccelOffset();
710 void setZAccelOffset(int16_t offset);
712 // XG_OFFS_USR* registers
713 int16_t getXGyroOffsetUser();
714 void setXGyroOffsetUser(int16_t offset);
716 // YG_OFFS_USR* register
717 int16_t getYGyroOffsetUser();
718 void setYGyroOffsetUser(int16_t offset);
720 // ZG_OFFS_USR* register
721 int16_t getZGyroOffsetUser();
722 void setZGyroOffsetUser(int16_t offset);
724 // INT_ENABLE register (DMP functions)
725 bool getIntPLLReadyEnabled();
726 void setIntPLLReadyEnabled(bool enabled);
727 bool getIntDMPEnabled();
728 void setIntDMPEnabled(bool enabled);
731 bool getDMPInt5Status();
732 bool getDMPInt4Status();
733 bool getDMPInt3Status();
734 bool getDMPInt2Status();
735 bool getDMPInt1Status();
736 bool getDMPInt0Status();
738 // INT_STATUS register (DMP functions)
739 bool getIntPLLReadyStatus();
740 bool getIntDMPStatus();
742 // USER_CTRL register (DMP functions)
743 bool getDMPEnabled();
744 void setDMPEnabled(bool enabled);
748 void setMemoryBank(uint8_t bank, bool prefetchEnabled=false, bool userBank=false);
750 // MEM_START_ADDR register
751 void setMemoryStartAddress(uint8_t address);
754 uint8_t readMemoryByte();
755 void writeMemoryByte(uint8_t data);
756 void readMemoryBlock(uint8_t *data, uint16_t dataSize, uint8_t bank=0, uint8_t address=0);
757 bool writeMemoryBlock(uint8_t *data, uint16_t dataSize, uint8_t bank=0, uint8_t address=0, bool verify=true, bool useProgMem=false);
758 bool writeProgMemoryBlock(uint8_t *data, uint16_t dataSize, uint8_t bank=0, uint8_t address=0, bool verify=true);
760 // DMP_CFG_1 register
761 uint8_t getDMPConfig1();
762 void setDMPConfig1(uint8_t config);
764 // DMP_CFG_2 register
765 uint8_t getDMPConfig2();
766 void setDMPConfig2(uint8_t config);
773 #ifdef MPU6050_INCLUDE_DMP_MOTIONAPPS20
774 /* This is only included if you want it, since it eats about 2K of program
775 * memory, which is a waste if you aren't using the DMP (or if you aren't
776 * using this particular flavor of DMP).
778 * Source is from the InvenSense MotionApps v2 demo code. Original source is
779 * unavailable, unless you happen to be amazing as decompiling binary by
780 * hand (in which case, please contact me, and I'm totally serious).
782 * Also, I'd like to offer many, many thanks to Noah Zerkin for all of the
783 * DMP reverse-engineering he did to help make this bit of wizardry
787 #define MPU6050_DMP_CODE_SIZE 1929
789 // this block of memory gets written to the MPU on start-up, and it seems
790 // to be volatile memory, so it has to be done each time (it only takes ~1
792 prog_uchar dmpMemory[MPU6050_DMP_CODE_SIZE] PROGMEM = {
794 0xFB, 0x00, 0x00, 0x3E, 0x00, 0x0B, 0x00, 0x36, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00,
795 0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0xFA, 0x80, 0x00, 0x0B, 0x12, 0x82, 0x00, 0x01,
796 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
797 0x00, 0x28, 0x00, 0x00, 0xFF, 0xFF, 0x45, 0x81, 0xFF, 0xFF, 0xFA, 0x72, 0x00, 0x00, 0x00, 0x00,
798 0x00, 0x00, 0x03, 0xE8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x7F, 0xFF, 0xFF, 0xFE, 0x80, 0x01,
799 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
800 0x00, 0x3E, 0x03, 0x30, 0x40, 0x00, 0x00, 0x00, 0x02, 0xCA, 0xE3, 0x09, 0x3E, 0x80, 0x00, 0x00,
801 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
802 0x41, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x2A, 0x00, 0x00, 0x16, 0x55, 0x00, 0x00, 0x21, 0x82,
803 0xFD, 0x87, 0x26, 0x50, 0xFD, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x05, 0x80, 0x00,
804 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
805 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x6F, 0x00, 0x02, 0x65, 0x32, 0x00, 0x00, 0x5E, 0xC0,
806 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
807 0xFB, 0x8C, 0x6F, 0x5D, 0xFD, 0x5D, 0x08, 0xD9, 0x00, 0x7C, 0x73, 0x3B, 0x00, 0x6C, 0x12, 0xCC,
808 0x32, 0x00, 0x13, 0x9D, 0x32, 0x00, 0xD0, 0xD6, 0x32, 0x00, 0x08, 0x00, 0x40, 0x00, 0x01, 0xF4,
809 0xFF, 0xE6, 0x80, 0x79, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xD6, 0x00, 0x00, 0x27, 0x10,
812 0xFB, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
813 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
814 0x00, 0x00, 0xFA, 0x36, 0xFF, 0xBC, 0x30, 0x8E, 0x00, 0x05, 0xFB, 0xF0, 0xFF, 0xD9, 0x5B, 0xC8,
815 0xFF, 0xD0, 0x9A, 0xBE, 0x00, 0x00, 0x10, 0xA9, 0xFF, 0xF4, 0x1E, 0xB2, 0x00, 0xCE, 0xBB, 0xF7,
816 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00, 0x0C,
817 0xFF, 0xC2, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0xCF, 0x80, 0x00, 0x40, 0x00, 0x00, 0x00,
818 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x14,
819 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
820 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
821 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
822 0x00, 0x00, 0x00, 0x00, 0x03, 0x3F, 0x68, 0xB6, 0x79, 0x35, 0x28, 0xBC, 0xC6, 0x7E, 0xD1, 0x6C,
823 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB2, 0x6A, 0x00, 0x00, 0x00, 0x00,
824 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x30,
825 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
826 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
827 0x00, 0x00, 0x25, 0x4D, 0x00, 0x2F, 0x70, 0x6D, 0x00, 0x00, 0x05, 0xAE, 0x00, 0x0C, 0x02, 0xD0,
830 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
831 0x00, 0x00, 0x01, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00,
832 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0xFF, 0xEF, 0x00, 0x00,
833 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
834 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
835 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
836 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
837 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
838 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
839 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
840 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
841 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
842 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
843 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
844 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
845 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
848 0xD8, 0xDC, 0xBA, 0xA2, 0xF1, 0xDE, 0xB2, 0xB8, 0xB4, 0xA8, 0x81, 0x91, 0xF7, 0x4A, 0x90, 0x7F,
849 0x91, 0x6A, 0xF3, 0xF9, 0xDB, 0xA8, 0xF9, 0xB0, 0xBA, 0xA0, 0x80, 0xF2, 0xCE, 0x81, 0xF3, 0xC2,
850 0xF1, 0xC1, 0xF2, 0xC3, 0xF3, 0xCC, 0xA2, 0xB2, 0x80, 0xF1, 0xC6, 0xD8, 0x80, 0xBA, 0xA7, 0xDF,
851 0xDF, 0xDF, 0xF2, 0xA7, 0xC3, 0xCB, 0xC5, 0xB6, 0xF0, 0x87, 0xA2, 0x94, 0x24, 0x48, 0x70, 0x3C,
852 0x95, 0x40, 0x68, 0x34, 0x58, 0x9B, 0x78, 0xA2, 0xF1, 0x83, 0x92, 0x2D, 0x55, 0x7D, 0xD8, 0xB1,
853 0xB4, 0xB8, 0xA1, 0xD0, 0x91, 0x80, 0xF2, 0x70, 0xF3, 0x70, 0xF2, 0x7C, 0x80, 0xA8, 0xF1, 0x01,
854 0xB0, 0x98, 0x87, 0xD9, 0x43, 0xD8, 0x86, 0xC9, 0x88, 0xBA, 0xA1, 0xF2, 0x0E, 0xB8, 0x97, 0x80,
855 0xF1, 0xA9,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DA, 0x2C, 0x4C, 0x0E, 0xD8, 0xB8, 0xB0, 0xA8, 0x8A,
893 0x9A, 0xF5, 0x20, 0xAA, 0xDA, 0xDF, 0xD8, 0xA8, 0x40, 0xAA, 0xD0, 0xDA, 0xDE, 0xD8, 0xA8, 0x60,
894 0xAA, 0xDA, 0xD0, 0xDF, 0xD8, 0xF1, 0x97, 0x86, 0xA8, 0x31, 0x9B, 0x06, 0x99, 0x07, 0xAB, 0x97,
895 0x28, 0x88, 0x9B, 0xF0, 0x0C, 0x20, 0x14, 0x40, 0xB8, 0xB0, 0xB4, 0xA8, 0x8C, 0x9C, 0xF0, 0x04,
896 0x28, 0x51, 0x79, 0x1D, 0x30, 0x14, 0x38, 0xB2, 0x82, 0xAB, 0xD0, 0x98, 0x2C, 0x50, 0x50, 0x78,
897 0x78, 0x9B, 0xF1, 0x1A, 0xB0, 0xF0, 0x8A, 0x9C, 0xA8, 0x29, 0x51, 0x79, 0x8B, 0x29, 0x51, 0x79,
898 0x8A, 0x24, 0x70, 0x59, 0x8B, 0x20, 0x58, 0x71, 0x8A, 0x44, 0x69, 0x38, 0x8B, 0x39, 0x40, 0x68,
899 0x8A, 0x64, 0x48, 0x31, 0x8B, 0x30, 0x49, 0x60, 0xA5, 0x88, 0x20, 0x09, 0x71, 0x58, 0x44, 0x68,
902 0x11, 0x39, 0x64, 0x49, 0x30, 0x19, 0xF1, 0xAC, 0x00, 0x2C, 0x54, 0x7C, 0xF0, 0x8C, 0xA8, 0x04,
903 0x28, 0x50, 0x78, 0xF1, 0x88, 0x97, 0x26, 0xA8, 0x59, 0x98, 0xAC, 0x8C, 0x02, 0x26, 0x46, 0x66,
904 0xF0, 0x89, 0x9C, 0xA8, 0x29, 0x51, 0x79, 0x24, 0x70, 0x59, 0x44, 0x69, 0x38, 0x64, 0x48, 0x31,
905 0xA9, 0x88, 0x09, 0x20, 0x59, 0x70, 0xAB, 0x11, 0x38, 0x40, 0x69, 0xA8, 0x19, 0x31, 0x48, 0x60,
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x91, 0x2C, 0x4C, 0x6C, 0x8A, 0x9B, 0x2D, 0xD9, 0xD8, 0xD8, 0x51, 0xD9, 0xD8, 0xD8, 0x79,
919 // bank 7, 138 bytes (remainder)
920 0xD9, 0xD8, 0xD8, 0xF1, 0x9E, 0x88, 0xA3, 0x31, 0xDA, 0xD8, 0xD8, 0x91, 0x2D, 0xD9, 0x28, 0xD8,
921 0x4D, 0xD9, 0x48, 0xD8, 0x6D, 0xD9, 0x68, 0xD8, 0xB1, 0x83, 0x93, 0x35, 0x3D, 0x80, 0x25, 0xDA,
922 0xD8, 0xD8, 0x85, 0x69, 0xDA, 0xD8, 0xD8, 0xB4, 0x93, 0x81, 0xA3, 0x28, 0x34, 0x3C, 0xF3, 0xAB,
923 0x8B, 0xF8, 0xA3, 0x91, 0xB6, 0x09, 0xB4, 0xD9, 0xAB, 0xDE, 0xFA, 0xB0, 0x87, 0x9C, 0xB9, 0xA3,
924 0xDD, 0xF1, 0xA3, 0xA3, 0xA3, 0xA3, 0x95, 0xF1, 0xA3, 0xA3, 0xA3, 0x9D, 0xF1, 0xA3, 0xA3, 0xA3,
925 0xA3, 0xF2, 0xA3, 0xB4, 0x90, 0x80, 0xF2, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3,
926 0xA3, 0xB2, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xB0, 0x87, 0xB5, 0x99, 0xF1, 0xA3, 0xA3, 0xA3,
927 0x98, 0xF1, 0xA3, 0xA3, 0xA3, 0xA3, 0x97, 0xA3, 0xA3, 0xA3, 0xA3, 0xF3, 0x9B, 0xA3, 0xA3, 0xDC,
928 0xB9, 0xA7, 0xF1, 0x26, 0x26, 0x26, 0xD8, 0xD8, 0xFF
931 uint8_t dmpUpdates[29][9] = {
932 { 0x03, 0x7B, 0x03, 0x4C, 0xCD, 0x6C }, // FCFG_1 inv_set_gyro_calibration
933 { 0x03, 0xAB, 0x03, 0x36, 0x56, 0x76 }, // FCFG_3 inv_set_gyro_calibration
934 { 0x00, 0x68, 0x04, 0x02, 0xCB, 0x47, 0xA2 }, // D_0_104 inv_set_gyro_calibration
935 { 0x02, 0x18, 0x04, 0x00, 0x05, 0x8B, 0xC1 }, // D_0_24 inv_set_gyro_calibration
936 { 0x01, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00 }, // D_1_152 inv_set_accel_calibration
937 { 0x03, 0x7F, 0x06, 0x0C, 0xC9, 0x2C, 0x97, 0x97, 0x97 }, // FCFG_2 inv_set_accel_calibration
938 { 0x03, 0x89, 0x03, 0x26, 0x46, 0x66 }, // FCFG_7 inv_set_accel_calibration
939 { 0x00, 0x6C, 0x02, 0x20, 0x00 }, // D_0_108 inv_set_accel_calibration
940 { 0x02, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00 }, // CPASS_MTX_00 inv_set_compass_calibration
941 { 0x02, 0x44, 0x04, 0x00, 0x00, 0x00, 0x00 }, // CPASS_MTX_01
942 { 0x02, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00 }, // CPASS_MTX_02
943 { 0x02, 0x4C, 0x04, 0x00, 0x00, 0x00, 0x00 }, // CPASS_MTX_10
944 { 0x02, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00 }, // CPASS_MTX_11
945 { 0x02, 0x54, 0x04, 0x00, 0x00, 0x00, 0x00 }, // CPASS_MTX_12
946 { 0x02, 0x58, 0x04, 0x00, 0x00, 0x00, 0x00 }, // CPASS_MTX_20
947 { 0x02, 0x5C, 0x04, 0x00, 0x00, 0x00, 0x00 }, // CPASS_MTX_21
948 { 0x02, 0xBC, 0x04, 0x00, 0x00, 0x00, 0x00 }, // CPASS_MTX_22
949 { 0x01, 0xEC, 0x04, 0x00, 0x00, 0x40, 0x00 }, // D_1_236 inv_apply_endian_accel
950 { 0x03, 0x7F, 0x06, 0x0C, 0xC9, 0x2C, 0x97, 0x97, 0x97 }, // FCFG_2 inv_set_mpu_sensors
951 { 0x04, 0x02, 0x03, 0x0D, 0x35, 0x5D }, // CFG_MOTION_BIAS inv_turn_on_bias_from_no_motion
952 { 0x04, 0x09, 0x04, 0x87, 0x2D, 0x35, 0x3D }, // FCFG_5 inv_set_bias_update
953 { 0x00, 0xA3, 0x01, 0x00 }, // D_0_163 inv_set_dead_zone
954 // SET INT_ENABLE at i=22
955 { 0x07, 0x86, 0x01, 0xFE }, // CFG_6 inv_set_fifo_interupt
956 { 0x07, 0x41, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38 }, // CFG_8 inv_send_quaternion
957 { 0x07, 0x7E, 0x01, 0x30 }, // CFG_16 inv_set_footer
958 { 0x07, 0x46, 0x01, 0x9A }, // CFG_GYRO_SOURCE inv_send_gyro
959 { 0x07, 0x47, 0x04, 0xF1, 0x28, 0x30, 0x38 }, // CFG_9 inv_send_gyro -> inv_construct3_fifo
960 { 0x07, 0x6C, 0x04, 0xF1, 0x28, 0x30, 0x38 }, // CFG_12 inv_send_accel -> inv_construct3_fifo
961 { 0x02, 0x16, 0x02, 0x00, 0x0A } // D_0_22 inv_set_fifo_rate
966 #endif /* _MPU6050_H_ */