Segue

Fork of MPU6050 by Simon Garfieldsg

Committer:
Gaetios
Date:
Mon Oct 02 16:42:34 2017 +0000
Revision:
2:85734ad35573
foi alterado para utilizar 4 acelerometros

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gaetios 2:85734ad35573 1 //ported from arduino library: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050
Gaetios 2:85734ad35573 2 //written by szymon gaertig (email: szymon@gaertig.com.pl)
Gaetios 2:85734ad35573 3 //
Gaetios 2:85734ad35573 4 //Changelog:
Gaetios 2:85734ad35573 5 //2013-01-08 - first beta release
Gaetios 2:85734ad35573 6
Gaetios 2:85734ad35573 7 // I2Cdev library collection - MPU6050 I2C device class
Gaetios 2:85734ad35573 8 // Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
Gaetios 2:85734ad35573 9 // 8/24/2011 by Jeff Rowberg <jeff@rowberg.net>
Gaetios 2:85734ad35573 10 // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
Gaetios 2:85734ad35573 11 //
Gaetios 2:85734ad35573 12 // Changelog:
Gaetios 2:85734ad35573 13 // ... - ongoing debug release
Gaetios 2:85734ad35573 14
Gaetios 2:85734ad35573 15 // NOTE: THIS IS ONLY A PARIAL RELEASE. THIS DEVICE CLASS IS CURRENTLY UNDERGOING ACTIVE
Gaetios 2:85734ad35573 16 // DEVELOPMENT AND IS STILL MISSING SOME IMPORTANT FEATURES. PLEASE KEEP THIS IN MIND IF
Gaetios 2:85734ad35573 17 // YOU DECIDE TO USE THIS PARTICULAR CODE FOR ANYTHING.
Gaetios 2:85734ad35573 18
Gaetios 2:85734ad35573 19 /* ============================================
Gaetios 2:85734ad35573 20 I2Cdev device library code is placed under the MIT license
Gaetios 2:85734ad35573 21 Copyright (c) 2012 Jeff Rowberg
Gaetios 2:85734ad35573 22
Gaetios 2:85734ad35573 23 Permission is hereby granted, free of charge, to any person obtaining a copy
Gaetios 2:85734ad35573 24 of this software and associated documentation files (the "Software"), to deal
Gaetios 2:85734ad35573 25 in the Software without restriction, including without limitation the rights
Gaetios 2:85734ad35573 26 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Gaetios 2:85734ad35573 27 copies of the Software, and to permit persons to whom the Software is
Gaetios 2:85734ad35573 28 furnished to do so, subject to the following conditions:
Gaetios 2:85734ad35573 29
Gaetios 2:85734ad35573 30 The above copyright notice and this permission notice shall be included in
Gaetios 2:85734ad35573 31 all copies or substantial portions of the Software.
Gaetios 2:85734ad35573 32
Gaetios 2:85734ad35573 33 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Gaetios 2:85734ad35573 34 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Gaetios 2:85734ad35573 35 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Gaetios 2:85734ad35573 36 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Gaetios 2:85734ad35573 37 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Gaetios 2:85734ad35573 38 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Gaetios 2:85734ad35573 39 THE SOFTWARE.
Gaetios 2:85734ad35573 40 ===============================================
Gaetios 2:85734ad35573 41 */
Gaetios 2:85734ad35573 42
Gaetios 2:85734ad35573 43 #include "MPU60503.h"
Gaetios 2:85734ad35573 44
Gaetios 2:85734ad35573 45 #define useDebugSerial
Gaetios 2:85734ad35573 46
Gaetios 2:85734ad35573 47 //instead of using pgmspace.h
Gaetios 2:85734ad35573 48 typedef const unsigned char prog_uchar;
Gaetios 2:85734ad35573 49 #define pgm_read_byte_near(x) (*(prog_uchar*)x)
Gaetios 2:85734ad35573 50 #define pgm_read_byte(x) (*(prog_uchar*)x)
Gaetios 2:85734ad35573 51
Gaetios 2:85734ad35573 52 /** Default constructor, uses default I2C address.
Gaetios 2:85734ad35573 53 * @see MPU6050_DEFAULT_ADDRESS
Gaetios 2:85734ad35573 54 */
Gaetios 2:85734ad35573 55 MPU60503::MPU60503() : debugSerial(USBTX, USBRX)
Gaetios 2:85734ad35573 56 {
Gaetios 2:85734ad35573 57 devAddr = MPU6050_ADDRESS_AD0_HIGH;
Gaetios 2:85734ad35573 58 }
Gaetios 2:85734ad35573 59
Gaetios 2:85734ad35573 60 /** Specific address constructor.
Gaetios 2:85734ad35573 61 * @param address I2C address
Gaetios 2:85734ad35573 62 * @see MPU6050_DEFAULT_ADDRESS
Gaetios 2:85734ad35573 63 * @see MPU6050_ADDRESS_AD0_LOW
Gaetios 2:85734ad35573 64 * @see MPU6050_ADDRESS_AD0_HIGH
Gaetios 2:85734ad35573 65 */
Gaetios 2:85734ad35573 66 MPU60503::MPU60503(uint8_t address) : debugSerial(USBTX, USBRX)
Gaetios 2:85734ad35573 67 {
Gaetios 2:85734ad35573 68 devAddr = address;
Gaetios 2:85734ad35573 69 }
Gaetios 2:85734ad35573 70
Gaetios 2:85734ad35573 71 /** Power on and prepare for general usage.
Gaetios 2:85734ad35573 72 * This will activate the device and take it out of sleep mode (which must be done
Gaetios 2:85734ad35573 73 * after start-up). This function also sets both the accelerometer and the gyroscope
Gaetios 2:85734ad35573 74 * to their most sensitive settings, namely +/- 2g and +/- 250 degrees/sec, and sets
Gaetios 2:85734ad35573 75 * the clock source to use the X Gyro for reference, which is slightly better than
Gaetios 2:85734ad35573 76 * the default internal clock source.
Gaetios 2:85734ad35573 77 */
Gaetios 2:85734ad35573 78 void MPU60503::initialize()
Gaetios 2:85734ad35573 79 {
Gaetios 2:85734ad35573 80
Gaetios 2:85734ad35573 81 #ifdef useDebugSerial
Gaetios 2:85734ad35573 82 /// debugSerial.printf("MPU6050::initialize start\n");
Gaetios 2:85734ad35573 83 #endif
Gaetios 2:85734ad35573 84
Gaetios 2:85734ad35573 85 setClockSource(MPU6050_CLOCK_PLL_XGYRO);
Gaetios 2:85734ad35573 86 setFullScaleGyroRange(MPU6050_GYRO_FS_250);
Gaetios 2:85734ad35573 87 setFullScaleAccelRange(MPU6050_ACCEL_FS_2);
Gaetios 2:85734ad35573 88 setSleepEnabled(false); // thanks to Jack Elston for pointing this one out!
Gaetios 2:85734ad35573 89
Gaetios 2:85734ad35573 90 #ifdef useDebugSerial
Gaetios 2:85734ad35573 91 // debugSerial.printf("MPU6050::initialize end\n");
Gaetios 2:85734ad35573 92 #endif
Gaetios 2:85734ad35573 93 }
Gaetios 2:85734ad35573 94
Gaetios 2:85734ad35573 95 /** Verify the I2C connection.
Gaetios 2:85734ad35573 96 * Make sure the device is connected and responds as expected.
Gaetios 2:85734ad35573 97 * @return True if connection is valid, false otherwise
Gaetios 2:85734ad35573 98 */
Gaetios 2:85734ad35573 99 bool MPU60503::testConnection()
Gaetios 2:85734ad35573 100 {
Gaetios 2:85734ad35573 101 #ifdef useDebugSerial
Gaetios 2:85734ad35573 102 debugSerial.printf("MPU6050::testConnection start\n");
Gaetios 2:85734ad35573 103 #endif
Gaetios 2:85734ad35573 104 uint8_t deviceId = getDeviceID();
Gaetios 2:85734ad35573 105 #ifdef useDebugSerial
Gaetios 2:85734ad35573 106 debugSerial.printf("DeviceId = %d\n",deviceId);
Gaetios 2:85734ad35573 107 #endif
Gaetios 2:85734ad35573 108 return deviceId == 0x34;
Gaetios 2:85734ad35573 109 }
Gaetios 2:85734ad35573 110
Gaetios 2:85734ad35573 111 // AUX_VDDIO register (InvenSense demo code calls this RA_*G_OFFS_TC)
Gaetios 2:85734ad35573 112
Gaetios 2:85734ad35573 113 /** Get the auxiliary I2C supply voltage level.
Gaetios 2:85734ad35573 114 * When set to 1, the auxiliary I2C bus high logic level is VDD. When cleared to
Gaetios 2:85734ad35573 115 * 0, the auxiliary I2C bus high logic level is VLOGIC. This does not apply to
Gaetios 2:85734ad35573 116 * the MPU-6000, which does not have a VLOGIC pin.
Gaetios 2:85734ad35573 117 * @return I2C supply voltage level (0=VLOGIC, 1=VDD)
Gaetios 2:85734ad35573 118 */
Gaetios 2:85734ad35573 119 uint8_t MPU60503::getAuxVDDIOLevel()
Gaetios 2:85734ad35573 120 {
Gaetios 2:85734ad35573 121 i2Cdev.readBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, buffer);
Gaetios 2:85734ad35573 122 return buffer[0];
Gaetios 2:85734ad35573 123 }
Gaetios 2:85734ad35573 124 /** Set the auxiliary I2C supply voltage level.
Gaetios 2:85734ad35573 125 * When set to 1, the auxiliary I2C bus high logic level is VDD. When cleared to
Gaetios 2:85734ad35573 126 * 0, the auxiliary I2C bus high logic level is VLOGIC. This does not apply to
Gaetios 2:85734ad35573 127 * the MPU-6000, which does not have a VLOGIC pin.
Gaetios 2:85734ad35573 128 * @param level I2C supply voltage level (0=VLOGIC, 1=VDD)
Gaetios 2:85734ad35573 129 */
Gaetios 2:85734ad35573 130 void MPU60503::setAuxVDDIOLevel(uint8_t level)
Gaetios 2:85734ad35573 131 {
Gaetios 2:85734ad35573 132 i2Cdev.writeBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, level);
Gaetios 2:85734ad35573 133 }
Gaetios 2:85734ad35573 134
Gaetios 2:85734ad35573 135 // SMPLRT_DIV register
Gaetios 2:85734ad35573 136
Gaetios 2:85734ad35573 137 /** Get gyroscope output rate divider.
Gaetios 2:85734ad35573 138 * The sensor register output, FIFO output, DMP sampling, Motion detection, Zero
Gaetios 2:85734ad35573 139 * Motion detection, and Free Fall detection are all based on the Sample Rate.
Gaetios 2:85734ad35573 140 * The Sample Rate is generated by dividing the gyroscope output rate by
Gaetios 2:85734ad35573 141 * SMPLRT_DIV:
Gaetios 2:85734ad35573 142 *
Gaetios 2:85734ad35573 143 * Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)
Gaetios 2:85734ad35573 144 *
Gaetios 2:85734ad35573 145 * where Gyroscope Output Rate = 8kHz when the DLPF is disabled (DLPF_CFG = 0 or
Gaetios 2:85734ad35573 146 * 7), and 1kHz when the DLPF is enabled (see Register 26).
Gaetios 2:85734ad35573 147 *
Gaetios 2:85734ad35573 148 * Note: The accelerometer output rate is 1kHz. This means that for a Sample
Gaetios 2:85734ad35573 149 * Rate greater than 1kHz, the same accelerometer sample may be output to the
Gaetios 2:85734ad35573 150 * FIFO, DMP, and sensor registers more than once.
Gaetios 2:85734ad35573 151 *
Gaetios 2:85734ad35573 152 * For a diagram of the gyroscope and accelerometer signal paths, see Section 8
Gaetios 2:85734ad35573 153 * of the MPU-6000/MPU-6050 Product Specification document.
Gaetios 2:85734ad35573 154 *
Gaetios 2:85734ad35573 155 * @return Current sample rate
Gaetios 2:85734ad35573 156 * @see MPU6050_RA_SMPLRT_DIV
Gaetios 2:85734ad35573 157 */
Gaetios 2:85734ad35573 158 uint8_t MPU60503::getRate()
Gaetios 2:85734ad35573 159 {
Gaetios 2:85734ad35573 160 i2Cdev.readByte(devAddr, MPU6050_RA_SMPLRT_DIV, buffer);
Gaetios 2:85734ad35573 161 return buffer[0];
Gaetios 2:85734ad35573 162 }
Gaetios 2:85734ad35573 163 /** Set gyroscope sample rate divider.
Gaetios 2:85734ad35573 164 * @param rate New sample rate divider
Gaetios 2:85734ad35573 165 * @see getRate()
Gaetios 2:85734ad35573 166 * @see MPU6050_RA_SMPLRT_DIV
Gaetios 2:85734ad35573 167 */
Gaetios 2:85734ad35573 168 void MPU60503::setRate(uint8_t rate)
Gaetios 2:85734ad35573 169 {
Gaetios 2:85734ad35573 170 i2Cdev.writeByte(devAddr, MPU6050_RA_SMPLRT_DIV, rate);
Gaetios 2:85734ad35573 171 }
Gaetios 2:85734ad35573 172
Gaetios 2:85734ad35573 173 // CONFIG register
Gaetios 2:85734ad35573 174
Gaetios 2:85734ad35573 175 /** Get external FSYNC configuration.
Gaetios 2:85734ad35573 176 * Configures the external Frame Synchronization (FSYNC) pin sampling. An
Gaetios 2:85734ad35573 177 * external signal connected to the FSYNC pin can be sampled by configuring
Gaetios 2:85734ad35573 178 * EXT_SYNC_SET. Signal changes to the FSYNC pin are latched so that short
Gaetios 2:85734ad35573 179 * strobes may be captured. The latched FSYNC signal will be sampled at the
Gaetios 2:85734ad35573 180 * Sampling Rate, as defined in register 25. After sampling, the latch will
Gaetios 2:85734ad35573 181 * reset to the current FSYNC signal state.
Gaetios 2:85734ad35573 182 *
Gaetios 2:85734ad35573 183 * The sampled value will be reported in place of the least significant bit in
Gaetios 2:85734ad35573 184 * a sensor data register determined by the value of EXT_SYNC_SET according to
Gaetios 2:85734ad35573 185 * the following table.
Gaetios 2:85734ad35573 186 *
Gaetios 2:85734ad35573 187 * <pre>
Gaetios 2:85734ad35573 188 * EXT_SYNC_SET | FSYNC Bit Location
Gaetios 2:85734ad35573 189 * -------------+-------------------
Gaetios 2:85734ad35573 190 * 0 | Input disabled
Gaetios 2:85734ad35573 191 * 1 | TEMP_OUT_L[0]
Gaetios 2:85734ad35573 192 * 2 | GYRO_XOUT_L[0]
Gaetios 2:85734ad35573 193 * 3 | GYRO_YOUT_L[0]
Gaetios 2:85734ad35573 194 * 4 | GYRO_ZOUT_L[0]
Gaetios 2:85734ad35573 195 * 5 | ACCEL_XOUT_L[0]
Gaetios 2:85734ad35573 196 * 6 | ACCEL_YOUT_L[0]
Gaetios 2:85734ad35573 197 * 7 | ACCEL_ZOUT_L[0]
Gaetios 2:85734ad35573 198 * </pre>
Gaetios 2:85734ad35573 199 *
Gaetios 2:85734ad35573 200 * @return FSYNC configuration value
Gaetios 2:85734ad35573 201 */
Gaetios 2:85734ad35573 202 uint8_t MPU60503::getExternalFrameSync()
Gaetios 2:85734ad35573 203 {
Gaetios 2:85734ad35573 204 i2Cdev.readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, buffer);
Gaetios 2:85734ad35573 205 return buffer[0];
Gaetios 2:85734ad35573 206 }
Gaetios 2:85734ad35573 207 /** Set external FSYNC configuration.
Gaetios 2:85734ad35573 208 * @see getExternalFrameSync()
Gaetios 2:85734ad35573 209 * @see MPU6050_RA_CONFIG
Gaetios 2:85734ad35573 210 * @param sync New FSYNC configuration value
Gaetios 2:85734ad35573 211 */
Gaetios 2:85734ad35573 212 void MPU60503::setExternalFrameSync(uint8_t sync)
Gaetios 2:85734ad35573 213 {
Gaetios 2:85734ad35573 214 i2Cdev.writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, sync);
Gaetios 2:85734ad35573 215 }
Gaetios 2:85734ad35573 216 /** Get digital low-pass filter configuration.
Gaetios 2:85734ad35573 217 * The DLPF_CFG parameter sets the digital low pass filter configuration. It
Gaetios 2:85734ad35573 218 * also determines the internal sampling rate used by the device as shown in
Gaetios 2:85734ad35573 219 * the table below.
Gaetios 2:85734ad35573 220 *
Gaetios 2:85734ad35573 221 * Note: The accelerometer output rate is 1kHz. This means that for a Sample
Gaetios 2:85734ad35573 222 * Rate greater than 1kHz, the same accelerometer sample may be output to the
Gaetios 2:85734ad35573 223 * FIFO, DMP, and sensor registers more than once.
Gaetios 2:85734ad35573 224 *
Gaetios 2:85734ad35573 225 * <pre>
Gaetios 2:85734ad35573 226 * | ACCELEROMETER | GYROSCOPE
Gaetios 2:85734ad35573 227 * DLPF_CFG | Bandwidth | Delay | Bandwidth | Delay | Sample Rate
Gaetios 2:85734ad35573 228 * ---------+-----------+--------+-----------+--------+-------------
Gaetios 2:85734ad35573 229 * 0 | 260Hz | 0ms | 256Hz | 0.98ms | 8kHz
Gaetios 2:85734ad35573 230 * 1 | 184Hz | 2.0ms | 188Hz | 1.9ms | 1kHz
Gaetios 2:85734ad35573 231 * 2 | 94Hz | 3.0ms | 98Hz | 2.8ms | 1kHz
Gaetios 2:85734ad35573 232 * 3 | 44Hz | 4.9ms | 42Hz | 4.8ms | 1kHz
Gaetios 2:85734ad35573 233 * 4 | 21Hz | 8.5ms | 20Hz | 8.3ms | 1kHz
Gaetios 2:85734ad35573 234 * 5 | 10Hz | 13.8ms | 10Hz | 13.4ms | 1kHz
Gaetios 2:85734ad35573 235 * 6 | 5Hz | 19.0ms | 5Hz | 18.6ms | 1kHz
Gaetios 2:85734ad35573 236 * 7 | -- Reserved -- | -- Reserved -- | Reserved
Gaetios 2:85734ad35573 237 * </pre>
Gaetios 2:85734ad35573 238 *
Gaetios 2:85734ad35573 239 * @return DLFP configuration
Gaetios 2:85734ad35573 240 * @see MPU6050_RA_CONFIG
Gaetios 2:85734ad35573 241 * @see MPU6050_CFG_DLPF_CFG_BIT
Gaetios 2:85734ad35573 242 * @see MPU6050_CFG_DLPF_CFG_LENGTH
Gaetios 2:85734ad35573 243 */
Gaetios 2:85734ad35573 244 uint8_t MPU60503::getDLPFMode()
Gaetios 2:85734ad35573 245 {
Gaetios 2:85734ad35573 246 i2Cdev.readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, buffer);
Gaetios 2:85734ad35573 247 return buffer[0];
Gaetios 2:85734ad35573 248 }
Gaetios 2:85734ad35573 249 /** Set digital low-pass filter configuration.
Gaetios 2:85734ad35573 250 * @param mode New DLFP configuration setting
Gaetios 2:85734ad35573 251 * @see getDLPFBandwidth()
Gaetios 2:85734ad35573 252 * @see MPU6050_DLPF_BW_256
Gaetios 2:85734ad35573 253 * @see MPU6050_RA_CONFIG
Gaetios 2:85734ad35573 254 * @see MPU6050_CFG_DLPF_CFG_BIT
Gaetios 2:85734ad35573 255 * @see MPU6050_CFG_DLPF_CFG_LENGTH
Gaetios 2:85734ad35573 256 */
Gaetios 2:85734ad35573 257 void MPU60503::setDLPFMode(uint8_t mode)
Gaetios 2:85734ad35573 258 {
Gaetios 2:85734ad35573 259 i2Cdev.writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, mode);
Gaetios 2:85734ad35573 260 }
Gaetios 2:85734ad35573 261
Gaetios 2:85734ad35573 262 // GYRO_CONFIG register
Gaetios 2:85734ad35573 263
Gaetios 2:85734ad35573 264 /** Get full-scale gyroscope range.
Gaetios 2:85734ad35573 265 * The FS_SEL parameter allows setting the full-scale range of the gyro sensors,
Gaetios 2:85734ad35573 266 * as described in the table below.
Gaetios 2:85734ad35573 267 *
Gaetios 2:85734ad35573 268 * <pre>
Gaetios 2:85734ad35573 269 * 0 = +/- 250 degrees/sec
Gaetios 2:85734ad35573 270 * 1 = +/- 500 degrees/sec
Gaetios 2:85734ad35573 271 * 2 = +/- 1000 degrees/sec
Gaetios 2:85734ad35573 272 * 3 = +/- 2000 degrees/sec
Gaetios 2:85734ad35573 273 * </pre>
Gaetios 2:85734ad35573 274 *
Gaetios 2:85734ad35573 275 * @return Current full-scale gyroscope range setting
Gaetios 2:85734ad35573 276 * @see MPU6050_GYRO_FS_250
Gaetios 2:85734ad35573 277 * @see MPU6050_RA_GYRO_CONFIG
Gaetios 2:85734ad35573 278 * @see MPU6050_GCONFIG_FS_SEL_BIT
Gaetios 2:85734ad35573 279 * @see MPU6050_GCONFIG_FS_SEL_LENGTH
Gaetios 2:85734ad35573 280 */
Gaetios 2:85734ad35573 281 uint8_t MPU60503::getFullScaleGyroRange()
Gaetios 2:85734ad35573 282 {
Gaetios 2:85734ad35573 283 i2Cdev.readBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, buffer);
Gaetios 2:85734ad35573 284 return buffer[0];
Gaetios 2:85734ad35573 285 }
Gaetios 2:85734ad35573 286 /** Set full-scale gyroscope range.
Gaetios 2:85734ad35573 287 * @param range New full-scale gyroscope range value
Gaetios 2:85734ad35573 288 * @see getFullScaleRange()
Gaetios 2:85734ad35573 289 * @see MPU6050_GYRO_FS_250
Gaetios 2:85734ad35573 290 * @see MPU6050_RA_GYRO_CONFIG
Gaetios 2:85734ad35573 291 * @see MPU6050_GCONFIG_FS_SEL_BIT
Gaetios 2:85734ad35573 292 * @see MPU6050_GCONFIG_FS_SEL_LENGTH
Gaetios 2:85734ad35573 293 */
Gaetios 2:85734ad35573 294 void MPU60503::setFullScaleGyroRange(uint8_t range)
Gaetios 2:85734ad35573 295 {
Gaetios 2:85734ad35573 296 i2Cdev.writeBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, range);
Gaetios 2:85734ad35573 297 }
Gaetios 2:85734ad35573 298
Gaetios 2:85734ad35573 299 // ACCEL_CONFIG register
Gaetios 2:85734ad35573 300
Gaetios 2:85734ad35573 301 /** Get self-test enabled setting for accelerometer X axis.
Gaetios 2:85734ad35573 302 * @return Self-test enabled value
Gaetios 2:85734ad35573 303 * @see MPU6050_RA_ACCEL_CONFIG
Gaetios 2:85734ad35573 304 */
Gaetios 2:85734ad35573 305 bool MPU60503::getAccelXSelfTest()
Gaetios 2:85734ad35573 306 {
Gaetios 2:85734ad35573 307 i2Cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, buffer);
Gaetios 2:85734ad35573 308 return buffer[0];
Gaetios 2:85734ad35573 309 }
Gaetios 2:85734ad35573 310 /** Get self-test enabled setting for accelerometer X axis.
Gaetios 2:85734ad35573 311 * @param enabled Self-test enabled value
Gaetios 2:85734ad35573 312 * @see MPU6050_RA_ACCEL_CONFIG
Gaetios 2:85734ad35573 313 */
Gaetios 2:85734ad35573 314 void MPU60503::setAccelXSelfTest(bool enabled)
Gaetios 2:85734ad35573 315 {
Gaetios 2:85734ad35573 316 i2Cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, enabled);
Gaetios 2:85734ad35573 317 }
Gaetios 2:85734ad35573 318 /** Get self-test enabled value for accelerometer Y axis.
Gaetios 2:85734ad35573 319 * @return Self-test enabled value
Gaetios 2:85734ad35573 320 * @see MPU6050_RA_ACCEL_CONFIG
Gaetios 2:85734ad35573 321 */
Gaetios 2:85734ad35573 322 bool MPU60503::getAccelYSelfTest()
Gaetios 2:85734ad35573 323 {
Gaetios 2:85734ad35573 324 i2Cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, buffer);
Gaetios 2:85734ad35573 325 return buffer[0];
Gaetios 2:85734ad35573 326 }
Gaetios 2:85734ad35573 327 /** Get self-test enabled value for accelerometer Y axis.
Gaetios 2:85734ad35573 328 * @param enabled Self-test enabled value
Gaetios 2:85734ad35573 329 * @see MPU6050_RA_ACCEL_CONFIG
Gaetios 2:85734ad35573 330 */
Gaetios 2:85734ad35573 331 void MPU60503::setAccelYSelfTest(bool enabled)
Gaetios 2:85734ad35573 332 {
Gaetios 2:85734ad35573 333 i2Cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, enabled);
Gaetios 2:85734ad35573 334 }
Gaetios 2:85734ad35573 335 /** Get self-test enabled value for accelerometer Z axis.
Gaetios 2:85734ad35573 336 * @return Self-test enabled value
Gaetios 2:85734ad35573 337 * @see MPU6050_RA_ACCEL_CONFIG
Gaetios 2:85734ad35573 338 */
Gaetios 2:85734ad35573 339 bool MPU60503::getAccelZSelfTest()
Gaetios 2:85734ad35573 340 {
Gaetios 2:85734ad35573 341 i2Cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, buffer);
Gaetios 2:85734ad35573 342 return buffer[0];
Gaetios 2:85734ad35573 343 }
Gaetios 2:85734ad35573 344 /** Set self-test enabled value for accelerometer Z axis.
Gaetios 2:85734ad35573 345 * @param enabled Self-test enabled value
Gaetios 2:85734ad35573 346 * @see MPU6050_RA_ACCEL_CONFIG
Gaetios 2:85734ad35573 347 */
Gaetios 2:85734ad35573 348 void MPU60503::setAccelZSelfTest(bool enabled)
Gaetios 2:85734ad35573 349 {
Gaetios 2:85734ad35573 350 i2Cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, enabled);
Gaetios 2:85734ad35573 351 }
Gaetios 2:85734ad35573 352 /** Get full-scale accelerometer range.
Gaetios 2:85734ad35573 353 * The FS_SEL parameter allows setting the full-scale range of the accelerometer
Gaetios 2:85734ad35573 354 * sensors, as described in the table below.
Gaetios 2:85734ad35573 355 *
Gaetios 2:85734ad35573 356 * <pre>
Gaetios 2:85734ad35573 357 * 0 = +/- 2g
Gaetios 2:85734ad35573 358 * 1 = +/- 4g
Gaetios 2:85734ad35573 359 * 2 = +/- 8g
Gaetios 2:85734ad35573 360 * 3 = +/- 16g
Gaetios 2:85734ad35573 361 * </pre>
Gaetios 2:85734ad35573 362 *
Gaetios 2:85734ad35573 363 * @return Current full-scale accelerometer range setting
Gaetios 2:85734ad35573 364 * @see MPU6050_ACCEL_FS_2
Gaetios 2:85734ad35573 365 * @see MPU6050_RA_ACCEL_CONFIG
Gaetios 2:85734ad35573 366 * @see MPU6050_ACONFIG_AFS_SEL_BIT
Gaetios 2:85734ad35573 367 * @see MPU6050_ACONFIG_AFS_SEL_LENGTH
Gaetios 2:85734ad35573 368 */
Gaetios 2:85734ad35573 369 uint8_t MPU60503::getFullScaleAccelRange()
Gaetios 2:85734ad35573 370 {
Gaetios 2:85734ad35573 371 i2Cdev.readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, buffer);
Gaetios 2:85734ad35573 372 return buffer[0];
Gaetios 2:85734ad35573 373 }
Gaetios 2:85734ad35573 374 /** Set full-scale accelerometer range.
Gaetios 2:85734ad35573 375 * @param range New full-scale accelerometer range setting
Gaetios 2:85734ad35573 376 * @see getFullScaleAccelRange()
Gaetios 2:85734ad35573 377 */
Gaetios 2:85734ad35573 378 void MPU60503::setFullScaleAccelRange(uint8_t range)
Gaetios 2:85734ad35573 379 {
Gaetios 2:85734ad35573 380 i2Cdev.writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, range);
Gaetios 2:85734ad35573 381 }
Gaetios 2:85734ad35573 382 /** Get the high-pass filter configuration.
Gaetios 2:85734ad35573 383 * The DHPF is a filter module in the path leading to motion detectors (Free
Gaetios 2:85734ad35573 384 * Fall, Motion threshold, and Zero Motion). The high pass filter output is not
Gaetios 2:85734ad35573 385 * available to the data registers (see Figure in Section 8 of the MPU-6000/
Gaetios 2:85734ad35573 386 * MPU-6050 Product Specification document).
Gaetios 2:85734ad35573 387 *
Gaetios 2:85734ad35573 388 * The high pass filter has three modes:
Gaetios 2:85734ad35573 389 *
Gaetios 2:85734ad35573 390 * <pre>
Gaetios 2:85734ad35573 391 * Reset: The filter output settles to zero within one sample. This
Gaetios 2:85734ad35573 392 * effectively disables the high pass filter. This mode may be toggled
Gaetios 2:85734ad35573 393 * to quickly settle the filter.
Gaetios 2:85734ad35573 394 *
Gaetios 2:85734ad35573 395 * On: The high pass filter will pass signals above the cut off frequency.
Gaetios 2:85734ad35573 396 *
Gaetios 2:85734ad35573 397 * Hold: When triggered, the filter holds the present sample. The filter
Gaetios 2:85734ad35573 398 * output will be the difference between the input sample and the held
Gaetios 2:85734ad35573 399 * sample.
Gaetios 2:85734ad35573 400 * </pre>
Gaetios 2:85734ad35573 401 *
Gaetios 2:85734ad35573 402 * <pre>
Gaetios 2:85734ad35573 403 * ACCEL_HPF | Filter Mode | Cut-off Frequency
Gaetios 2:85734ad35573 404 * ----------+-------------+------------------
Gaetios 2:85734ad35573 405 * 0 | Reset | None
Gaetios 2:85734ad35573 406 * 1 | On | 5Hz
Gaetios 2:85734ad35573 407 * 2 | On | 2.5Hz
Gaetios 2:85734ad35573 408 * 3 | On | 1.25Hz
Gaetios 2:85734ad35573 409 * 4 | On | 0.63Hz
Gaetios 2:85734ad35573 410 * 7 | Hold | None
Gaetios 2:85734ad35573 411 * </pre>
Gaetios 2:85734ad35573 412 *
Gaetios 2:85734ad35573 413 * @return Current high-pass filter configuration
Gaetios 2:85734ad35573 414 * @see MPU6050_DHPF_RESET
Gaetios 2:85734ad35573 415 * @see MPU6050_RA_ACCEL_CONFIG
Gaetios 2:85734ad35573 416 */
Gaetios 2:85734ad35573 417 uint8_t MPU60503::getDHPFMode()
Gaetios 2:85734ad35573 418 {
Gaetios 2:85734ad35573 419 i2Cdev.readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, buffer);
Gaetios 2:85734ad35573 420 return buffer[0];
Gaetios 2:85734ad35573 421 }
Gaetios 2:85734ad35573 422 /** Set the high-pass filter configuration.
Gaetios 2:85734ad35573 423 * @param bandwidth New high-pass filter configuration
Gaetios 2:85734ad35573 424 * @see setDHPFMode()
Gaetios 2:85734ad35573 425 * @see MPU6050_DHPF_RESET
Gaetios 2:85734ad35573 426 * @see MPU6050_RA_ACCEL_CONFIG
Gaetios 2:85734ad35573 427 */
Gaetios 2:85734ad35573 428 void MPU60503::setDHPFMode(uint8_t bandwidth)
Gaetios 2:85734ad35573 429 {
Gaetios 2:85734ad35573 430 i2Cdev.writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, bandwidth);
Gaetios 2:85734ad35573 431 }
Gaetios 2:85734ad35573 432
Gaetios 2:85734ad35573 433 // FF_THR register
Gaetios 2:85734ad35573 434
Gaetios 2:85734ad35573 435 /** Get free-fall event acceleration threshold.
Gaetios 2:85734ad35573 436 * This register configures the detection threshold for Free Fall event
Gaetios 2:85734ad35573 437 * detection. The unit of FF_THR is 1LSB = 2mg. Free Fall is detected when the
Gaetios 2:85734ad35573 438 * absolute value of the accelerometer measurements for the three axes are each
Gaetios 2:85734ad35573 439 * less than the detection threshold. This condition increments the Free Fall
Gaetios 2:85734ad35573 440 * duration counter (Register 30). The Free Fall interrupt is triggered when the
Gaetios 2:85734ad35573 441 * Free Fall duration counter reaches the time specified in FF_DUR.
Gaetios 2:85734ad35573 442 *
Gaetios 2:85734ad35573 443 * For more details on the Free Fall detection interrupt, see Section 8.2 of the
Gaetios 2:85734ad35573 444 * MPU-6000/MPU-6050 Product Specification document as well as Registers 56 and
Gaetios 2:85734ad35573 445 * 58 of this document.
Gaetios 2:85734ad35573 446 *
Gaetios 2:85734ad35573 447 * @return Current free-fall acceleration threshold value (LSB = 2mg)
Gaetios 2:85734ad35573 448 * @see MPU6050_RA_FF_THR
Gaetios 2:85734ad35573 449 */
Gaetios 2:85734ad35573 450 uint8_t MPU60503::getFreefallDetectionThreshold()
Gaetios 2:85734ad35573 451 {
Gaetios 2:85734ad35573 452 i2Cdev.readByte(devAddr, MPU6050_RA_FF_THR, buffer);
Gaetios 2:85734ad35573 453 return buffer[0];
Gaetios 2:85734ad35573 454 }
Gaetios 2:85734ad35573 455 /** Get free-fall event acceleration threshold.
Gaetios 2:85734ad35573 456 * @param threshold New free-fall acceleration threshold value (LSB = 2mg)
Gaetios 2:85734ad35573 457 * @see getFreefallDetectionThreshold()
Gaetios 2:85734ad35573 458 * @see MPU6050_RA_FF_THR
Gaetios 2:85734ad35573 459 */
Gaetios 2:85734ad35573 460 void MPU60503::setFreefallDetectionThreshold(uint8_t threshold)
Gaetios 2:85734ad35573 461 {
Gaetios 2:85734ad35573 462 i2Cdev.writeByte(devAddr, MPU6050_RA_FF_THR, threshold);
Gaetios 2:85734ad35573 463 }
Gaetios 2:85734ad35573 464
Gaetios 2:85734ad35573 465 // FF_DUR register
Gaetios 2:85734ad35573 466
Gaetios 2:85734ad35573 467 /** Get free-fall event duration threshold.
Gaetios 2:85734ad35573 468 * This register configures the duration counter threshold for Free Fall event
Gaetios 2:85734ad35573 469 * detection. The duration counter ticks at 1kHz, therefore FF_DUR has a unit
Gaetios 2:85734ad35573 470 * of 1 LSB = 1 ms.
Gaetios 2:85734ad35573 471 *
Gaetios 2:85734ad35573 472 * The Free Fall duration counter increments while the absolute value of the
Gaetios 2:85734ad35573 473 * accelerometer measurements are each less than the detection threshold
Gaetios 2:85734ad35573 474 * (Register 29). The Free Fall interrupt is triggered when the Free Fall
Gaetios 2:85734ad35573 475 * duration counter reaches the time specified in this register.
Gaetios 2:85734ad35573 476 *
Gaetios 2:85734ad35573 477 * For more details on the Free Fall detection interrupt, see Section 8.2 of
Gaetios 2:85734ad35573 478 * the MPU-6000/MPU-6050 Product Specification document as well as Registers 56
Gaetios 2:85734ad35573 479 * and 58 of this document.
Gaetios 2:85734ad35573 480 *
Gaetios 2:85734ad35573 481 * @return Current free-fall duration threshold value (LSB = 1ms)
Gaetios 2:85734ad35573 482 * @see MPU6050_RA_FF_DUR
Gaetios 2:85734ad35573 483 */
Gaetios 2:85734ad35573 484 uint8_t MPU60503::getFreefallDetectionDuration()
Gaetios 2:85734ad35573 485 {
Gaetios 2:85734ad35573 486 i2Cdev.readByte(devAddr, MPU6050_RA_FF_DUR, buffer);
Gaetios 2:85734ad35573 487 return buffer[0];
Gaetios 2:85734ad35573 488 }
Gaetios 2:85734ad35573 489 /** Get free-fall event duration threshold.
Gaetios 2:85734ad35573 490 * @param duration New free-fall duration threshold value (LSB = 1ms)
Gaetios 2:85734ad35573 491 * @see getFreefallDetectionDuration()
Gaetios 2:85734ad35573 492 * @see MPU6050_RA_FF_DUR
Gaetios 2:85734ad35573 493 */
Gaetios 2:85734ad35573 494 void MPU60503::setFreefallDetectionDuration(uint8_t duration)
Gaetios 2:85734ad35573 495 {
Gaetios 2:85734ad35573 496 i2Cdev.writeByte(devAddr, MPU6050_RA_FF_DUR, duration);
Gaetios 2:85734ad35573 497 }
Gaetios 2:85734ad35573 498
Gaetios 2:85734ad35573 499 // MOT_THR register
Gaetios 2:85734ad35573 500
Gaetios 2:85734ad35573 501 /** Get motion detection event acceleration threshold.
Gaetios 2:85734ad35573 502 * This register configures the detection threshold for Motion interrupt
Gaetios 2:85734ad35573 503 * generation. The unit of MOT_THR is 1LSB = 2mg. Motion is detected when the
Gaetios 2:85734ad35573 504 * absolute value of any of the accelerometer measurements exceeds this Motion
Gaetios 2:85734ad35573 505 * detection threshold. This condition increments the Motion detection duration
Gaetios 2:85734ad35573 506 * counter (Register 32). The Motion detection interrupt is triggered when the
Gaetios 2:85734ad35573 507 * Motion Detection counter reaches the time count specified in MOT_DUR
Gaetios 2:85734ad35573 508 * (Register 32).
Gaetios 2:85734ad35573 509 *
Gaetios 2:85734ad35573 510 * The Motion interrupt will indicate the axis and polarity of detected motion
Gaetios 2:85734ad35573 511 * in MOT_DETECT_STATUS (Register 97).
Gaetios 2:85734ad35573 512 *
Gaetios 2:85734ad35573 513 * For more details on the Motion detection interrupt, see Section 8.3 of the
Gaetios 2:85734ad35573 514 * MPU-6000/MPU-6050 Product Specification document as well as Registers 56 and
Gaetios 2:85734ad35573 515 * 58 of this document.
Gaetios 2:85734ad35573 516 *
Gaetios 2:85734ad35573 517 * @return Current motion detection acceleration threshold value (LSB = 2mg)
Gaetios 2:85734ad35573 518 * @see MPU6050_RA_MOT_THR
Gaetios 2:85734ad35573 519 */
Gaetios 2:85734ad35573 520 uint8_t MPU60503::getMotionDetectionThreshold()
Gaetios 2:85734ad35573 521 {
Gaetios 2:85734ad35573 522 i2Cdev.readByte(devAddr, MPU6050_RA_MOT_THR, buffer);
Gaetios 2:85734ad35573 523 return buffer[0];
Gaetios 2:85734ad35573 524 }
Gaetios 2:85734ad35573 525 /** Set free-fall event acceleration threshold.
Gaetios 2:85734ad35573 526 * @param threshold New motion detection acceleration threshold value (LSB = 2mg)
Gaetios 2:85734ad35573 527 * @see getMotionDetectionThreshold()
Gaetios 2:85734ad35573 528 * @see MPU6050_RA_MOT_THR
Gaetios 2:85734ad35573 529 */
Gaetios 2:85734ad35573 530 void MPU60503::setMotionDetectionThreshold(uint8_t threshold)
Gaetios 2:85734ad35573 531 {
Gaetios 2:85734ad35573 532 i2Cdev.writeByte(devAddr, MPU6050_RA_MOT_THR, threshold);
Gaetios 2:85734ad35573 533 }
Gaetios 2:85734ad35573 534
Gaetios 2:85734ad35573 535 // MOT_DUR register
Gaetios 2:85734ad35573 536
Gaetios 2:85734ad35573 537 /** Get motion detection event duration threshold.
Gaetios 2:85734ad35573 538 * This register configures the duration counter threshold for Motion interrupt
Gaetios 2:85734ad35573 539 * generation. The duration counter ticks at 1 kHz, therefore MOT_DUR has a unit
Gaetios 2:85734ad35573 540 * of 1LSB = 1ms. The Motion detection duration counter increments when the
Gaetios 2:85734ad35573 541 * absolute value of any of the accelerometer measurements exceeds the Motion
Gaetios 2:85734ad35573 542 * detection threshold (Register 31). The Motion detection interrupt is
Gaetios 2:85734ad35573 543 * triggered when the Motion detection counter reaches the time count specified
Gaetios 2:85734ad35573 544 * in this register.
Gaetios 2:85734ad35573 545 *
Gaetios 2:85734ad35573 546 * For more details on the Motion detection interrupt, see Section 8.3 of the
Gaetios 2:85734ad35573 547 * MPU-6000/MPU-6050 Product Specification document.
Gaetios 2:85734ad35573 548 *
Gaetios 2:85734ad35573 549 * @return Current motion detection duration threshold value (LSB = 1ms)
Gaetios 2:85734ad35573 550 * @see MPU6050_RA_MOT_DUR
Gaetios 2:85734ad35573 551 */
Gaetios 2:85734ad35573 552 uint8_t MPU60503::getMotionDetectionDuration()
Gaetios 2:85734ad35573 553 {
Gaetios 2:85734ad35573 554 i2Cdev.readByte(devAddr, MPU6050_RA_MOT_DUR, buffer);
Gaetios 2:85734ad35573 555 return buffer[0];
Gaetios 2:85734ad35573 556 }
Gaetios 2:85734ad35573 557 /** Set motion detection event duration threshold.
Gaetios 2:85734ad35573 558 * @param duration New motion detection duration threshold value (LSB = 1ms)
Gaetios 2:85734ad35573 559 * @see getMotionDetectionDuration()
Gaetios 2:85734ad35573 560 * @see MPU6050_RA_MOT_DUR
Gaetios 2:85734ad35573 561 */
Gaetios 2:85734ad35573 562 void MPU60503::setMotionDetectionDuration(uint8_t duration)
Gaetios 2:85734ad35573 563 {
Gaetios 2:85734ad35573 564 i2Cdev.writeByte(devAddr, MPU6050_RA_MOT_DUR, duration);
Gaetios 2:85734ad35573 565 }
Gaetios 2:85734ad35573 566
Gaetios 2:85734ad35573 567 // ZRMOT_THR register
Gaetios 2:85734ad35573 568
Gaetios 2:85734ad35573 569 /** Get zero motion detection event acceleration threshold.
Gaetios 2:85734ad35573 570 * This register configures the detection threshold for Zero Motion interrupt
Gaetios 2:85734ad35573 571 * generation. The unit of ZRMOT_THR is 1LSB = 2mg. Zero Motion is detected when
Gaetios 2:85734ad35573 572 * the absolute value of the accelerometer measurements for the 3 axes are each
Gaetios 2:85734ad35573 573 * less than the detection threshold. This condition increments the Zero Motion
Gaetios 2:85734ad35573 574 * duration counter (Register 34). The Zero Motion interrupt is triggered when
Gaetios 2:85734ad35573 575 * the Zero Motion duration counter reaches the time count specified in
Gaetios 2:85734ad35573 576 * ZRMOT_DUR (Register 34).
Gaetios 2:85734ad35573 577 *
Gaetios 2:85734ad35573 578 * Unlike Free Fall or Motion detection, Zero Motion detection triggers an
Gaetios 2:85734ad35573 579 * interrupt both when Zero Motion is first detected and when Zero Motion is no
Gaetios 2:85734ad35573 580 * longer detected.
Gaetios 2:85734ad35573 581 *
Gaetios 2:85734ad35573 582 * When a zero motion event is detected, a Zero Motion Status will be indicated
Gaetios 2:85734ad35573 583 * in the MOT_DETECT_STATUS register (Register 97). When a motion-to-zero-motion
Gaetios 2:85734ad35573 584 * condition is detected, the status bit is set to 1. When a zero-motion-to-
Gaetios 2:85734ad35573 585 * motion condition is detected, the status bit is set to 0.
Gaetios 2:85734ad35573 586 *
Gaetios 2:85734ad35573 587 * For more details on the Zero Motion detection interrupt, see Section 8.4 of
Gaetios 2:85734ad35573 588 * the MPU-6000/MPU-6050 Product Specification document as well as Registers 56
Gaetios 2:85734ad35573 589 * and 58 of this document.
Gaetios 2:85734ad35573 590 *
Gaetios 2:85734ad35573 591 * @return Current zero motion detection acceleration threshold value (LSB = 2mg)
Gaetios 2:85734ad35573 592 * @see MPU6050_RA_ZRMOT_THR
Gaetios 2:85734ad35573 593 */
Gaetios 2:85734ad35573 594 uint8_t MPU60503::getZeroMotionDetectionThreshold()
Gaetios 2:85734ad35573 595 {
Gaetios 2:85734ad35573 596 i2Cdev.readByte(devAddr, MPU6050_RA_ZRMOT_THR, buffer);
Gaetios 2:85734ad35573 597 return buffer[0];
Gaetios 2:85734ad35573 598 }
Gaetios 2:85734ad35573 599 /** Set zero motion detection event acceleration threshold.
Gaetios 2:85734ad35573 600 * @param threshold New zero motion detection acceleration threshold value (LSB = 2mg)
Gaetios 2:85734ad35573 601 * @see getZeroMotionDetectionThreshold()
Gaetios 2:85734ad35573 602 * @see MPU6050_RA_ZRMOT_THR
Gaetios 2:85734ad35573 603 */
Gaetios 2:85734ad35573 604 void MPU60503::setZeroMotionDetectionThreshold(uint8_t threshold)
Gaetios 2:85734ad35573 605 {
Gaetios 2:85734ad35573 606 i2Cdev.writeByte(devAddr, MPU6050_RA_ZRMOT_THR, threshold);
Gaetios 2:85734ad35573 607 }
Gaetios 2:85734ad35573 608
Gaetios 2:85734ad35573 609 // ZRMOT_DUR register
Gaetios 2:85734ad35573 610
Gaetios 2:85734ad35573 611 /** Get zero motion detection event duration threshold.
Gaetios 2:85734ad35573 612 * This register configures the duration counter threshold for Zero Motion
Gaetios 2:85734ad35573 613 * interrupt generation. The duration counter ticks at 16 Hz, therefore
Gaetios 2:85734ad35573 614 * ZRMOT_DUR has a unit of 1 LSB = 64 ms. The Zero Motion duration counter
Gaetios 2:85734ad35573 615 * increments while the absolute value of the accelerometer measurements are
Gaetios 2:85734ad35573 616 * each less than the detection threshold (Register 33). The Zero Motion
Gaetios 2:85734ad35573 617 * interrupt is triggered when the Zero Motion duration counter reaches the time
Gaetios 2:85734ad35573 618 * count specified in this register.
Gaetios 2:85734ad35573 619 *
Gaetios 2:85734ad35573 620 * For more details on the Zero Motion detection interrupt, see Section 8.4 of
Gaetios 2:85734ad35573 621 * the MPU-6000/MPU-6050 Product Specification document, as well as Registers 56
Gaetios 2:85734ad35573 622 * and 58 of this document.
Gaetios 2:85734ad35573 623 *
Gaetios 2:85734ad35573 624 * @return Current zero motion detection duration threshold value (LSB = 64ms)
Gaetios 2:85734ad35573 625 * @see MPU6050_RA_ZRMOT_DUR
Gaetios 2:85734ad35573 626 */
Gaetios 2:85734ad35573 627 uint8_t MPU60503::getZeroMotionDetectionDuration()
Gaetios 2:85734ad35573 628 {
Gaetios 2:85734ad35573 629 i2Cdev.readByte(devAddr, MPU6050_RA_ZRMOT_DUR, buffer);
Gaetios 2:85734ad35573 630 return buffer[0];
Gaetios 2:85734ad35573 631 }
Gaetios 2:85734ad35573 632 /** Set zero motion detection event duration threshold.
Gaetios 2:85734ad35573 633 * @param duration New zero motion detection duration threshold value (LSB = 1ms)
Gaetios 2:85734ad35573 634 * @see getZeroMotionDetectionDuration()
Gaetios 2:85734ad35573 635 * @see MPU6050_RA_ZRMOT_DUR
Gaetios 2:85734ad35573 636 */
Gaetios 2:85734ad35573 637 void MPU60503::setZeroMotionDetectionDuration(uint8_t duration)
Gaetios 2:85734ad35573 638 {
Gaetios 2:85734ad35573 639 i2Cdev.writeByte(devAddr, MPU6050_RA_ZRMOT_DUR, duration);
Gaetios 2:85734ad35573 640 }
Gaetios 2:85734ad35573 641
Gaetios 2:85734ad35573 642 // FIFO_EN register
Gaetios 2:85734ad35573 643
Gaetios 2:85734ad35573 644 /** Get temperature FIFO enabled value.
Gaetios 2:85734ad35573 645 * When set to 1, this bit enables TEMP_OUT_H and TEMP_OUT_L (Registers 65 and
Gaetios 2:85734ad35573 646 * 66) to be written into the FIFO buffer.
Gaetios 2:85734ad35573 647 * @return Current temperature FIFO enabled value
Gaetios 2:85734ad35573 648 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 649 */
Gaetios 2:85734ad35573 650 bool MPU60503::getTempFIFOEnabled()
Gaetios 2:85734ad35573 651 {
Gaetios 2:85734ad35573 652 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, buffer);
Gaetios 2:85734ad35573 653 return buffer[0];
Gaetios 2:85734ad35573 654 }
Gaetios 2:85734ad35573 655 /** Set temperature FIFO enabled value.
Gaetios 2:85734ad35573 656 * @param enabled New temperature FIFO enabled value
Gaetios 2:85734ad35573 657 * @see getTempFIFOEnabled()
Gaetios 2:85734ad35573 658 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 659 */
Gaetios 2:85734ad35573 660 void MPU60503::setTempFIFOEnabled(bool enabled)
Gaetios 2:85734ad35573 661 {
Gaetios 2:85734ad35573 662 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, enabled);
Gaetios 2:85734ad35573 663 }
Gaetios 2:85734ad35573 664 /** Get gyroscope X-axis FIFO enabled value.
Gaetios 2:85734ad35573 665 * When set to 1, this bit enables GYRO_XOUT_H and GYRO_XOUT_L (Registers 67 and
Gaetios 2:85734ad35573 666 * 68) to be written into the FIFO buffer.
Gaetios 2:85734ad35573 667 * @return Current gyroscope X-axis FIFO enabled value
Gaetios 2:85734ad35573 668 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 669 */
Gaetios 2:85734ad35573 670 bool MPU60503::getXGyroFIFOEnabled()
Gaetios 2:85734ad35573 671 {
Gaetios 2:85734ad35573 672 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, buffer);
Gaetios 2:85734ad35573 673 return buffer[0];
Gaetios 2:85734ad35573 674 }
Gaetios 2:85734ad35573 675 /** Set gyroscope X-axis FIFO enabled value.
Gaetios 2:85734ad35573 676 * @param enabled New gyroscope X-axis FIFO enabled value
Gaetios 2:85734ad35573 677 * @see getXGyroFIFOEnabled()
Gaetios 2:85734ad35573 678 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 679 */
Gaetios 2:85734ad35573 680 void MPU60503::setXGyroFIFOEnabled(bool enabled)
Gaetios 2:85734ad35573 681 {
Gaetios 2:85734ad35573 682 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, enabled);
Gaetios 2:85734ad35573 683 }
Gaetios 2:85734ad35573 684 /** Get gyroscope Y-axis FIFO enabled value.
Gaetios 2:85734ad35573 685 * When set to 1, this bit enables GYRO_YOUT_H and GYRO_YOUT_L (Registers 69 and
Gaetios 2:85734ad35573 686 * 70) to be written into the FIFO buffer.
Gaetios 2:85734ad35573 687 * @return Current gyroscope Y-axis FIFO enabled value
Gaetios 2:85734ad35573 688 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 689 */
Gaetios 2:85734ad35573 690 bool MPU60503::getYGyroFIFOEnabled()
Gaetios 2:85734ad35573 691 {
Gaetios 2:85734ad35573 692 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, buffer);
Gaetios 2:85734ad35573 693 return buffer[0];
Gaetios 2:85734ad35573 694 }
Gaetios 2:85734ad35573 695 /** Set gyroscope Y-axis FIFO enabled value.
Gaetios 2:85734ad35573 696 * @param enabled New gyroscope Y-axis FIFO enabled value
Gaetios 2:85734ad35573 697 * @see getYGyroFIFOEnabled()
Gaetios 2:85734ad35573 698 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 699 */
Gaetios 2:85734ad35573 700 void MPU60503::setYGyroFIFOEnabled(bool enabled)
Gaetios 2:85734ad35573 701 {
Gaetios 2:85734ad35573 702 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, enabled);
Gaetios 2:85734ad35573 703 }
Gaetios 2:85734ad35573 704 /** Get gyroscope Z-axis FIFO enabled value.
Gaetios 2:85734ad35573 705 * When set to 1, this bit enables GYRO_ZOUT_H and GYRO_ZOUT_L (Registers 71 and
Gaetios 2:85734ad35573 706 * 72) to be written into the FIFO buffer.
Gaetios 2:85734ad35573 707 * @return Current gyroscope Z-axis FIFO enabled value
Gaetios 2:85734ad35573 708 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 709 */
Gaetios 2:85734ad35573 710 bool MPU60503::getZGyroFIFOEnabled()
Gaetios 2:85734ad35573 711 {
Gaetios 2:85734ad35573 712 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, buffer);
Gaetios 2:85734ad35573 713 return buffer[0];
Gaetios 2:85734ad35573 714 }
Gaetios 2:85734ad35573 715 /** Set gyroscope Z-axis FIFO enabled value.
Gaetios 2:85734ad35573 716 * @param enabled New gyroscope Z-axis FIFO enabled value
Gaetios 2:85734ad35573 717 * @see getZGyroFIFOEnabled()
Gaetios 2:85734ad35573 718 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 719 */
Gaetios 2:85734ad35573 720 void MPU60503::setZGyroFIFOEnabled(bool enabled)
Gaetios 2:85734ad35573 721 {
Gaetios 2:85734ad35573 722 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, enabled);
Gaetios 2:85734ad35573 723 }
Gaetios 2:85734ad35573 724 /** Get accelerometer FIFO enabled value.
Gaetios 2:85734ad35573 725 * When set to 1, this bit enables ACCEL_XOUT_H, ACCEL_XOUT_L, ACCEL_YOUT_H,
Gaetios 2:85734ad35573 726 * ACCEL_YOUT_L, ACCEL_ZOUT_H, and ACCEL_ZOUT_L (Registers 59 to 64) to be
Gaetios 2:85734ad35573 727 * written into the FIFO buffer.
Gaetios 2:85734ad35573 728 * @return Current accelerometer FIFO enabled value
Gaetios 2:85734ad35573 729 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 730 */
Gaetios 2:85734ad35573 731 bool MPU60503::getAccelFIFOEnabled()
Gaetios 2:85734ad35573 732 {
Gaetios 2:85734ad35573 733 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, buffer);
Gaetios 2:85734ad35573 734 return buffer[0];
Gaetios 2:85734ad35573 735 }
Gaetios 2:85734ad35573 736 /** Set accelerometer FIFO enabled value.
Gaetios 2:85734ad35573 737 * @param enabled New accelerometer FIFO enabled value
Gaetios 2:85734ad35573 738 * @see getAccelFIFOEnabled()
Gaetios 2:85734ad35573 739 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 740 */
Gaetios 2:85734ad35573 741 void MPU60503::setAccelFIFOEnabled(bool enabled)
Gaetios 2:85734ad35573 742 {
Gaetios 2:85734ad35573 743 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, enabled);
Gaetios 2:85734ad35573 744 }
Gaetios 2:85734ad35573 745 /** Get Slave 2 FIFO enabled value.
Gaetios 2:85734ad35573 746 * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
Gaetios 2:85734ad35573 747 * associated with Slave 2 to be written into the FIFO buffer.
Gaetios 2:85734ad35573 748 * @return Current Slave 2 FIFO enabled value
Gaetios 2:85734ad35573 749 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 750 */
Gaetios 2:85734ad35573 751 bool MPU60503::getSlave2FIFOEnabled()
Gaetios 2:85734ad35573 752 {
Gaetios 2:85734ad35573 753 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, buffer);
Gaetios 2:85734ad35573 754 return buffer[0];
Gaetios 2:85734ad35573 755 }
Gaetios 2:85734ad35573 756 /** Set Slave 2 FIFO enabled value.
Gaetios 2:85734ad35573 757 * @param enabled New Slave 2 FIFO enabled value
Gaetios 2:85734ad35573 758 * @see getSlave2FIFOEnabled()
Gaetios 2:85734ad35573 759 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 760 */
Gaetios 2:85734ad35573 761 void MPU60503::setSlave2FIFOEnabled(bool enabled)
Gaetios 2:85734ad35573 762 {
Gaetios 2:85734ad35573 763 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, enabled);
Gaetios 2:85734ad35573 764 }
Gaetios 2:85734ad35573 765 /** Get Slave 1 FIFO enabled value.
Gaetios 2:85734ad35573 766 * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
Gaetios 2:85734ad35573 767 * associated with Slave 1 to be written into the FIFO buffer.
Gaetios 2:85734ad35573 768 * @return Current Slave 1 FIFO enabled value
Gaetios 2:85734ad35573 769 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 770 */
Gaetios 2:85734ad35573 771 bool MPU60503::getSlave1FIFOEnabled()
Gaetios 2:85734ad35573 772 {
Gaetios 2:85734ad35573 773 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, buffer);
Gaetios 2:85734ad35573 774 return buffer[0];
Gaetios 2:85734ad35573 775 }
Gaetios 2:85734ad35573 776 /** Set Slave 1 FIFO enabled value.
Gaetios 2:85734ad35573 777 * @param enabled New Slave 1 FIFO enabled value
Gaetios 2:85734ad35573 778 * @see getSlave1FIFOEnabled()
Gaetios 2:85734ad35573 779 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 780 */
Gaetios 2:85734ad35573 781 void MPU60503::setSlave1FIFOEnabled(bool enabled)
Gaetios 2:85734ad35573 782 {
Gaetios 2:85734ad35573 783 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, enabled);
Gaetios 2:85734ad35573 784 }
Gaetios 2:85734ad35573 785 /** Get Slave 0 FIFO enabled value.
Gaetios 2:85734ad35573 786 * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
Gaetios 2:85734ad35573 787 * associated with Slave 0 to be written into the FIFO buffer.
Gaetios 2:85734ad35573 788 * @return Current Slave 0 FIFO enabled value
Gaetios 2:85734ad35573 789 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 790 */
Gaetios 2:85734ad35573 791 bool MPU60503::getSlave0FIFOEnabled()
Gaetios 2:85734ad35573 792 {
Gaetios 2:85734ad35573 793 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, buffer);
Gaetios 2:85734ad35573 794 return buffer[0];
Gaetios 2:85734ad35573 795 }
Gaetios 2:85734ad35573 796 /** Set Slave 0 FIFO enabled value.
Gaetios 2:85734ad35573 797 * @param enabled New Slave 0 FIFO enabled value
Gaetios 2:85734ad35573 798 * @see getSlave0FIFOEnabled()
Gaetios 2:85734ad35573 799 * @see MPU6050_RA_FIFO_EN
Gaetios 2:85734ad35573 800 */
Gaetios 2:85734ad35573 801 void MPU60503::setSlave0FIFOEnabled(bool enabled)
Gaetios 2:85734ad35573 802 {
Gaetios 2:85734ad35573 803 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, enabled);
Gaetios 2:85734ad35573 804 }
Gaetios 2:85734ad35573 805
Gaetios 2:85734ad35573 806 // I2C_MST_CTRL register
Gaetios 2:85734ad35573 807
Gaetios 2:85734ad35573 808 /** Get multi-master enabled value.
Gaetios 2:85734ad35573 809 * Multi-master capability allows multiple I2C masters to operate on the same
Gaetios 2:85734ad35573 810 * bus. In circuits where multi-master capability is required, set MULT_MST_EN
Gaetios 2:85734ad35573 811 * to 1. This will increase current drawn by approximately 30uA.
Gaetios 2:85734ad35573 812 *
Gaetios 2:85734ad35573 813 * In circuits where multi-master capability is required, the state of the I2C
Gaetios 2:85734ad35573 814 * bus must always be monitored by each separate I2C Master. Before an I2C
Gaetios 2:85734ad35573 815 * Master can assume arbitration of the bus, it must first confirm that no other
Gaetios 2:85734ad35573 816 * I2C Master has arbitration of the bus. When MULT_MST_EN is set to 1, the
Gaetios 2:85734ad35573 817 * MPU-60X0's bus arbitration detection logic is turned on, enabling it to
Gaetios 2:85734ad35573 818 * detect when the bus is available.
Gaetios 2:85734ad35573 819 *
Gaetios 2:85734ad35573 820 * @return Current multi-master enabled value
Gaetios 2:85734ad35573 821 * @see MPU6050_RA_I2C_MST_CTRL
Gaetios 2:85734ad35573 822 */
Gaetios 2:85734ad35573 823 bool MPU60503::getMultiMasterEnabled()
Gaetios 2:85734ad35573 824 {
Gaetios 2:85734ad35573 825 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, buffer);
Gaetios 2:85734ad35573 826 return buffer[0];
Gaetios 2:85734ad35573 827 }
Gaetios 2:85734ad35573 828 /** Set multi-master enabled value.
Gaetios 2:85734ad35573 829 * @param enabled New multi-master enabled value
Gaetios 2:85734ad35573 830 * @see getMultiMasterEnabled()
Gaetios 2:85734ad35573 831 * @see MPU6050_RA_I2C_MST_CTRL
Gaetios 2:85734ad35573 832 */
Gaetios 2:85734ad35573 833 void MPU60503::setMultiMasterEnabled(bool enabled)
Gaetios 2:85734ad35573 834 {
Gaetios 2:85734ad35573 835 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, enabled);
Gaetios 2:85734ad35573 836 }
Gaetios 2:85734ad35573 837 /** Get wait-for-external-sensor-data enabled value.
Gaetios 2:85734ad35573 838 * When the WAIT_FOR_ES bit is set to 1, the Data Ready interrupt will be
Gaetios 2:85734ad35573 839 * delayed until External Sensor data from the Slave Devices are loaded into the
Gaetios 2:85734ad35573 840 * EXT_SENS_DATA registers. This is used to ensure that both the internal sensor
Gaetios 2:85734ad35573 841 * data (i.e. from gyro and accel) and external sensor data have been loaded to
Gaetios 2:85734ad35573 842 * their respective data registers (i.e. the data is synced) when the Data Ready
Gaetios 2:85734ad35573 843 * interrupt is triggered.
Gaetios 2:85734ad35573 844 *
Gaetios 2:85734ad35573 845 * @return Current wait-for-external-sensor-data enabled value
Gaetios 2:85734ad35573 846 * @see MPU6050_RA_I2C_MST_CTRL
Gaetios 2:85734ad35573 847 */
Gaetios 2:85734ad35573 848 bool MPU60503::getWaitForExternalSensorEnabled()
Gaetios 2:85734ad35573 849 {
Gaetios 2:85734ad35573 850 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, buffer);
Gaetios 2:85734ad35573 851 return buffer[0];
Gaetios 2:85734ad35573 852 }
Gaetios 2:85734ad35573 853 /** Set wait-for-external-sensor-data enabled value.
Gaetios 2:85734ad35573 854 * @param enabled New wait-for-external-sensor-data enabled value
Gaetios 2:85734ad35573 855 * @see getWaitForExternalSensorEnabled()
Gaetios 2:85734ad35573 856 * @see MPU6050_RA_I2C_MST_CTRL
Gaetios 2:85734ad35573 857 */
Gaetios 2:85734ad35573 858 void MPU60503::setWaitForExternalSensorEnabled(bool enabled)
Gaetios 2:85734ad35573 859 {
Gaetios 2:85734ad35573 860 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, enabled);
Gaetios 2:85734ad35573 861 }
Gaetios 2:85734ad35573 862 /** Get Slave 3 FIFO enabled value.
Gaetios 2:85734ad35573 863 * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
Gaetios 2:85734ad35573 864 * associated with Slave 3 to be written into the FIFO buffer.
Gaetios 2:85734ad35573 865 * @return Current Slave 3 FIFO enabled value
Gaetios 2:85734ad35573 866 * @see MPU6050_RA_MST_CTRL
Gaetios 2:85734ad35573 867 */
Gaetios 2:85734ad35573 868 bool MPU60503::getSlave3FIFOEnabled()
Gaetios 2:85734ad35573 869 {
Gaetios 2:85734ad35573 870 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, buffer);
Gaetios 2:85734ad35573 871 return buffer[0];
Gaetios 2:85734ad35573 872 }
Gaetios 2:85734ad35573 873 /** Set Slave 3 FIFO enabled value.
Gaetios 2:85734ad35573 874 * @param enabled New Slave 3 FIFO enabled value
Gaetios 2:85734ad35573 875 * @see getSlave3FIFOEnabled()
Gaetios 2:85734ad35573 876 * @see MPU6050_RA_MST_CTRL
Gaetios 2:85734ad35573 877 */
Gaetios 2:85734ad35573 878 void MPU60503::setSlave3FIFOEnabled(bool enabled)
Gaetios 2:85734ad35573 879 {
Gaetios 2:85734ad35573 880 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, enabled);
Gaetios 2:85734ad35573 881 }
Gaetios 2:85734ad35573 882 /** Get slave read/write transition enabled value.
Gaetios 2:85734ad35573 883 * The I2C_MST_P_NSR bit configures the I2C Master's transition from one slave
Gaetios 2:85734ad35573 884 * read to the next slave read. If the bit equals 0, there will be a restart
Gaetios 2:85734ad35573 885 * between reads. If the bit equals 1, there will be a stop followed by a start
Gaetios 2:85734ad35573 886 * of the following read. When a write transaction follows a read transaction,
Gaetios 2:85734ad35573 887 * the stop followed by a start of the successive write will be always used.
Gaetios 2:85734ad35573 888 *
Gaetios 2:85734ad35573 889 * @return Current slave read/write transition enabled value
Gaetios 2:85734ad35573 890 * @see MPU6050_RA_I2C_MST_CTRL
Gaetios 2:85734ad35573 891 */
Gaetios 2:85734ad35573 892 bool MPU60503::getSlaveReadWriteTransitionEnabled()
Gaetios 2:85734ad35573 893 {
Gaetios 2:85734ad35573 894 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, buffer);
Gaetios 2:85734ad35573 895 return buffer[0];
Gaetios 2:85734ad35573 896 }
Gaetios 2:85734ad35573 897 /** Set slave read/write transition enabled value.
Gaetios 2:85734ad35573 898 * @param enabled New slave read/write transition enabled value
Gaetios 2:85734ad35573 899 * @see getSlaveReadWriteTransitionEnabled()
Gaetios 2:85734ad35573 900 * @see MPU6050_RA_I2C_MST_CTRL
Gaetios 2:85734ad35573 901 */
Gaetios 2:85734ad35573 902 void MPU60503::setSlaveReadWriteTransitionEnabled(bool enabled)
Gaetios 2:85734ad35573 903 {
Gaetios 2:85734ad35573 904 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, enabled);
Gaetios 2:85734ad35573 905 }
Gaetios 2:85734ad35573 906 /** Get I2C master clock speed.
Gaetios 2:85734ad35573 907 * I2C_MST_CLK is a 4 bit unsigned value which configures a divider on the
Gaetios 2:85734ad35573 908 * MPU-60X0 internal 8MHz clock. It sets the I2C master clock speed according to
Gaetios 2:85734ad35573 909 * the following table:
Gaetios 2:85734ad35573 910 *
Gaetios 2:85734ad35573 911 * <pre>
Gaetios 2:85734ad35573 912 * I2C_MST_CLK | I2C Master Clock Speed | 8MHz Clock Divider
Gaetios 2:85734ad35573 913 * ------------+------------------------+-------------------
Gaetios 2:85734ad35573 914 * 0 | 348kHz | 23
Gaetios 2:85734ad35573 915 * 1 | 333kHz | 24
Gaetios 2:85734ad35573 916 * 2 | 320kHz | 25
Gaetios 2:85734ad35573 917 * 3 | 308kHz | 26
Gaetios 2:85734ad35573 918 * 4 | 296kHz | 27
Gaetios 2:85734ad35573 919 * 5 | 286kHz | 28
Gaetios 2:85734ad35573 920 * 6 | 276kHz | 29
Gaetios 2:85734ad35573 921 * 7 | 267kHz | 30
Gaetios 2:85734ad35573 922 * 8 | 258kHz | 31
Gaetios 2:85734ad35573 923 * 9 | 500kHz | 16
Gaetios 2:85734ad35573 924 * 10 | 471kHz | 17
Gaetios 2:85734ad35573 925 * 11 | 444kHz | 18
Gaetios 2:85734ad35573 926 * 12 | 421kHz | 19
Gaetios 2:85734ad35573 927 * 13 | 400kHz | 20
Gaetios 2:85734ad35573 928 * 14 | 381kHz | 21
Gaetios 2:85734ad35573 929 * 15 | 364kHz | 22
Gaetios 2:85734ad35573 930 * </pre>
Gaetios 2:85734ad35573 931 *
Gaetios 2:85734ad35573 932 * @return Current I2C master clock speed
Gaetios 2:85734ad35573 933 * @see MPU6050_RA_I2C_MST_CTRL
Gaetios 2:85734ad35573 934 */
Gaetios 2:85734ad35573 935 uint8_t MPU60503::getMasterClockSpeed()
Gaetios 2:85734ad35573 936 {
Gaetios 2:85734ad35573 937 i2Cdev.readBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, buffer);
Gaetios 2:85734ad35573 938 return buffer[0];
Gaetios 2:85734ad35573 939 }
Gaetios 2:85734ad35573 940 /** Set I2C master clock speed.
Gaetios 2:85734ad35573 941 * @reparam speed Current I2C master clock speed
Gaetios 2:85734ad35573 942 * @see MPU6050_RA_I2C_MST_CTRL
Gaetios 2:85734ad35573 943 */
Gaetios 2:85734ad35573 944 void MPU60503::setMasterClockSpeed(uint8_t speed)
Gaetios 2:85734ad35573 945 {
Gaetios 2:85734ad35573 946 i2Cdev.writeBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, speed);
Gaetios 2:85734ad35573 947 }
Gaetios 2:85734ad35573 948
Gaetios 2:85734ad35573 949 // I2C_SLV* registers (Slave 0-3)
Gaetios 2:85734ad35573 950
Gaetios 2:85734ad35573 951 /** Get the I2C address of the specified slave (0-3).
Gaetios 2:85734ad35573 952 * Note that Bit 7 (MSB) controls read/write mode. If Bit 7 is set, it's a read
Gaetios 2:85734ad35573 953 * operation, and if it is cleared, then it's a write operation. The remaining
Gaetios 2:85734ad35573 954 * bits (6-0) are the 7-bit device address of the slave device.
Gaetios 2:85734ad35573 955 *
Gaetios 2:85734ad35573 956 * In read mode, the result of the read is placed in the lowest available
Gaetios 2:85734ad35573 957 * EXT_SENS_DATA register. For further information regarding the allocation of
Gaetios 2:85734ad35573 958 * read results, please refer to the EXT_SENS_DATA register description
Gaetios 2:85734ad35573 959 * (Registers 73 - 96).
Gaetios 2:85734ad35573 960 *
Gaetios 2:85734ad35573 961 * The MPU-6050 supports a total of five slaves, but Slave 4 has unique
Gaetios 2:85734ad35573 962 * characteristics, and so it has its own functions (getSlave4* and setSlave4*).
Gaetios 2:85734ad35573 963 *
Gaetios 2:85734ad35573 964 * I2C data transactions are performed at the Sample Rate, as defined in
Gaetios 2:85734ad35573 965 * Register 25. The user is responsible for ensuring that I2C data transactions
Gaetios 2:85734ad35573 966 * to and from each enabled Slave can be completed within a single period of the
Gaetios 2:85734ad35573 967 * Sample Rate.
Gaetios 2:85734ad35573 968 *
Gaetios 2:85734ad35573 969 * The I2C slave access rate can be reduced relative to the Sample Rate. This
Gaetios 2:85734ad35573 970 * reduced access rate is determined by I2C_MST_DLY (Register 52). Whether a
Gaetios 2:85734ad35573 971 * slave's access rate is reduced relative to the Sample Rate is determined by
Gaetios 2:85734ad35573 972 * I2C_MST_DELAY_CTRL (Register 103).
Gaetios 2:85734ad35573 973 *
Gaetios 2:85734ad35573 974 * The processing order for the slaves is fixed. The sequence followed for
Gaetios 2:85734ad35573 975 * processing the slaves is Slave 0, Slave 1, Slave 2, Slave 3 and Slave 4. If a
Gaetios 2:85734ad35573 976 * particular Slave is disabled it will be skipped.
Gaetios 2:85734ad35573 977 *
Gaetios 2:85734ad35573 978 * Each slave can either be accessed at the sample rate or at a reduced sample
Gaetios 2:85734ad35573 979 * rate. In a case where some slaves are accessed at the Sample Rate and some
Gaetios 2:85734ad35573 980 * slaves are accessed at the reduced rate, the sequence of accessing the slaves
Gaetios 2:85734ad35573 981 * (Slave 0 to Slave 4) is still followed. However, the reduced rate slaves will
Gaetios 2:85734ad35573 982 * be skipped if their access rate dictates that they should not be accessed
Gaetios 2:85734ad35573 983 * during that particular cycle. For further information regarding the reduced
Gaetios 2:85734ad35573 984 * access rate, please refer to Register 52. Whether a slave is accessed at the
Gaetios 2:85734ad35573 985 * Sample Rate or at the reduced rate is determined by the Delay Enable bits in
Gaetios 2:85734ad35573 986 * Register 103.
Gaetios 2:85734ad35573 987 *
Gaetios 2:85734ad35573 988 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 989 * @return Current address for specified slave
Gaetios 2:85734ad35573 990 * @see MPU6050_RA_I2C_SLV0_ADDR
Gaetios 2:85734ad35573 991 */
Gaetios 2:85734ad35573 992 uint8_t MPU60503::getSlaveAddress(uint8_t num)
Gaetios 2:85734ad35573 993 {
Gaetios 2:85734ad35573 994 if (num > 3) return 0;
Gaetios 2:85734ad35573 995 i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, buffer);
Gaetios 2:85734ad35573 996 return buffer[0];
Gaetios 2:85734ad35573 997 }
Gaetios 2:85734ad35573 998 /** Set the I2C address of the specified slave (0-3).
Gaetios 2:85734ad35573 999 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1000 * @param address New address for specified slave
Gaetios 2:85734ad35573 1001 * @see getSlaveAddress()
Gaetios 2:85734ad35573 1002 * @see MPU6050_RA_I2C_SLV0_ADDR
Gaetios 2:85734ad35573 1003 */
Gaetios 2:85734ad35573 1004 void MPU60503::setSlaveAddress(uint8_t num, uint8_t address)
Gaetios 2:85734ad35573 1005 {
Gaetios 2:85734ad35573 1006 if (num > 3) return;
Gaetios 2:85734ad35573 1007 i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, address);
Gaetios 2:85734ad35573 1008 }
Gaetios 2:85734ad35573 1009 /** Get the active internal register for the specified slave (0-3).
Gaetios 2:85734ad35573 1010 * Read/write operations for this slave will be done to whatever internal
Gaetios 2:85734ad35573 1011 * register address is stored in this MPU register.
Gaetios 2:85734ad35573 1012 *
Gaetios 2:85734ad35573 1013 * The MPU-6050 supports a total of five slaves, but Slave 4 has unique
Gaetios 2:85734ad35573 1014 * characteristics, and so it has its own functions.
Gaetios 2:85734ad35573 1015 *
Gaetios 2:85734ad35573 1016 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1017 * @return Current active register for specified slave
Gaetios 2:85734ad35573 1018 * @see MPU6050_RA_I2C_SLV0_REG
Gaetios 2:85734ad35573 1019 */
Gaetios 2:85734ad35573 1020 uint8_t MPU60503::getSlaveRegister(uint8_t num)
Gaetios 2:85734ad35573 1021 {
Gaetios 2:85734ad35573 1022 if (num > 3) return 0;
Gaetios 2:85734ad35573 1023 i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, buffer);
Gaetios 2:85734ad35573 1024 return buffer[0];
Gaetios 2:85734ad35573 1025 }
Gaetios 2:85734ad35573 1026 /** Set the active internal register for the specified slave (0-3).
Gaetios 2:85734ad35573 1027 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1028 * @param reg New active register for specified slave
Gaetios 2:85734ad35573 1029 * @see getSlaveRegister()
Gaetios 2:85734ad35573 1030 * @see MPU6050_RA_I2C_SLV0_REG
Gaetios 2:85734ad35573 1031 */
Gaetios 2:85734ad35573 1032 void MPU60503::setSlaveRegister(uint8_t num, uint8_t reg)
Gaetios 2:85734ad35573 1033 {
Gaetios 2:85734ad35573 1034 if (num > 3) return;
Gaetios 2:85734ad35573 1035 i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, reg);
Gaetios 2:85734ad35573 1036 }
Gaetios 2:85734ad35573 1037 /** Get the enabled value for the specified slave (0-3).
Gaetios 2:85734ad35573 1038 * When set to 1, this bit enables Slave 0 for data transfer operations. When
Gaetios 2:85734ad35573 1039 * cleared to 0, this bit disables Slave 0 from data transfer operations.
Gaetios 2:85734ad35573 1040 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1041 * @return Current enabled value for specified slave
Gaetios 2:85734ad35573 1042 * @see MPU6050_RA_I2C_SLV0_CTRL
Gaetios 2:85734ad35573 1043 */
Gaetios 2:85734ad35573 1044 bool MPU60503::getSlaveEnabled(uint8_t num)
Gaetios 2:85734ad35573 1045 {
Gaetios 2:85734ad35573 1046 if (num > 3) return 0;
Gaetios 2:85734ad35573 1047 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_EN_BIT, buffer);
Gaetios 2:85734ad35573 1048 return buffer[0];
Gaetios 2:85734ad35573 1049 }
Gaetios 2:85734ad35573 1050 /** Set the enabled value for the specified slave (0-3).
Gaetios 2:85734ad35573 1051 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1052 * @param enabled New enabled value for specified slave
Gaetios 2:85734ad35573 1053 * @see getSlaveEnabled()
Gaetios 2:85734ad35573 1054 * @see MPU6050_RA_I2C_SLV0_CTRL
Gaetios 2:85734ad35573 1055 */
Gaetios 2:85734ad35573 1056 void MPU60503::setSlaveEnabled(uint8_t num, bool enabled)
Gaetios 2:85734ad35573 1057 {
Gaetios 2:85734ad35573 1058 if (num > 3) return;
Gaetios 2:85734ad35573 1059 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_EN_BIT, enabled);
Gaetios 2:85734ad35573 1060 }
Gaetios 2:85734ad35573 1061 /** Get word pair byte-swapping enabled for the specified slave (0-3).
Gaetios 2:85734ad35573 1062 * When set to 1, this bit enables byte swapping. When byte swapping is enabled,
Gaetios 2:85734ad35573 1063 * the high and low bytes of a word pair are swapped. Please refer to
Gaetios 2:85734ad35573 1064 * I2C_SLV0_GRP for the pairing convention of the word pairs. When cleared to 0,
Gaetios 2:85734ad35573 1065 * bytes transferred to and from Slave 0 will be written to EXT_SENS_DATA
Gaetios 2:85734ad35573 1066 * registers in the order they were transferred.
Gaetios 2:85734ad35573 1067 *
Gaetios 2:85734ad35573 1068 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1069 * @return Current word pair byte-swapping enabled value for specified slave
Gaetios 2:85734ad35573 1070 * @see MPU6050_RA_I2C_SLV0_CTRL
Gaetios 2:85734ad35573 1071 */
Gaetios 2:85734ad35573 1072 bool MPU60503::getSlaveWordByteSwap(uint8_t num)
Gaetios 2:85734ad35573 1073 {
Gaetios 2:85734ad35573 1074 if (num > 3) return 0;
Gaetios 2:85734ad35573 1075 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_BYTE_SW_BIT, buffer);
Gaetios 2:85734ad35573 1076 return buffer[0];
Gaetios 2:85734ad35573 1077 }
Gaetios 2:85734ad35573 1078 /** Set word pair byte-swapping enabled for the specified slave (0-3).
Gaetios 2:85734ad35573 1079 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1080 * @param enabled New word pair byte-swapping enabled value for specified slave
Gaetios 2:85734ad35573 1081 * @see getSlaveWordByteSwap()
Gaetios 2:85734ad35573 1082 * @see MPU6050_RA_I2C_SLV0_CTRL
Gaetios 2:85734ad35573 1083 */
Gaetios 2:85734ad35573 1084 void MPU60503::setSlaveWordByteSwap(uint8_t num, bool enabled)
Gaetios 2:85734ad35573 1085 {
Gaetios 2:85734ad35573 1086 if (num > 3) return;
Gaetios 2:85734ad35573 1087 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_BYTE_SW_BIT, enabled);
Gaetios 2:85734ad35573 1088 }
Gaetios 2:85734ad35573 1089 /** Get write mode for the specified slave (0-3).
Gaetios 2:85734ad35573 1090 * When set to 1, the transaction will read or write data only. When cleared to
Gaetios 2:85734ad35573 1091 * 0, the transaction will write a register address prior to reading or writing
Gaetios 2:85734ad35573 1092 * data. This should equal 0 when specifying the register address within the
Gaetios 2:85734ad35573 1093 * Slave device to/from which the ensuing data transaction will take place.
Gaetios 2:85734ad35573 1094 *
Gaetios 2:85734ad35573 1095 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1096 * @return Current write mode for specified slave (0 = register address + data, 1 = data only)
Gaetios 2:85734ad35573 1097 * @see MPU6050_RA_I2C_SLV0_CTRL
Gaetios 2:85734ad35573 1098 */
Gaetios 2:85734ad35573 1099 bool MPU60503::getSlaveWriteMode(uint8_t num)
Gaetios 2:85734ad35573 1100 {
Gaetios 2:85734ad35573 1101 if (num > 3) return 0;
Gaetios 2:85734ad35573 1102 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_REG_DIS_BIT, buffer);
Gaetios 2:85734ad35573 1103 return buffer[0];
Gaetios 2:85734ad35573 1104 }
Gaetios 2:85734ad35573 1105 /** Set write mode for the specified slave (0-3).
Gaetios 2:85734ad35573 1106 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1107 * @param mode New write mode for specified slave (0 = register address + data, 1 = data only)
Gaetios 2:85734ad35573 1108 * @see getSlaveWriteMode()
Gaetios 2:85734ad35573 1109 * @see MPU6050_RA_I2C_SLV0_CTRL
Gaetios 2:85734ad35573 1110 */
Gaetios 2:85734ad35573 1111 void MPU60503::setSlaveWriteMode(uint8_t num, bool mode)
Gaetios 2:85734ad35573 1112 {
Gaetios 2:85734ad35573 1113 if (num > 3) return;
Gaetios 2:85734ad35573 1114 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_REG_DIS_BIT, mode);
Gaetios 2:85734ad35573 1115 }
Gaetios 2:85734ad35573 1116 /** Get word pair grouping order offset for the specified slave (0-3).
Gaetios 2:85734ad35573 1117 * This sets specifies the grouping order of word pairs received from registers.
Gaetios 2:85734ad35573 1118 * When cleared to 0, bytes from register addresses 0 and 1, 2 and 3, etc (even,
Gaetios 2:85734ad35573 1119 * then odd register addresses) are paired to form a word. When set to 1, bytes
Gaetios 2:85734ad35573 1120 * from register addresses are paired 1 and 2, 3 and 4, etc. (odd, then even
Gaetios 2:85734ad35573 1121 * register addresses) are paired to form a word.
Gaetios 2:85734ad35573 1122 *
Gaetios 2:85734ad35573 1123 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1124 * @return Current word pair grouping order offset for specified slave
Gaetios 2:85734ad35573 1125 * @see MPU6050_RA_I2C_SLV0_CTRL
Gaetios 2:85734ad35573 1126 */
Gaetios 2:85734ad35573 1127 bool MPU60503::getSlaveWordGroupOffset(uint8_t num)
Gaetios 2:85734ad35573 1128 {
Gaetios 2:85734ad35573 1129 if (num > 3) return 0;
Gaetios 2:85734ad35573 1130 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_GRP_BIT, buffer);
Gaetios 2:85734ad35573 1131 return buffer[0];
Gaetios 2:85734ad35573 1132 }
Gaetios 2:85734ad35573 1133 /** Set word pair grouping order offset for the specified slave (0-3).
Gaetios 2:85734ad35573 1134 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1135 * @param enabled New word pair grouping order offset for specified slave
Gaetios 2:85734ad35573 1136 * @see getSlaveWordGroupOffset()
Gaetios 2:85734ad35573 1137 * @see MPU6050_RA_I2C_SLV0_CTRL
Gaetios 2:85734ad35573 1138 */
Gaetios 2:85734ad35573 1139 void MPU60503::setSlaveWordGroupOffset(uint8_t num, bool enabled)
Gaetios 2:85734ad35573 1140 {
Gaetios 2:85734ad35573 1141 if (num > 3) return;
Gaetios 2:85734ad35573 1142 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_GRP_BIT, enabled);
Gaetios 2:85734ad35573 1143 }
Gaetios 2:85734ad35573 1144 /** Get number of bytes to read for the specified slave (0-3).
Gaetios 2:85734ad35573 1145 * Specifies the number of bytes transferred to and from Slave 0. Clearing this
Gaetios 2:85734ad35573 1146 * bit to 0 is equivalent to disabling the register by writing 0 to I2C_SLV0_EN.
Gaetios 2:85734ad35573 1147 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1148 * @return Number of bytes to read for specified slave
Gaetios 2:85734ad35573 1149 * @see MPU6050_RA_I2C_SLV0_CTRL
Gaetios 2:85734ad35573 1150 */
Gaetios 2:85734ad35573 1151 uint8_t MPU60503::getSlaveDataLength(uint8_t num)
Gaetios 2:85734ad35573 1152 {
Gaetios 2:85734ad35573 1153 if (num > 3) return 0;
Gaetios 2:85734ad35573 1154 i2Cdev.readBits(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_LEN_BIT, MPU6050_I2C_SLV_LEN_LENGTH, buffer);
Gaetios 2:85734ad35573 1155 return buffer[0];
Gaetios 2:85734ad35573 1156 }
Gaetios 2:85734ad35573 1157 /** Set number of bytes to read for the specified slave (0-3).
Gaetios 2:85734ad35573 1158 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 1159 * @param length Number of bytes to read for specified slave
Gaetios 2:85734ad35573 1160 * @see getSlaveDataLength()
Gaetios 2:85734ad35573 1161 * @see MPU6050_RA_I2C_SLV0_CTRL
Gaetios 2:85734ad35573 1162 */
Gaetios 2:85734ad35573 1163 void MPU60503::setSlaveDataLength(uint8_t num, uint8_t length)
Gaetios 2:85734ad35573 1164 {
Gaetios 2:85734ad35573 1165 if (num > 3) return;
Gaetios 2:85734ad35573 1166 i2Cdev.writeBits(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_LEN_BIT, MPU6050_I2C_SLV_LEN_LENGTH, length);
Gaetios 2:85734ad35573 1167 }
Gaetios 2:85734ad35573 1168
Gaetios 2:85734ad35573 1169 // I2C_SLV* registers (Slave 4)
Gaetios 2:85734ad35573 1170
Gaetios 2:85734ad35573 1171 /** Get the I2C address of Slave 4.
Gaetios 2:85734ad35573 1172 * Note that Bit 7 (MSB) controls read/write mode. If Bit 7 is set, it's a read
Gaetios 2:85734ad35573 1173 * operation, and if it is cleared, then it's a write operation. The remaining
Gaetios 2:85734ad35573 1174 * bits (6-0) are the 7-bit device address of the slave device.
Gaetios 2:85734ad35573 1175 *
Gaetios 2:85734ad35573 1176 * @return Current address for Slave 4
Gaetios 2:85734ad35573 1177 * @see getSlaveAddress()
Gaetios 2:85734ad35573 1178 * @see MPU6050_RA_I2C_SLV4_ADDR
Gaetios 2:85734ad35573 1179 */
Gaetios 2:85734ad35573 1180 uint8_t MPU60503::getSlave4Address()
Gaetios 2:85734ad35573 1181 {
Gaetios 2:85734ad35573 1182 i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, buffer);
Gaetios 2:85734ad35573 1183 return buffer[0];
Gaetios 2:85734ad35573 1184 }
Gaetios 2:85734ad35573 1185 /** Set the I2C address of Slave 4.
Gaetios 2:85734ad35573 1186 * @param address New address for Slave 4
Gaetios 2:85734ad35573 1187 * @see getSlave4Address()
Gaetios 2:85734ad35573 1188 * @see MPU6050_RA_I2C_SLV4_ADDR
Gaetios 2:85734ad35573 1189 */
Gaetios 2:85734ad35573 1190 void MPU60503::setSlave4Address(uint8_t address)
Gaetios 2:85734ad35573 1191 {
Gaetios 2:85734ad35573 1192 i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, address);
Gaetios 2:85734ad35573 1193 }
Gaetios 2:85734ad35573 1194 /** Get the active internal register for the Slave 4.
Gaetios 2:85734ad35573 1195 * Read/write operations for this slave will be done to whatever internal
Gaetios 2:85734ad35573 1196 * register address is stored in this MPU register.
Gaetios 2:85734ad35573 1197 *
Gaetios 2:85734ad35573 1198 * @return Current active register for Slave 4
Gaetios 2:85734ad35573 1199 * @see MPU6050_RA_I2C_SLV4_REG
Gaetios 2:85734ad35573 1200 */
Gaetios 2:85734ad35573 1201 uint8_t MPU60503::getSlave4Register()
Gaetios 2:85734ad35573 1202 {
Gaetios 2:85734ad35573 1203 i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_REG, buffer);
Gaetios 2:85734ad35573 1204 return buffer[0];
Gaetios 2:85734ad35573 1205 }
Gaetios 2:85734ad35573 1206 /** Set the active internal register for Slave 4.
Gaetios 2:85734ad35573 1207 * @param reg New active register for Slave 4
Gaetios 2:85734ad35573 1208 * @see getSlave4Register()
Gaetios 2:85734ad35573 1209 * @see MPU6050_RA_I2C_SLV4_REG
Gaetios 2:85734ad35573 1210 */
Gaetios 2:85734ad35573 1211 void MPU60503::setSlave4Register(uint8_t reg)
Gaetios 2:85734ad35573 1212 {
Gaetios 2:85734ad35573 1213 i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_REG, reg);
Gaetios 2:85734ad35573 1214 }
Gaetios 2:85734ad35573 1215 /** Set new byte to write to Slave 4.
Gaetios 2:85734ad35573 1216 * This register stores the data to be written into the Slave 4. If I2C_SLV4_RW
Gaetios 2:85734ad35573 1217 * is set 1 (set to read), this register has no effect.
Gaetios 2:85734ad35573 1218 * @param data New byte to write to Slave 4
Gaetios 2:85734ad35573 1219 * @see MPU6050_RA_I2C_SLV4_DO
Gaetios 2:85734ad35573 1220 */
Gaetios 2:85734ad35573 1221 void MPU60503::setSlave4OutputByte(uint8_t data)
Gaetios 2:85734ad35573 1222 {
Gaetios 2:85734ad35573 1223 i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_DO, data);
Gaetios 2:85734ad35573 1224 }
Gaetios 2:85734ad35573 1225 /** Get the enabled value for the Slave 4.
Gaetios 2:85734ad35573 1226 * When set to 1, this bit enables Slave 4 for data transfer operations. When
Gaetios 2:85734ad35573 1227 * cleared to 0, this bit disables Slave 4 from data transfer operations.
Gaetios 2:85734ad35573 1228 * @return Current enabled value for Slave 4
Gaetios 2:85734ad35573 1229 * @see MPU6050_RA_I2C_SLV4_CTRL
Gaetios 2:85734ad35573 1230 */
Gaetios 2:85734ad35573 1231 bool MPU60503::getSlave4Enabled()
Gaetios 2:85734ad35573 1232 {
Gaetios 2:85734ad35573 1233 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, buffer);
Gaetios 2:85734ad35573 1234 return buffer[0];
Gaetios 2:85734ad35573 1235 }
Gaetios 2:85734ad35573 1236 /** Set the enabled value for Slave 4.
Gaetios 2:85734ad35573 1237 * @param enabled New enabled value for Slave 4
Gaetios 2:85734ad35573 1238 * @see getSlave4Enabled()
Gaetios 2:85734ad35573 1239 * @see MPU6050_RA_I2C_SLV4_CTRL
Gaetios 2:85734ad35573 1240 */
Gaetios 2:85734ad35573 1241 void MPU60503::setSlave4Enabled(bool enabled)
Gaetios 2:85734ad35573 1242 {
Gaetios 2:85734ad35573 1243 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, enabled);
Gaetios 2:85734ad35573 1244 }
Gaetios 2:85734ad35573 1245 /** Get the enabled value for Slave 4 transaction interrupts.
Gaetios 2:85734ad35573 1246 * When set to 1, this bit enables the generation of an interrupt signal upon
Gaetios 2:85734ad35573 1247 * completion of a Slave 4 transaction. When cleared to 0, this bit disables the
Gaetios 2:85734ad35573 1248 * generation of an interrupt signal upon completion of a Slave 4 transaction.
Gaetios 2:85734ad35573 1249 * The interrupt status can be observed in Register 54.
Gaetios 2:85734ad35573 1250 *
Gaetios 2:85734ad35573 1251 * @return Current enabled value for Slave 4 transaction interrupts.
Gaetios 2:85734ad35573 1252 * @see MPU6050_RA_I2C_SLV4_CTRL
Gaetios 2:85734ad35573 1253 */
Gaetios 2:85734ad35573 1254 bool MPU60503::getSlave4InterruptEnabled()
Gaetios 2:85734ad35573 1255 {
Gaetios 2:85734ad35573 1256 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, buffer);
Gaetios 2:85734ad35573 1257 return buffer[0];
Gaetios 2:85734ad35573 1258 }
Gaetios 2:85734ad35573 1259 /** Set the enabled value for Slave 4 transaction interrupts.
Gaetios 2:85734ad35573 1260 * @param enabled New enabled value for Slave 4 transaction interrupts.
Gaetios 2:85734ad35573 1261 * @see getSlave4InterruptEnabled()
Gaetios 2:85734ad35573 1262 * @see MPU6050_RA_I2C_SLV4_CTRL
Gaetios 2:85734ad35573 1263 */
Gaetios 2:85734ad35573 1264 void MPU60503::setSlave4InterruptEnabled(bool enabled)
Gaetios 2:85734ad35573 1265 {
Gaetios 2:85734ad35573 1266 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, enabled);
Gaetios 2:85734ad35573 1267 }
Gaetios 2:85734ad35573 1268 /** Get write mode for Slave 4.
Gaetios 2:85734ad35573 1269 * When set to 1, the transaction will read or write data only. When cleared to
Gaetios 2:85734ad35573 1270 * 0, the transaction will write a register address prior to reading or writing
Gaetios 2:85734ad35573 1271 * data. This should equal 0 when specifying the register address within the
Gaetios 2:85734ad35573 1272 * Slave device to/from which the ensuing data transaction will take place.
Gaetios 2:85734ad35573 1273 *
Gaetios 2:85734ad35573 1274 * @return Current write mode for Slave 4 (0 = register address + data, 1 = data only)
Gaetios 2:85734ad35573 1275 * @see MPU6050_RA_I2C_SLV4_CTRL
Gaetios 2:85734ad35573 1276 */
Gaetios 2:85734ad35573 1277 bool MPU60503::getSlave4WriteMode()
Gaetios 2:85734ad35573 1278 {
Gaetios 2:85734ad35573 1279 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, buffer);
Gaetios 2:85734ad35573 1280 return buffer[0];
Gaetios 2:85734ad35573 1281 }
Gaetios 2:85734ad35573 1282 /** Set write mode for the Slave 4.
Gaetios 2:85734ad35573 1283 * @param mode New write mode for Slave 4 (0 = register address + data, 1 = data only)
Gaetios 2:85734ad35573 1284 * @see getSlave4WriteMode()
Gaetios 2:85734ad35573 1285 * @see MPU6050_RA_I2C_SLV4_CTRL
Gaetios 2:85734ad35573 1286 */
Gaetios 2:85734ad35573 1287 void MPU60503::setSlave4WriteMode(bool mode)
Gaetios 2:85734ad35573 1288 {
Gaetios 2:85734ad35573 1289 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, mode);
Gaetios 2:85734ad35573 1290 }
Gaetios 2:85734ad35573 1291 /** Get Slave 4 master delay value.
Gaetios 2:85734ad35573 1292 * This configures the reduced access rate of I2C slaves relative to the Sample
Gaetios 2:85734ad35573 1293 * Rate. When a slave's access rate is decreased relative to the Sample Rate,
Gaetios 2:85734ad35573 1294 * the slave is accessed every:
Gaetios 2:85734ad35573 1295 *
Gaetios 2:85734ad35573 1296 * 1 / (1 + I2C_MST_DLY) samples
Gaetios 2:85734ad35573 1297 *
Gaetios 2:85734ad35573 1298 * This base Sample Rate in turn is determined by SMPLRT_DIV (register 25) and
Gaetios 2:85734ad35573 1299 * DLPF_CFG (register 26). Whether a slave's access rate is reduced relative to
Gaetios 2:85734ad35573 1300 * the Sample Rate is determined by I2C_MST_DELAY_CTRL (register 103). For
Gaetios 2:85734ad35573 1301 * further information regarding the Sample Rate, please refer to register 25.
Gaetios 2:85734ad35573 1302 *
Gaetios 2:85734ad35573 1303 * @return Current Slave 4 master delay value
Gaetios 2:85734ad35573 1304 * @see MPU6050_RA_I2C_SLV4_CTRL
Gaetios 2:85734ad35573 1305 */
Gaetios 2:85734ad35573 1306 uint8_t MPU60503::getSlave4MasterDelay()
Gaetios 2:85734ad35573 1307 {
Gaetios 2:85734ad35573 1308 i2Cdev.readBits(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_MST_DLY_BIT, MPU6050_I2C_SLV4_MST_DLY_LENGTH, buffer);
Gaetios 2:85734ad35573 1309 return buffer[0];
Gaetios 2:85734ad35573 1310 }
Gaetios 2:85734ad35573 1311 /** Set Slave 4 master delay value.
Gaetios 2:85734ad35573 1312 * @param delay New Slave 4 master delay value
Gaetios 2:85734ad35573 1313 * @see getSlave4MasterDelay()
Gaetios 2:85734ad35573 1314 * @see MPU6050_RA_I2C_SLV4_CTRL
Gaetios 2:85734ad35573 1315 */
Gaetios 2:85734ad35573 1316 void MPU60503::setSlave4MasterDelay(uint8_t delay)
Gaetios 2:85734ad35573 1317 {
Gaetios 2:85734ad35573 1318 i2Cdev.writeBits(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_MST_DLY_BIT, MPU6050_I2C_SLV4_MST_DLY_LENGTH, delay);
Gaetios 2:85734ad35573 1319 }
Gaetios 2:85734ad35573 1320 /** Get last available byte read from Slave 4.
Gaetios 2:85734ad35573 1321 * This register stores the data read from Slave 4. This field is populated
Gaetios 2:85734ad35573 1322 * after a read transaction.
Gaetios 2:85734ad35573 1323 * @return Last available byte read from to Slave 4
Gaetios 2:85734ad35573 1324 * @see MPU6050_RA_I2C_SLV4_DI
Gaetios 2:85734ad35573 1325 */
Gaetios 2:85734ad35573 1326 uint8_t MPU60503::getSlate4InputByte()
Gaetios 2:85734ad35573 1327 {
Gaetios 2:85734ad35573 1328 i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_DI, buffer);
Gaetios 2:85734ad35573 1329 return buffer[0];
Gaetios 2:85734ad35573 1330 }
Gaetios 2:85734ad35573 1331
Gaetios 2:85734ad35573 1332 // I2C_MST_STATUS register
Gaetios 2:85734ad35573 1333
Gaetios 2:85734ad35573 1334 /** Get FSYNC interrupt status.
Gaetios 2:85734ad35573 1335 * This bit reflects the status of the FSYNC interrupt from an external device
Gaetios 2:85734ad35573 1336 * into the MPU-60X0. This is used as a way to pass an external interrupt
Gaetios 2:85734ad35573 1337 * through the MPU-60X0 to the host application processor. When set to 1, this
Gaetios 2:85734ad35573 1338 * bit will cause an interrupt if FSYNC_INT_EN is asserted in INT_PIN_CFG
Gaetios 2:85734ad35573 1339 * (Register 55).
Gaetios 2:85734ad35573 1340 * @return FSYNC interrupt status
Gaetios 2:85734ad35573 1341 * @see MPU6050_RA_I2C_MST_STATUS
Gaetios 2:85734ad35573 1342 */
Gaetios 2:85734ad35573 1343 bool MPU60503::getPassthroughStatus()
Gaetios 2:85734ad35573 1344 {
Gaetios 2:85734ad35573 1345 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_PASS_THROUGH_BIT, buffer);
Gaetios 2:85734ad35573 1346 return buffer[0];
Gaetios 2:85734ad35573 1347 }
Gaetios 2:85734ad35573 1348 /** Get Slave 4 transaction done status.
Gaetios 2:85734ad35573 1349 * Automatically sets to 1 when a Slave 4 transaction has completed. This
Gaetios 2:85734ad35573 1350 * triggers an interrupt if the I2C_MST_INT_EN bit in the INT_ENABLE register
Gaetios 2:85734ad35573 1351 * (Register 56) is asserted and if the SLV_4_DONE_INT bit is asserted in the
Gaetios 2:85734ad35573 1352 * I2C_SLV4_CTRL register (Register 52).
Gaetios 2:85734ad35573 1353 * @return Slave 4 transaction done status
Gaetios 2:85734ad35573 1354 * @see MPU6050_RA_I2C_MST_STATUS
Gaetios 2:85734ad35573 1355 */
Gaetios 2:85734ad35573 1356 bool MPU60503::getSlave4IsDone()
Gaetios 2:85734ad35573 1357 {
Gaetios 2:85734ad35573 1358 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_DONE_BIT, buffer);
Gaetios 2:85734ad35573 1359 return buffer[0];
Gaetios 2:85734ad35573 1360 }
Gaetios 2:85734ad35573 1361 /** Get master arbitration lost status.
Gaetios 2:85734ad35573 1362 * This bit automatically sets to 1 when the I2C Master has lost arbitration of
Gaetios 2:85734ad35573 1363 * the auxiliary I2C bus (an error condition). This triggers an interrupt if the
Gaetios 2:85734ad35573 1364 * I2C_MST_INT_EN bit in the INT_ENABLE register (Register 56) is asserted.
Gaetios 2:85734ad35573 1365 * @return Master arbitration lost status
Gaetios 2:85734ad35573 1366 * @see MPU6050_RA_I2C_MST_STATUS
Gaetios 2:85734ad35573 1367 */
Gaetios 2:85734ad35573 1368 bool MPU60503::getLostArbitration()
Gaetios 2:85734ad35573 1369 {
Gaetios 2:85734ad35573 1370 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_LOST_ARB_BIT, buffer);
Gaetios 2:85734ad35573 1371 return buffer[0];
Gaetios 2:85734ad35573 1372 }
Gaetios 2:85734ad35573 1373 /** Get Slave 4 NACK status.
Gaetios 2:85734ad35573 1374 * This bit automatically sets to 1 when the I2C Master receives a NACK in a
Gaetios 2:85734ad35573 1375 * transaction with Slave 4. This triggers an interrupt if the I2C_MST_INT_EN
Gaetios 2:85734ad35573 1376 * bit in the INT_ENABLE register (Register 56) is asserted.
Gaetios 2:85734ad35573 1377 * @return Slave 4 NACK interrupt status
Gaetios 2:85734ad35573 1378 * @see MPU6050_RA_I2C_MST_STATUS
Gaetios 2:85734ad35573 1379 */
Gaetios 2:85734ad35573 1380 bool MPU60503::getSlave4Nack()
Gaetios 2:85734ad35573 1381 {
Gaetios 2:85734ad35573 1382 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_NACK_BIT, buffer);
Gaetios 2:85734ad35573 1383 return buffer[0];
Gaetios 2:85734ad35573 1384 }
Gaetios 2:85734ad35573 1385 /** Get Slave 3 NACK status.
Gaetios 2:85734ad35573 1386 * This bit automatically sets to 1 when the I2C Master receives a NACK in a
Gaetios 2:85734ad35573 1387 * transaction with Slave 3. This triggers an interrupt if the I2C_MST_INT_EN
Gaetios 2:85734ad35573 1388 * bit in the INT_ENABLE register (Register 56) is asserted.
Gaetios 2:85734ad35573 1389 * @return Slave 3 NACK interrupt status
Gaetios 2:85734ad35573 1390 * @see MPU6050_RA_I2C_MST_STATUS
Gaetios 2:85734ad35573 1391 */
Gaetios 2:85734ad35573 1392 bool MPU60503::getSlave3Nack()
Gaetios 2:85734ad35573 1393 {
Gaetios 2:85734ad35573 1394 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV3_NACK_BIT, buffer);
Gaetios 2:85734ad35573 1395 return buffer[0];
Gaetios 2:85734ad35573 1396 }
Gaetios 2:85734ad35573 1397 /** Get Slave 2 NACK status.
Gaetios 2:85734ad35573 1398 * This bit automatically sets to 1 when the I2C Master receives a NACK in a
Gaetios 2:85734ad35573 1399 * transaction with Slave 2. This triggers an interrupt if the I2C_MST_INT_EN
Gaetios 2:85734ad35573 1400 * bit in the INT_ENABLE register (Register 56) is asserted.
Gaetios 2:85734ad35573 1401 * @return Slave 2 NACK interrupt status
Gaetios 2:85734ad35573 1402 * @see MPU6050_RA_I2C_MST_STATUS
Gaetios 2:85734ad35573 1403 */
Gaetios 2:85734ad35573 1404 bool MPU60503::getSlave2Nack()
Gaetios 2:85734ad35573 1405 {
Gaetios 2:85734ad35573 1406 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV2_NACK_BIT, buffer);
Gaetios 2:85734ad35573 1407 return buffer[0];
Gaetios 2:85734ad35573 1408 }
Gaetios 2:85734ad35573 1409 /** Get Slave 1 NACK status.
Gaetios 2:85734ad35573 1410 * This bit automatically sets to 1 when the I2C Master receives a NACK in a
Gaetios 2:85734ad35573 1411 * transaction with Slave 1. This triggers an interrupt if the I2C_MST_INT_EN
Gaetios 2:85734ad35573 1412 * bit in the INT_ENABLE register (Register 56) is asserted.
Gaetios 2:85734ad35573 1413 * @return Slave 1 NACK interrupt status
Gaetios 2:85734ad35573 1414 * @see MPU6050_RA_I2C_MST_STATUS
Gaetios 2:85734ad35573 1415 */
Gaetios 2:85734ad35573 1416 bool MPU60503::getSlave1Nack()
Gaetios 2:85734ad35573 1417 {
Gaetios 2:85734ad35573 1418 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV1_NACK_BIT, buffer);
Gaetios 2:85734ad35573 1419 return buffer[0];
Gaetios 2:85734ad35573 1420 }
Gaetios 2:85734ad35573 1421 /** Get Slave 0 NACK status.
Gaetios 2:85734ad35573 1422 * This bit automatically sets to 1 when the I2C Master receives a NACK in a
Gaetios 2:85734ad35573 1423 * transaction with Slave 0. This triggers an interrupt if the I2C_MST_INT_EN
Gaetios 2:85734ad35573 1424 * bit in the INT_ENABLE register (Register 56) is asserted.
Gaetios 2:85734ad35573 1425 * @return Slave 0 NACK interrupt status
Gaetios 2:85734ad35573 1426 * @see MPU6050_RA_I2C_MST_STATUS
Gaetios 2:85734ad35573 1427 */
Gaetios 2:85734ad35573 1428 bool MPU60503::getSlave0Nack()
Gaetios 2:85734ad35573 1429 {
Gaetios 2:85734ad35573 1430 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV0_NACK_BIT, buffer);
Gaetios 2:85734ad35573 1431 return buffer[0];
Gaetios 2:85734ad35573 1432 }
Gaetios 2:85734ad35573 1433
Gaetios 2:85734ad35573 1434 // INT_PIN_CFG register
Gaetios 2:85734ad35573 1435
Gaetios 2:85734ad35573 1436 /** Get interrupt logic level mode.
Gaetios 2:85734ad35573 1437 * Will be set 0 for active-high, 1 for active-low.
Gaetios 2:85734ad35573 1438 * @return Current interrupt mode (0=active-high, 1=active-low)
Gaetios 2:85734ad35573 1439 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1440 * @see MPU6050_INTCFG_INT_LEVEL_BIT
Gaetios 2:85734ad35573 1441 */
Gaetios 2:85734ad35573 1442 bool MPU60503::getInterruptMode()
Gaetios 2:85734ad35573 1443 {
Gaetios 2:85734ad35573 1444 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, buffer);
Gaetios 2:85734ad35573 1445 return buffer[0];
Gaetios 2:85734ad35573 1446 }
Gaetios 2:85734ad35573 1447 /** Set interrupt logic level mode.
Gaetios 2:85734ad35573 1448 * @param mode New interrupt mode (0=active-high, 1=active-low)
Gaetios 2:85734ad35573 1449 * @see getInterruptMode()
Gaetios 2:85734ad35573 1450 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1451 * @see MPU6050_INTCFG_INT_LEVEL_BIT
Gaetios 2:85734ad35573 1452 */
Gaetios 2:85734ad35573 1453 void MPU60503::setInterruptMode(bool mode)
Gaetios 2:85734ad35573 1454 {
Gaetios 2:85734ad35573 1455 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, mode);
Gaetios 2:85734ad35573 1456 }
Gaetios 2:85734ad35573 1457 /** Get interrupt drive mode.
Gaetios 2:85734ad35573 1458 * Will be set 0 for push-pull, 1 for open-drain.
Gaetios 2:85734ad35573 1459 * @return Current interrupt drive mode (0=push-pull, 1=open-drain)
Gaetios 2:85734ad35573 1460 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1461 * @see MPU6050_INTCFG_INT_OPEN_BIT
Gaetios 2:85734ad35573 1462 */
Gaetios 2:85734ad35573 1463 bool MPU60503::getInterruptDrive()
Gaetios 2:85734ad35573 1464 {
Gaetios 2:85734ad35573 1465 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, buffer);
Gaetios 2:85734ad35573 1466 return buffer[0];
Gaetios 2:85734ad35573 1467 }
Gaetios 2:85734ad35573 1468 /** Set interrupt drive mode.
Gaetios 2:85734ad35573 1469 * @param drive New interrupt drive mode (0=push-pull, 1=open-drain)
Gaetios 2:85734ad35573 1470 * @see getInterruptDrive()
Gaetios 2:85734ad35573 1471 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1472 * @see MPU6050_INTCFG_INT_OPEN_BIT
Gaetios 2:85734ad35573 1473 */
Gaetios 2:85734ad35573 1474 void MPU60503::setInterruptDrive(bool drive)
Gaetios 2:85734ad35573 1475 {
Gaetios 2:85734ad35573 1476 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, drive);
Gaetios 2:85734ad35573 1477 }
Gaetios 2:85734ad35573 1478 /** Get interrupt latch mode.
Gaetios 2:85734ad35573 1479 * Will be set 0 for 50us-pulse, 1 for latch-until-int-cleared.
Gaetios 2:85734ad35573 1480 * @return Current latch mode (0=50us-pulse, 1=latch-until-int-cleared)
Gaetios 2:85734ad35573 1481 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1482 * @see MPU6050_INTCFG_LATCH_INT_EN_BIT
Gaetios 2:85734ad35573 1483 */
Gaetios 2:85734ad35573 1484 bool MPU60503::getInterruptLatch()
Gaetios 2:85734ad35573 1485 {
Gaetios 2:85734ad35573 1486 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, buffer);
Gaetios 2:85734ad35573 1487 return buffer[0];
Gaetios 2:85734ad35573 1488 }
Gaetios 2:85734ad35573 1489 /** Set interrupt latch mode.
Gaetios 2:85734ad35573 1490 * @param latch New latch mode (0=50us-pulse, 1=latch-until-int-cleared)
Gaetios 2:85734ad35573 1491 * @see getInterruptLatch()
Gaetios 2:85734ad35573 1492 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1493 * @see MPU6050_INTCFG_LATCH_INT_EN_BIT
Gaetios 2:85734ad35573 1494 */
Gaetios 2:85734ad35573 1495 void MPU60503::setInterruptLatch(bool latch)
Gaetios 2:85734ad35573 1496 {
Gaetios 2:85734ad35573 1497 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, latch);
Gaetios 2:85734ad35573 1498 }
Gaetios 2:85734ad35573 1499 /** Get interrupt latch clear mode.
Gaetios 2:85734ad35573 1500 * Will be set 0 for status-read-only, 1 for any-register-read.
Gaetios 2:85734ad35573 1501 * @return Current latch clear mode (0=status-read-only, 1=any-register-read)
Gaetios 2:85734ad35573 1502 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1503 * @see MPU6050_INTCFG_INT_RD_CLEAR_BIT
Gaetios 2:85734ad35573 1504 */
Gaetios 2:85734ad35573 1505 bool MPU60503::getInterruptLatchClear()
Gaetios 2:85734ad35573 1506 {
Gaetios 2:85734ad35573 1507 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, buffer);
Gaetios 2:85734ad35573 1508 return buffer[0];
Gaetios 2:85734ad35573 1509 }
Gaetios 2:85734ad35573 1510 /** Set interrupt latch clear mode.
Gaetios 2:85734ad35573 1511 * @param clear New latch clear mode (0=status-read-only, 1=any-register-read)
Gaetios 2:85734ad35573 1512 * @see getInterruptLatchClear()
Gaetios 2:85734ad35573 1513 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1514 * @see MPU6050_INTCFG_INT_RD_CLEAR_BIT
Gaetios 2:85734ad35573 1515 */
Gaetios 2:85734ad35573 1516 void MPU60503::setInterruptLatchClear(bool clear)
Gaetios 2:85734ad35573 1517 {
Gaetios 2:85734ad35573 1518 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, clear);
Gaetios 2:85734ad35573 1519 }
Gaetios 2:85734ad35573 1520 /** Get FSYNC interrupt logic level mode.
Gaetios 2:85734ad35573 1521 * @return Current FSYNC interrupt mode (0=active-high, 1=active-low)
Gaetios 2:85734ad35573 1522 * @see getFSyncInterruptMode()
Gaetios 2:85734ad35573 1523 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1524 * @see MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT
Gaetios 2:85734ad35573 1525 */
Gaetios 2:85734ad35573 1526 bool MPU60503::getFSyncInterruptLevel()
Gaetios 2:85734ad35573 1527 {
Gaetios 2:85734ad35573 1528 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, buffer);
Gaetios 2:85734ad35573 1529 return buffer[0];
Gaetios 2:85734ad35573 1530 }
Gaetios 2:85734ad35573 1531 /** Set FSYNC interrupt logic level mode.
Gaetios 2:85734ad35573 1532 * @param mode New FSYNC interrupt mode (0=active-high, 1=active-low)
Gaetios 2:85734ad35573 1533 * @see getFSyncInterruptMode()
Gaetios 2:85734ad35573 1534 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1535 * @see MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT
Gaetios 2:85734ad35573 1536 */
Gaetios 2:85734ad35573 1537 void MPU60503::setFSyncInterruptLevel(bool level)
Gaetios 2:85734ad35573 1538 {
Gaetios 2:85734ad35573 1539 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, level);
Gaetios 2:85734ad35573 1540 }
Gaetios 2:85734ad35573 1541 /** Get FSYNC pin interrupt enabled setting.
Gaetios 2:85734ad35573 1542 * Will be set 0 for disabled, 1 for enabled.
Gaetios 2:85734ad35573 1543 * @return Current interrupt enabled setting
Gaetios 2:85734ad35573 1544 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1545 * @see MPU6050_INTCFG_FSYNC_INT_EN_BIT
Gaetios 2:85734ad35573 1546 */
Gaetios 2:85734ad35573 1547 bool MPU60503::getFSyncInterruptEnabled()
Gaetios 2:85734ad35573 1548 {
Gaetios 2:85734ad35573 1549 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, buffer);
Gaetios 2:85734ad35573 1550 return buffer[0];
Gaetios 2:85734ad35573 1551 }
Gaetios 2:85734ad35573 1552 /** Set FSYNC pin interrupt enabled setting.
Gaetios 2:85734ad35573 1553 * @param enabled New FSYNC pin interrupt enabled setting
Gaetios 2:85734ad35573 1554 * @see getFSyncInterruptEnabled()
Gaetios 2:85734ad35573 1555 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1556 * @see MPU6050_INTCFG_FSYNC_INT_EN_BIT
Gaetios 2:85734ad35573 1557 */
Gaetios 2:85734ad35573 1558 void MPU60503::setFSyncInterruptEnabled(bool enabled)
Gaetios 2:85734ad35573 1559 {
Gaetios 2:85734ad35573 1560 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, enabled);
Gaetios 2:85734ad35573 1561 }
Gaetios 2:85734ad35573 1562 /** Get I2C bypass enabled status.
Gaetios 2:85734ad35573 1563 * When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is equal to
Gaetios 2:85734ad35573 1564 * 0, the host application processor will be able to directly access the
Gaetios 2:85734ad35573 1565 * auxiliary I2C bus of the MPU-60X0. When this bit is equal to 0, the host
Gaetios 2:85734ad35573 1566 * application processor will not be able to directly access the auxiliary I2C
Gaetios 2:85734ad35573 1567 * bus of the MPU-60X0 regardless of the state of I2C_MST_EN (Register 106
Gaetios 2:85734ad35573 1568 * bit[5]).
Gaetios 2:85734ad35573 1569 * @return Current I2C bypass enabled status
Gaetios 2:85734ad35573 1570 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1571 * @see MPU6050_INTCFG_I2C_BYPASS_EN_BIT
Gaetios 2:85734ad35573 1572 */
Gaetios 2:85734ad35573 1573 bool MPU60503::getI2CBypassEnabled()
Gaetios 2:85734ad35573 1574 {
Gaetios 2:85734ad35573 1575 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, buffer);
Gaetios 2:85734ad35573 1576 return buffer[0];
Gaetios 2:85734ad35573 1577 }
Gaetios 2:85734ad35573 1578 /** Set I2C bypass enabled status.
Gaetios 2:85734ad35573 1579 * When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is equal to
Gaetios 2:85734ad35573 1580 * 0, the host application processor will be able to directly access the
Gaetios 2:85734ad35573 1581 * auxiliary I2C bus of the MPU-60X0. When this bit is equal to 0, the host
Gaetios 2:85734ad35573 1582 * application processor will not be able to directly access the auxiliary I2C
Gaetios 2:85734ad35573 1583 * bus of the MPU-60X0 regardless of the state of I2C_MST_EN (Register 106
Gaetios 2:85734ad35573 1584 * bit[5]).
Gaetios 2:85734ad35573 1585 * @param enabled New I2C bypass enabled status
Gaetios 2:85734ad35573 1586 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1587 * @see MPU6050_INTCFG_I2C_BYPASS_EN_BIT
Gaetios 2:85734ad35573 1588 */
Gaetios 2:85734ad35573 1589 void MPU60503::setI2CBypassEnabled(bool enabled)
Gaetios 2:85734ad35573 1590 {
Gaetios 2:85734ad35573 1591 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, enabled);
Gaetios 2:85734ad35573 1592 }
Gaetios 2:85734ad35573 1593 /** Get reference clock output enabled status.
Gaetios 2:85734ad35573 1594 * When this bit is equal to 1, a reference clock output is provided at the
Gaetios 2:85734ad35573 1595 * CLKOUT pin. When this bit is equal to 0, the clock output is disabled. For
Gaetios 2:85734ad35573 1596 * further information regarding CLKOUT, please refer to the MPU-60X0 Product
Gaetios 2:85734ad35573 1597 * Specification document.
Gaetios 2:85734ad35573 1598 * @return Current reference clock output enabled status
Gaetios 2:85734ad35573 1599 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1600 * @see MPU6050_INTCFG_CLKOUT_EN_BIT
Gaetios 2:85734ad35573 1601 */
Gaetios 2:85734ad35573 1602 bool MPU60503::getClockOutputEnabled()
Gaetios 2:85734ad35573 1603 {
Gaetios 2:85734ad35573 1604 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, buffer);
Gaetios 2:85734ad35573 1605 return buffer[0];
Gaetios 2:85734ad35573 1606 }
Gaetios 2:85734ad35573 1607 /** Set reference clock output enabled status.
Gaetios 2:85734ad35573 1608 * When this bit is equal to 1, a reference clock output is provided at the
Gaetios 2:85734ad35573 1609 * CLKOUT pin. When this bit is equal to 0, the clock output is disabled. For
Gaetios 2:85734ad35573 1610 * further information regarding CLKOUT, please refer to the MPU-60X0 Product
Gaetios 2:85734ad35573 1611 * Specification document.
Gaetios 2:85734ad35573 1612 * @param enabled New reference clock output enabled status
Gaetios 2:85734ad35573 1613 * @see MPU6050_RA_INT_PIN_CFG
Gaetios 2:85734ad35573 1614 * @see MPU6050_INTCFG_CLKOUT_EN_BIT
Gaetios 2:85734ad35573 1615 */
Gaetios 2:85734ad35573 1616 void MPU60503::setClockOutputEnabled(bool enabled)
Gaetios 2:85734ad35573 1617 {
Gaetios 2:85734ad35573 1618 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, enabled);
Gaetios 2:85734ad35573 1619 }
Gaetios 2:85734ad35573 1620
Gaetios 2:85734ad35573 1621 // INT_ENABLE register
Gaetios 2:85734ad35573 1622
Gaetios 2:85734ad35573 1623 /** Get full interrupt enabled status.
Gaetios 2:85734ad35573 1624 * Full register byte for all interrupts, for quick reading. Each bit will be
Gaetios 2:85734ad35573 1625 * set 0 for disabled, 1 for enabled.
Gaetios 2:85734ad35573 1626 * @return Current interrupt enabled status
Gaetios 2:85734ad35573 1627 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1628 * @see MPU6050_INTERRUPT_FF_BIT
Gaetios 2:85734ad35573 1629 **/
Gaetios 2:85734ad35573 1630 uint8_t MPU60503::getIntEnabled()
Gaetios 2:85734ad35573 1631 {
Gaetios 2:85734ad35573 1632 i2Cdev.readByte(devAddr, MPU6050_RA_INT_ENABLE, buffer);
Gaetios 2:85734ad35573 1633 return buffer[0];
Gaetios 2:85734ad35573 1634 }
Gaetios 2:85734ad35573 1635 /** Set full interrupt enabled status.
Gaetios 2:85734ad35573 1636 * Full register byte for all interrupts, for quick reading. Each bit should be
Gaetios 2:85734ad35573 1637 * set 0 for disabled, 1 for enabled.
Gaetios 2:85734ad35573 1638 * @param enabled New interrupt enabled status
Gaetios 2:85734ad35573 1639 * @see getIntFreefallEnabled()
Gaetios 2:85734ad35573 1640 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1641 * @see MPU6050_INTERRUPT_FF_BIT
Gaetios 2:85734ad35573 1642 **/
Gaetios 2:85734ad35573 1643 void MPU60503::setIntEnabled(uint8_t enabled)
Gaetios 2:85734ad35573 1644 {
Gaetios 2:85734ad35573 1645 i2Cdev.writeByte(devAddr, MPU6050_RA_INT_ENABLE, enabled);
Gaetios 2:85734ad35573 1646 }
Gaetios 2:85734ad35573 1647 /** Get Free Fall interrupt enabled status.
Gaetios 2:85734ad35573 1648 * Will be set 0 for disabled, 1 for enabled.
Gaetios 2:85734ad35573 1649 * @return Current interrupt enabled status
Gaetios 2:85734ad35573 1650 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1651 * @see MPU6050_INTERRUPT_FF_BIT
Gaetios 2:85734ad35573 1652 **/
Gaetios 2:85734ad35573 1653 bool MPU60503::getIntFreefallEnabled()
Gaetios 2:85734ad35573 1654 {
Gaetios 2:85734ad35573 1655 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, buffer);
Gaetios 2:85734ad35573 1656 return buffer[0];
Gaetios 2:85734ad35573 1657 }
Gaetios 2:85734ad35573 1658 /** Set Free Fall interrupt enabled status.
Gaetios 2:85734ad35573 1659 * @param enabled New interrupt enabled status
Gaetios 2:85734ad35573 1660 * @see getIntFreefallEnabled()
Gaetios 2:85734ad35573 1661 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1662 * @see MPU6050_INTERRUPT_FF_BIT
Gaetios 2:85734ad35573 1663 **/
Gaetios 2:85734ad35573 1664 void MPU60503::setIntFreefallEnabled(bool enabled)
Gaetios 2:85734ad35573 1665 {
Gaetios 2:85734ad35573 1666 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, enabled);
Gaetios 2:85734ad35573 1667 }
Gaetios 2:85734ad35573 1668 /** Get Motion Detection interrupt enabled status.
Gaetios 2:85734ad35573 1669 * Will be set 0 for disabled, 1 for enabled.
Gaetios 2:85734ad35573 1670 * @return Current interrupt enabled status
Gaetios 2:85734ad35573 1671 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1672 * @see MPU6050_INTERRUPT_MOT_BIT
Gaetios 2:85734ad35573 1673 **/
Gaetios 2:85734ad35573 1674 bool MPU60503::getIntMotionEnabled()
Gaetios 2:85734ad35573 1675 {
Gaetios 2:85734ad35573 1676 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, buffer);
Gaetios 2:85734ad35573 1677 return buffer[0];
Gaetios 2:85734ad35573 1678 }
Gaetios 2:85734ad35573 1679 /** Set Motion Detection interrupt enabled status.
Gaetios 2:85734ad35573 1680 * @param enabled New interrupt enabled status
Gaetios 2:85734ad35573 1681 * @see getIntMotionEnabled()
Gaetios 2:85734ad35573 1682 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1683 * @see MPU6050_INTERRUPT_MOT_BIT
Gaetios 2:85734ad35573 1684 **/
Gaetios 2:85734ad35573 1685 void MPU60503::setIntMotionEnabled(bool enabled)
Gaetios 2:85734ad35573 1686 {
Gaetios 2:85734ad35573 1687 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, enabled);
Gaetios 2:85734ad35573 1688 }
Gaetios 2:85734ad35573 1689 /** Get Zero Motion Detection interrupt enabled status.
Gaetios 2:85734ad35573 1690 * Will be set 0 for disabled, 1 for enabled.
Gaetios 2:85734ad35573 1691 * @return Current interrupt enabled status
Gaetios 2:85734ad35573 1692 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1693 * @see MPU6050_INTERRUPT_ZMOT_BIT
Gaetios 2:85734ad35573 1694 **/
Gaetios 2:85734ad35573 1695 bool MPU60503::getIntZeroMotionEnabled()
Gaetios 2:85734ad35573 1696 {
Gaetios 2:85734ad35573 1697 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, buffer);
Gaetios 2:85734ad35573 1698 return buffer[0];
Gaetios 2:85734ad35573 1699 }
Gaetios 2:85734ad35573 1700 /** Set Zero Motion Detection interrupt enabled status.
Gaetios 2:85734ad35573 1701 * @param enabled New interrupt enabled status
Gaetios 2:85734ad35573 1702 * @see getIntZeroMotionEnabled()
Gaetios 2:85734ad35573 1703 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1704 * @see MPU6050_INTERRUPT_ZMOT_BIT
Gaetios 2:85734ad35573 1705 **/
Gaetios 2:85734ad35573 1706 void MPU60503::setIntZeroMotionEnabled(bool enabled)
Gaetios 2:85734ad35573 1707 {
Gaetios 2:85734ad35573 1708 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, enabled);
Gaetios 2:85734ad35573 1709 }
Gaetios 2:85734ad35573 1710 /** Get FIFO Buffer Overflow interrupt enabled status.
Gaetios 2:85734ad35573 1711 * Will be set 0 for disabled, 1 for enabled.
Gaetios 2:85734ad35573 1712 * @return Current interrupt enabled status
Gaetios 2:85734ad35573 1713 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1714 * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT
Gaetios 2:85734ad35573 1715 **/
Gaetios 2:85734ad35573 1716 bool MPU60503::getIntFIFOBufferOverflowEnabled()
Gaetios 2:85734ad35573 1717 {
Gaetios 2:85734ad35573 1718 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer);
Gaetios 2:85734ad35573 1719 return buffer[0];
Gaetios 2:85734ad35573 1720 }
Gaetios 2:85734ad35573 1721 /** Set FIFO Buffer Overflow interrupt enabled status.
Gaetios 2:85734ad35573 1722 * @param enabled New interrupt enabled status
Gaetios 2:85734ad35573 1723 * @see getIntFIFOBufferOverflowEnabled()
Gaetios 2:85734ad35573 1724 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1725 * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT
Gaetios 2:85734ad35573 1726 **/
Gaetios 2:85734ad35573 1727 void MPU60503::setIntFIFOBufferOverflowEnabled(bool enabled)
Gaetios 2:85734ad35573 1728 {
Gaetios 2:85734ad35573 1729 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, enabled);
Gaetios 2:85734ad35573 1730 }
Gaetios 2:85734ad35573 1731 /** Get I2C Master interrupt enabled status.
Gaetios 2:85734ad35573 1732 * This enables any of the I2C Master interrupt sources to generate an
Gaetios 2:85734ad35573 1733 * interrupt. Will be set 0 for disabled, 1 for enabled.
Gaetios 2:85734ad35573 1734 * @return Current interrupt enabled status
Gaetios 2:85734ad35573 1735 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1736 * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT
Gaetios 2:85734ad35573 1737 **/
Gaetios 2:85734ad35573 1738 bool MPU60503::getIntI2CMasterEnabled()
Gaetios 2:85734ad35573 1739 {
Gaetios 2:85734ad35573 1740 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer);
Gaetios 2:85734ad35573 1741 return buffer[0];
Gaetios 2:85734ad35573 1742 }
Gaetios 2:85734ad35573 1743 /** Set I2C Master interrupt enabled status.
Gaetios 2:85734ad35573 1744 * @param enabled New interrupt enabled status
Gaetios 2:85734ad35573 1745 * @see getIntI2CMasterEnabled()
Gaetios 2:85734ad35573 1746 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1747 * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT
Gaetios 2:85734ad35573 1748 **/
Gaetios 2:85734ad35573 1749 void MPU60503::setIntI2CMasterEnabled(bool enabled)
Gaetios 2:85734ad35573 1750 {
Gaetios 2:85734ad35573 1751 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, enabled);
Gaetios 2:85734ad35573 1752 }
Gaetios 2:85734ad35573 1753 /** Get Data Ready interrupt enabled setting.
Gaetios 2:85734ad35573 1754 * This event occurs each time a write operation to all of the sensor registers
Gaetios 2:85734ad35573 1755 * has been completed. Will be set 0 for disabled, 1 for enabled.
Gaetios 2:85734ad35573 1756 * @return Current interrupt enabled status
Gaetios 2:85734ad35573 1757 * @see MPU6050_RA_INT_ENABLE
Gaetios 2:85734ad35573 1758 * @see MPU6050_INTERRUPT_DATA_RDY_BIT
Gaetios 2:85734ad35573 1759 */
Gaetios 2:85734ad35573 1760 bool MPU60503::getIntDataReadyEnabled()
Gaetios 2:85734ad35573 1761 {
Gaetios 2:85734ad35573 1762 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer);
Gaetios 2:85734ad35573 1763 return buffer[0];
Gaetios 2:85734ad35573 1764 }
Gaetios 2:85734ad35573 1765 /** Set Data Ready interrupt enabled status.
Gaetios 2:85734ad35573 1766 * @param enabled New interrupt enabled status
Gaetios 2:85734ad35573 1767 * @see getIntDataReadyEnabled()
Gaetios 2:85734ad35573 1768 * @see MPU6050_RA_INT_CFG
Gaetios 2:85734ad35573 1769 * @see MPU6050_INTERRUPT_DATA_RDY_BIT
Gaetios 2:85734ad35573 1770 */
Gaetios 2:85734ad35573 1771 void MPU60503::setIntDataReadyEnabled(bool enabled)
Gaetios 2:85734ad35573 1772 {
Gaetios 2:85734ad35573 1773 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, enabled);
Gaetios 2:85734ad35573 1774 }
Gaetios 2:85734ad35573 1775
Gaetios 2:85734ad35573 1776 // INT_STATUS register
Gaetios 2:85734ad35573 1777
Gaetios 2:85734ad35573 1778 /** Get full set of interrupt status bits.
Gaetios 2:85734ad35573 1779 * These bits clear to 0 after the register has been read. Very useful
Gaetios 2:85734ad35573 1780 * for getting multiple INT statuses, since each single bit read clears
Gaetios 2:85734ad35573 1781 * all of them because it has to read the whole byte.
Gaetios 2:85734ad35573 1782 * @return Current interrupt status
Gaetios 2:85734ad35573 1783 * @see MPU6050_RA_INT_STATUS
Gaetios 2:85734ad35573 1784 */
Gaetios 2:85734ad35573 1785 uint8_t MPU60503::getIntStatus()
Gaetios 2:85734ad35573 1786 {
Gaetios 2:85734ad35573 1787 i2Cdev.readByte(devAddr, MPU6050_RA_INT_STATUS, buffer);
Gaetios 2:85734ad35573 1788 return buffer[0];
Gaetios 2:85734ad35573 1789 }
Gaetios 2:85734ad35573 1790 /** Get Free Fall interrupt status.
Gaetios 2:85734ad35573 1791 * This bit automatically sets to 1 when a Free Fall interrupt has been
Gaetios 2:85734ad35573 1792 * generated. The bit clears to 0 after the register has been read.
Gaetios 2:85734ad35573 1793 * @return Current interrupt status
Gaetios 2:85734ad35573 1794 * @see MPU6050_RA_INT_STATUS
Gaetios 2:85734ad35573 1795 * @see MPU6050_INTERRUPT_FF_BIT
Gaetios 2:85734ad35573 1796 */
Gaetios 2:85734ad35573 1797 bool MPU60503::getIntFreefallStatus()
Gaetios 2:85734ad35573 1798 {
Gaetios 2:85734ad35573 1799 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FF_BIT, buffer);
Gaetios 2:85734ad35573 1800 return buffer[0];
Gaetios 2:85734ad35573 1801 }
Gaetios 2:85734ad35573 1802 /** Get Motion Detection interrupt status.
Gaetios 2:85734ad35573 1803 * This bit automatically sets to 1 when a Motion Detection interrupt has been
Gaetios 2:85734ad35573 1804 * generated. The bit clears to 0 after the register has been read.
Gaetios 2:85734ad35573 1805 * @return Current interrupt status
Gaetios 2:85734ad35573 1806 * @see MPU6050_RA_INT_STATUS
Gaetios 2:85734ad35573 1807 * @see MPU6050_INTERRUPT_MOT_BIT
Gaetios 2:85734ad35573 1808 */
Gaetios 2:85734ad35573 1809 bool MPU60503::getIntMotionStatus()
Gaetios 2:85734ad35573 1810 {
Gaetios 2:85734ad35573 1811 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_MOT_BIT, buffer);
Gaetios 2:85734ad35573 1812 return buffer[0];
Gaetios 2:85734ad35573 1813 }
Gaetios 2:85734ad35573 1814 /** Get Zero Motion Detection interrupt status.
Gaetios 2:85734ad35573 1815 * This bit automatically sets to 1 when a Zero Motion Detection interrupt has
Gaetios 2:85734ad35573 1816 * been generated. The bit clears to 0 after the register has been read.
Gaetios 2:85734ad35573 1817 * @return Current interrupt status
Gaetios 2:85734ad35573 1818 * @see MPU6050_RA_INT_STATUS
Gaetios 2:85734ad35573 1819 * @see MPU6050_INTERRUPT_ZMOT_BIT
Gaetios 2:85734ad35573 1820 */
Gaetios 2:85734ad35573 1821 bool MPU60503::getIntZeroMotionStatus()
Gaetios 2:85734ad35573 1822 {
Gaetios 2:85734ad35573 1823 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_ZMOT_BIT, buffer);
Gaetios 2:85734ad35573 1824 return buffer[0];
Gaetios 2:85734ad35573 1825 }
Gaetios 2:85734ad35573 1826 /** Get FIFO Buffer Overflow interrupt status.
Gaetios 2:85734ad35573 1827 * This bit automatically sets to 1 when a Free Fall interrupt has been
Gaetios 2:85734ad35573 1828 * generated. The bit clears to 0 after the register has been read.
Gaetios 2:85734ad35573 1829 * @return Current interrupt status
Gaetios 2:85734ad35573 1830 * @see MPU6050_RA_INT_STATUS
Gaetios 2:85734ad35573 1831 * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT
Gaetios 2:85734ad35573 1832 */
Gaetios 2:85734ad35573 1833 bool MPU60503::getIntFIFOBufferOverflowStatus()
Gaetios 2:85734ad35573 1834 {
Gaetios 2:85734ad35573 1835 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer);
Gaetios 2:85734ad35573 1836 return buffer[0];
Gaetios 2:85734ad35573 1837 }
Gaetios 2:85734ad35573 1838 /** Get I2C Master interrupt status.
Gaetios 2:85734ad35573 1839 * This bit automatically sets to 1 when an I2C Master interrupt has been
Gaetios 2:85734ad35573 1840 * generated. For a list of I2C Master interrupts, please refer to Register 54.
Gaetios 2:85734ad35573 1841 * The bit clears to 0 after the register has been read.
Gaetios 2:85734ad35573 1842 * @return Current interrupt status
Gaetios 2:85734ad35573 1843 * @see MPU6050_RA_INT_STATUS
Gaetios 2:85734ad35573 1844 * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT
Gaetios 2:85734ad35573 1845 */
Gaetios 2:85734ad35573 1846 bool MPU60503::getIntI2CMasterStatus()
Gaetios 2:85734ad35573 1847 {
Gaetios 2:85734ad35573 1848 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer);
Gaetios 2:85734ad35573 1849 return buffer[0];
Gaetios 2:85734ad35573 1850 }
Gaetios 2:85734ad35573 1851 /** Get Data Ready interrupt status.
Gaetios 2:85734ad35573 1852 * This bit automatically sets to 1 when a Data Ready interrupt has been
Gaetios 2:85734ad35573 1853 * generated. The bit clears to 0 after the register has been read.
Gaetios 2:85734ad35573 1854 * @return Current interrupt status
Gaetios 2:85734ad35573 1855 * @see MPU6050_RA_INT_STATUS
Gaetios 2:85734ad35573 1856 * @see MPU6050_INTERRUPT_DATA_RDY_BIT
Gaetios 2:85734ad35573 1857 */
Gaetios 2:85734ad35573 1858 bool MPU60503::getIntDataReadyStatus()
Gaetios 2:85734ad35573 1859 {
Gaetios 2:85734ad35573 1860 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer);
Gaetios 2:85734ad35573 1861 return buffer[0];
Gaetios 2:85734ad35573 1862 }
Gaetios 2:85734ad35573 1863
Gaetios 2:85734ad35573 1864 // ACCEL_*OUT_* registers
Gaetios 2:85734ad35573 1865
Gaetios 2:85734ad35573 1866 /** Get raw 9-axis motion sensor readings (accel/gyro/compass).
Gaetios 2:85734ad35573 1867 * FUNCTION NOT FULLY IMPLEMENTED YET.
Gaetios 2:85734ad35573 1868 * @param ax 16-bit signed integer container for accelerometer X-axis value
Gaetios 2:85734ad35573 1869 * @param ay 16-bit signed integer container for accelerometer Y-axis value
Gaetios 2:85734ad35573 1870 * @param az 16-bit signed integer container for accelerometer Z-axis value
Gaetios 2:85734ad35573 1871 * @param gx 16-bit signed integer container for gyroscope X-axis value
Gaetios 2:85734ad35573 1872 * @param gy 16-bit signed integer container for gyroscope Y-axis value
Gaetios 2:85734ad35573 1873 * @param gz 16-bit signed integer container for gyroscope Z-axis value
Gaetios 2:85734ad35573 1874 * @param mx 16-bit signed integer container for magnetometer X-axis value
Gaetios 2:85734ad35573 1875 * @param my 16-bit signed integer container for magnetometer Y-axis value
Gaetios 2:85734ad35573 1876 * @param mz 16-bit signed integer container for magnetometer Z-axis value
Gaetios 2:85734ad35573 1877 * @see getMotion6()
Gaetios 2:85734ad35573 1878 * @see getAcceleration()
Gaetios 2:85734ad35573 1879 * @see getRotation()
Gaetios 2:85734ad35573 1880 * @see MPU6050_RA_ACCEL_XOUT_H
Gaetios 2:85734ad35573 1881 */
Gaetios 2:85734ad35573 1882 void MPU60503::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)
Gaetios 2:85734ad35573 1883 {
Gaetios 2:85734ad35573 1884 getMotion6(ax, ay, az, gx, gy, gz);
Gaetios 2:85734ad35573 1885 // TODO: magnetometer integration
Gaetios 2:85734ad35573 1886 }
Gaetios 2:85734ad35573 1887 /** Get raw 6-axis motion sensor readings (accel/gyro).
Gaetios 2:85734ad35573 1888 * Retrieves all currently available motion sensor values.
Gaetios 2:85734ad35573 1889 * @param ax 16-bit signed integer container for accelerometer X-axis value
Gaetios 2:85734ad35573 1890 * @param ay 16-bit signed integer container for accelerometer Y-axis value
Gaetios 2:85734ad35573 1891 * @param az 16-bit signed integer container for accelerometer Z-axis value
Gaetios 2:85734ad35573 1892 * @param gx 16-bit signed integer container for gyroscope X-axis value
Gaetios 2:85734ad35573 1893 * @param gy 16-bit signed integer container for gyroscope Y-axis value
Gaetios 2:85734ad35573 1894 * @param gz 16-bit signed integer container for gyroscope Z-axis value
Gaetios 2:85734ad35573 1895 * @see getAcceleration()
Gaetios 2:85734ad35573 1896 * @see getRotation()
Gaetios 2:85734ad35573 1897 * @see MPU6050_RA_ACCEL_XOUT_H
Gaetios 2:85734ad35573 1898 */
Gaetios 2:85734ad35573 1899 void MPU60503::getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz)
Gaetios 2:85734ad35573 1900 {
Gaetios 2:85734ad35573 1901 i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 14, buffer);
Gaetios 2:85734ad35573 1902 *ax = (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 1903 *ay = (((int16_t)buffer[2]) << 8) | buffer[3];
Gaetios 2:85734ad35573 1904 *az = (((int16_t)buffer[4]) << 8) | buffer[5];
Gaetios 2:85734ad35573 1905 *gx = (((int16_t)buffer[8]) << 8) | buffer[9];
Gaetios 2:85734ad35573 1906 *gy = (((int16_t)buffer[10]) << 8) | buffer[11];
Gaetios 2:85734ad35573 1907 *gz = (((int16_t)buffer[12]) << 8) | buffer[13];
Gaetios 2:85734ad35573 1908 }
Gaetios 2:85734ad35573 1909 /** Get 3-axis accelerometer readings.
Gaetios 2:85734ad35573 1910 * These registers store the most recent accelerometer measurements.
Gaetios 2:85734ad35573 1911 * Accelerometer measurements are written to these registers at the Sample Rate
Gaetios 2:85734ad35573 1912 * as defined in Register 25.
Gaetios 2:85734ad35573 1913 *
Gaetios 2:85734ad35573 1914 * The accelerometer measurement registers, along with the temperature
Gaetios 2:85734ad35573 1915 * measurement registers, gyroscope measurement registers, and external sensor
Gaetios 2:85734ad35573 1916 * data registers, are composed of two sets of registers: an internal register
Gaetios 2:85734ad35573 1917 * set and a user-facing read register set.
Gaetios 2:85734ad35573 1918 *
Gaetios 2:85734ad35573 1919 * The data within the accelerometer sensors' internal register set is always
Gaetios 2:85734ad35573 1920 * updated at the Sample Rate. Meanwhile, the user-facing read register set
Gaetios 2:85734ad35573 1921 * duplicates the internal register set's data values whenever the serial
Gaetios 2:85734ad35573 1922 * interface is idle. This guarantees that a burst read of sensor registers will
Gaetios 2:85734ad35573 1923 * read measurements from the same sampling instant. Note that if burst reads
Gaetios 2:85734ad35573 1924 * are not used, the user is responsible for ensuring a set of single byte reads
Gaetios 2:85734ad35573 1925 * correspond to a single sampling instant by checking the Data Ready interrupt.
Gaetios 2:85734ad35573 1926 *
Gaetios 2:85734ad35573 1927 * Each 16-bit accelerometer measurement has a full scale defined in ACCEL_FS
Gaetios 2:85734ad35573 1928 * (Register 28). For each full scale setting, the accelerometers' sensitivity
Gaetios 2:85734ad35573 1929 * per LSB in ACCEL_xOUT is shown in the table below:
Gaetios 2:85734ad35573 1930 *
Gaetios 2:85734ad35573 1931 * <pre>
Gaetios 2:85734ad35573 1932 * AFS_SEL | Full Scale Range | LSB Sensitivity
Gaetios 2:85734ad35573 1933 * --------+------------------+----------------
Gaetios 2:85734ad35573 1934 * 0 | +/- 2g | 8192 LSB/mg
Gaetios 2:85734ad35573 1935 * 1 | +/- 4g | 4096 LSB/mg
Gaetios 2:85734ad35573 1936 * 2 | +/- 8g | 2048 LSB/mg
Gaetios 2:85734ad35573 1937 * 3 | +/- 16g | 1024 LSB/mg
Gaetios 2:85734ad35573 1938 * </pre>
Gaetios 2:85734ad35573 1939 *
Gaetios 2:85734ad35573 1940 * @param x 16-bit signed integer container for X-axis acceleration
Gaetios 2:85734ad35573 1941 * @param y 16-bit signed integer container for Y-axis acceleration
Gaetios 2:85734ad35573 1942 * @param z 16-bit signed integer container for Z-axis acceleration
Gaetios 2:85734ad35573 1943 * @see MPU6050_RA_GYRO_XOUT_H
Gaetios 2:85734ad35573 1944 */
Gaetios 2:85734ad35573 1945 void MPU60503::getAcceleration(int16_t* x, int16_t* y, int16_t* z)
Gaetios 2:85734ad35573 1946 {
Gaetios 2:85734ad35573 1947 i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 6, buffer);
Gaetios 2:85734ad35573 1948 *x = (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 1949 *y = (((int16_t)buffer[2]) << 8) | buffer[3];
Gaetios 2:85734ad35573 1950 *z = (((int16_t)buffer[4]) << 8) | buffer[5];
Gaetios 2:85734ad35573 1951 }
Gaetios 2:85734ad35573 1952 /** Get X-axis accelerometer reading.
Gaetios 2:85734ad35573 1953 * @return X-axis acceleration measurement in 16-bit 2's complement format
Gaetios 2:85734ad35573 1954 * @see getMotion6()
Gaetios 2:85734ad35573 1955 * @see MPU6050_RA_ACCEL_XOUT_H
Gaetios 2:85734ad35573 1956 */
Gaetios 2:85734ad35573 1957 int16_t MPU60503::getAccelerationX()
Gaetios 2:85734ad35573 1958 {
Gaetios 2:85734ad35573 1959 i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 2, buffer);
Gaetios 2:85734ad35573 1960 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 1961 }
Gaetios 2:85734ad35573 1962 /** Get Y-axis accelerometer reading.
Gaetios 2:85734ad35573 1963 * @return Y-axis acceleration measurement in 16-bit 2's complement format
Gaetios 2:85734ad35573 1964 * @see getMotion6()
Gaetios 2:85734ad35573 1965 * @see MPU6050_RA_ACCEL_YOUT_H
Gaetios 2:85734ad35573 1966 */
Gaetios 2:85734ad35573 1967 int16_t MPU60503::getAccelerationY()
Gaetios 2:85734ad35573 1968 {
Gaetios 2:85734ad35573 1969 i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_YOUT_H, 2, buffer);
Gaetios 2:85734ad35573 1970 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 1971 }
Gaetios 2:85734ad35573 1972 /** Get Z-axis accelerometer reading.
Gaetios 2:85734ad35573 1973 * @return Z-axis acceleration measurement in 16-bit 2's complement format
Gaetios 2:85734ad35573 1974 * @see getMotion6()
Gaetios 2:85734ad35573 1975 * @see MPU6050_RA_ACCEL_ZOUT_H
Gaetios 2:85734ad35573 1976 */
Gaetios 2:85734ad35573 1977 int16_t MPU60503::getAccelerationZ()
Gaetios 2:85734ad35573 1978 {
Gaetios 2:85734ad35573 1979 i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_ZOUT_H, 2, buffer);
Gaetios 2:85734ad35573 1980 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 1981 }
Gaetios 2:85734ad35573 1982
Gaetios 2:85734ad35573 1983 // TEMP_OUT_* registers
Gaetios 2:85734ad35573 1984
Gaetios 2:85734ad35573 1985 /** Get current internal temperature.
Gaetios 2:85734ad35573 1986 * @return Temperature reading in 16-bit 2's complement format
Gaetios 2:85734ad35573 1987 * @see MPU6050_RA_TEMP_OUT_H
Gaetios 2:85734ad35573 1988 */
Gaetios 2:85734ad35573 1989 int16_t MPU60503::getTemperature()
Gaetios 2:85734ad35573 1990 {
Gaetios 2:85734ad35573 1991 i2Cdev.readBytes(devAddr, MPU6050_RA_TEMP_OUT_H, 2, buffer);
Gaetios 2:85734ad35573 1992 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 1993 }
Gaetios 2:85734ad35573 1994
Gaetios 2:85734ad35573 1995 // GYRO_*OUT_* registers
Gaetios 2:85734ad35573 1996
Gaetios 2:85734ad35573 1997 /** Get 3-axis gyroscope readings.
Gaetios 2:85734ad35573 1998 * These gyroscope measurement registers, along with the accelerometer
Gaetios 2:85734ad35573 1999 * measurement registers, temperature measurement registers, and external sensor
Gaetios 2:85734ad35573 2000 * data registers, are composed of two sets of registers: an internal register
Gaetios 2:85734ad35573 2001 * set and a user-facing read register set.
Gaetios 2:85734ad35573 2002 * The data within the gyroscope sensors' internal register set is always
Gaetios 2:85734ad35573 2003 * updated at the Sample Rate. Meanwhile, the user-facing read register set
Gaetios 2:85734ad35573 2004 * duplicates the internal register set's data values whenever the serial
Gaetios 2:85734ad35573 2005 * interface is idle. This guarantees that a burst read of sensor registers will
Gaetios 2:85734ad35573 2006 * read measurements from the same sampling instant. Note that if burst reads
Gaetios 2:85734ad35573 2007 * are not used, the user is responsible for ensuring a set of single byte reads
Gaetios 2:85734ad35573 2008 * correspond to a single sampling instant by checking the Data Ready interrupt.
Gaetios 2:85734ad35573 2009 *
Gaetios 2:85734ad35573 2010 * Each 16-bit gyroscope measurement has a full scale defined in FS_SEL
Gaetios 2:85734ad35573 2011 * (Register 27). For each full scale setting, the gyroscopes' sensitivity per
Gaetios 2:85734ad35573 2012 * LSB in GYRO_xOUT is shown in the table below:
Gaetios 2:85734ad35573 2013 *
Gaetios 2:85734ad35573 2014 * <pre>
Gaetios 2:85734ad35573 2015 * FS_SEL | Full Scale Range | LSB Sensitivity
Gaetios 2:85734ad35573 2016 * -------+--------------------+----------------
Gaetios 2:85734ad35573 2017 * 0 | +/- 250 degrees/s | 131 LSB/deg/s
Gaetios 2:85734ad35573 2018 * 1 | +/- 500 degrees/s | 65.5 LSB/deg/s
Gaetios 2:85734ad35573 2019 * 2 | +/- 1000 degrees/s | 32.8 LSB/deg/s
Gaetios 2:85734ad35573 2020 * 3 | +/- 2000 degrees/s | 16.4 LSB/deg/s
Gaetios 2:85734ad35573 2021 * </pre>
Gaetios 2:85734ad35573 2022 *
Gaetios 2:85734ad35573 2023 * @param x 16-bit signed integer container for X-axis rotation
Gaetios 2:85734ad35573 2024 * @param y 16-bit signed integer container for Y-axis rotation
Gaetios 2:85734ad35573 2025 * @param z 16-bit signed integer container for Z-axis rotation
Gaetios 2:85734ad35573 2026 * @see getMotion6()
Gaetios 2:85734ad35573 2027 * @see MPU6050_RA_GYRO_XOUT_H
Gaetios 2:85734ad35573 2028 */
Gaetios 2:85734ad35573 2029 void MPU60503::getRotation(int16_t* x, int16_t* y, int16_t* z)
Gaetios 2:85734ad35573 2030 {
Gaetios 2:85734ad35573 2031 i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 6, buffer);
Gaetios 2:85734ad35573 2032 *x = (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 2033 *y = (((int16_t)buffer[2]) << 8) | buffer[3];
Gaetios 2:85734ad35573 2034 *z = (((int16_t)buffer[4]) << 8) | buffer[5];
Gaetios 2:85734ad35573 2035 }
Gaetios 2:85734ad35573 2036 /** Get X-axis gyroscope reading.
Gaetios 2:85734ad35573 2037 * @return X-axis rotation measurement in 16-bit 2's complement format
Gaetios 2:85734ad35573 2038 * @see getMotion6()
Gaetios 2:85734ad35573 2039 * @see MPU6050_RA_GYRO_XOUT_H
Gaetios 2:85734ad35573 2040 */
Gaetios 2:85734ad35573 2041 int16_t MPU60503::getRotationX()
Gaetios 2:85734ad35573 2042 {
Gaetios 2:85734ad35573 2043 i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 2, buffer);
Gaetios 2:85734ad35573 2044 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 2045 }
Gaetios 2:85734ad35573 2046 /** Get Y-axis gyroscope reading.
Gaetios 2:85734ad35573 2047 * @return Y-axis rotation measurement in 16-bit 2's complement format
Gaetios 2:85734ad35573 2048 * @see getMotion6()
Gaetios 2:85734ad35573 2049 * @see MPU6050_RA_GYRO_YOUT_H
Gaetios 2:85734ad35573 2050 */
Gaetios 2:85734ad35573 2051 int16_t MPU60503::getRotationY()
Gaetios 2:85734ad35573 2052 {
Gaetios 2:85734ad35573 2053 i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_YOUT_H, 2, buffer);
Gaetios 2:85734ad35573 2054 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 2055 }
Gaetios 2:85734ad35573 2056 /** Get Z-axis gyroscope reading.
Gaetios 2:85734ad35573 2057 * @return Z-axis rotation measurement in 16-bit 2's complement format
Gaetios 2:85734ad35573 2058 * @see getMotion6()
Gaetios 2:85734ad35573 2059 * @see MPU6050_RA_GYRO_ZOUT_H
Gaetios 2:85734ad35573 2060 */
Gaetios 2:85734ad35573 2061 int16_t MPU60503::getRotationZ()
Gaetios 2:85734ad35573 2062 {
Gaetios 2:85734ad35573 2063 i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_ZOUT_H, 2, buffer);
Gaetios 2:85734ad35573 2064 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 2065 }
Gaetios 2:85734ad35573 2066
Gaetios 2:85734ad35573 2067 // EXT_SENS_DATA_* registers
Gaetios 2:85734ad35573 2068
Gaetios 2:85734ad35573 2069 /** Read single byte from external sensor data register.
Gaetios 2:85734ad35573 2070 * These registers store data read from external sensors by the Slave 0, 1, 2,
Gaetios 2:85734ad35573 2071 * and 3 on the auxiliary I2C interface. Data read by Slave 4 is stored in
Gaetios 2:85734ad35573 2072 * I2C_SLV4_DI (Register 53).
Gaetios 2:85734ad35573 2073 *
Gaetios 2:85734ad35573 2074 * External sensor data is written to these registers at the Sample Rate as
Gaetios 2:85734ad35573 2075 * defined in Register 25. This access rate can be reduced by using the Slave
Gaetios 2:85734ad35573 2076 * Delay Enable registers (Register 103).
Gaetios 2:85734ad35573 2077 *
Gaetios 2:85734ad35573 2078 * External sensor data registers, along with the gyroscope measurement
Gaetios 2:85734ad35573 2079 * registers, accelerometer measurement registers, and temperature measurement
Gaetios 2:85734ad35573 2080 * registers, are composed of two sets of registers: an internal register set
Gaetios 2:85734ad35573 2081 * and a user-facing read register set.
Gaetios 2:85734ad35573 2082 *
Gaetios 2:85734ad35573 2083 * The data within the external sensors' internal register set is always updated
Gaetios 2:85734ad35573 2084 * at the Sample Rate (or the reduced access rate) whenever the serial interface
Gaetios 2:85734ad35573 2085 * is idle. This guarantees that a burst read of sensor registers will read
Gaetios 2:85734ad35573 2086 * measurements from the same sampling instant. Note that if burst reads are not
Gaetios 2:85734ad35573 2087 * used, the user is responsible for ensuring a set of single byte reads
Gaetios 2:85734ad35573 2088 * correspond to a single sampling instant by checking the Data Ready interrupt.
Gaetios 2:85734ad35573 2089 *
Gaetios 2:85734ad35573 2090 * Data is placed in these external sensor data registers according to
Gaetios 2:85734ad35573 2091 * I2C_SLV0_CTRL, I2C_SLV1_CTRL, I2C_SLV2_CTRL, and I2C_SLV3_CTRL (Registers 39,
Gaetios 2:85734ad35573 2092 * 42, 45, and 48). When more than zero bytes are read (I2C_SLVx_LEN > 0) from
Gaetios 2:85734ad35573 2093 * an enabled slave (I2C_SLVx_EN = 1), the slave is read at the Sample Rate (as
Gaetios 2:85734ad35573 2094 * defined in Register 25) or delayed rate (if specified in Register 52 and
Gaetios 2:85734ad35573 2095 * 103). During each Sample cycle, slave reads are performed in order of Slave
Gaetios 2:85734ad35573 2096 * number. If all slaves are enabled with more than zero bytes to be read, the
Gaetios 2:85734ad35573 2097 * order will be Slave 0, followed by Slave 1, Slave 2, and Slave 3.
Gaetios 2:85734ad35573 2098 *
Gaetios 2:85734ad35573 2099 * Each enabled slave will have EXT_SENS_DATA registers associated with it by
Gaetios 2:85734ad35573 2100 * number of bytes read (I2C_SLVx_LEN) in order of slave number, starting from
Gaetios 2:85734ad35573 2101 * EXT_SENS_DATA_00. Note that this means enabling or disabling a slave may
Gaetios 2:85734ad35573 2102 * change the higher numbered slaves' associated registers. Furthermore, if
Gaetios 2:85734ad35573 2103 * fewer total bytes are being read from the external sensors as a result of
Gaetios 2:85734ad35573 2104 * such a change, then the data remaining in the registers which no longer have
Gaetios 2:85734ad35573 2105 * an associated slave device (i.e. high numbered registers) will remain in
Gaetios 2:85734ad35573 2106 * these previously allocated registers unless reset.
Gaetios 2:85734ad35573 2107 *
Gaetios 2:85734ad35573 2108 * If the sum of the read lengths of all SLVx transactions exceed the number of
Gaetios 2:85734ad35573 2109 * available EXT_SENS_DATA registers, the excess bytes will be dropped. There
Gaetios 2:85734ad35573 2110 * are 24 EXT_SENS_DATA registers and hence the total read lengths between all
Gaetios 2:85734ad35573 2111 * the slaves cannot be greater than 24 or some bytes will be lost.
Gaetios 2:85734ad35573 2112 *
Gaetios 2:85734ad35573 2113 * Note: Slave 4's behavior is distinct from that of Slaves 0-3. For further
Gaetios 2:85734ad35573 2114 * information regarding the characteristics of Slave 4, please refer to
Gaetios 2:85734ad35573 2115 * Registers 49 to 53.
Gaetios 2:85734ad35573 2116 *
Gaetios 2:85734ad35573 2117 * EXAMPLE:
Gaetios 2:85734ad35573 2118 * Suppose that Slave 0 is enabled with 4 bytes to be read (I2C_SLV0_EN = 1 and
Gaetios 2:85734ad35573 2119 * I2C_SLV0_LEN = 4) while Slave 1 is enabled with 2 bytes to be read so that
Gaetios 2:85734ad35573 2120 * I2C_SLV1_EN = 1 and I2C_SLV1_LEN = 2. In such a situation, EXT_SENS_DATA _00
Gaetios 2:85734ad35573 2121 * through _03 will be associated with Slave 0, while EXT_SENS_DATA _04 and 05
Gaetios 2:85734ad35573 2122 * will be associated with Slave 1. If Slave 2 is enabled as well, registers
Gaetios 2:85734ad35573 2123 * starting from EXT_SENS_DATA_06 will be allocated to Slave 2.
Gaetios 2:85734ad35573 2124 *
Gaetios 2:85734ad35573 2125 * If Slave 2 is disabled while Slave 3 is enabled in this same situation, then
Gaetios 2:85734ad35573 2126 * registers starting from EXT_SENS_DATA_06 will be allocated to Slave 3
Gaetios 2:85734ad35573 2127 * instead.
Gaetios 2:85734ad35573 2128 *
Gaetios 2:85734ad35573 2129 * REGISTER ALLOCATION FOR DYNAMIC DISABLE VS. NORMAL DISABLE:
Gaetios 2:85734ad35573 2130 * If a slave is disabled at any time, the space initially allocated to the
Gaetios 2:85734ad35573 2131 * slave in the EXT_SENS_DATA register, will remain associated with that slave.
Gaetios 2:85734ad35573 2132 * This is to avoid dynamic adjustment of the register allocation.
Gaetios 2:85734ad35573 2133 *
Gaetios 2:85734ad35573 2134 * The allocation of the EXT_SENS_DATA registers is recomputed only when (1) all
Gaetios 2:85734ad35573 2135 * slaves are disabled, or (2) the I2C_MST_RST bit is set (Register 106).
Gaetios 2:85734ad35573 2136 *
Gaetios 2:85734ad35573 2137 * This above is also true if one of the slaves gets NACKed and stops
Gaetios 2:85734ad35573 2138 * functioning.
Gaetios 2:85734ad35573 2139 *
Gaetios 2:85734ad35573 2140 * @param position Starting position (0-23)
Gaetios 2:85734ad35573 2141 * @return Byte read from register
Gaetios 2:85734ad35573 2142 */
Gaetios 2:85734ad35573 2143 uint8_t MPU60503::getExternalSensorByte(int position)
Gaetios 2:85734ad35573 2144 {
Gaetios 2:85734ad35573 2145 i2Cdev.readByte(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, buffer);
Gaetios 2:85734ad35573 2146 return buffer[0];
Gaetios 2:85734ad35573 2147 }
Gaetios 2:85734ad35573 2148 /** Read word (2 bytes) from external sensor data registers.
Gaetios 2:85734ad35573 2149 * @param position Starting position (0-21)
Gaetios 2:85734ad35573 2150 * @return Word read from register
Gaetios 2:85734ad35573 2151 * @see getExternalSensorByte()
Gaetios 2:85734ad35573 2152 */
Gaetios 2:85734ad35573 2153 uint16_t MPU60503::getExternalSensorWord(int position)
Gaetios 2:85734ad35573 2154 {
Gaetios 2:85734ad35573 2155 i2Cdev.readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 2, buffer);
Gaetios 2:85734ad35573 2156 return (((uint16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 2157 }
Gaetios 2:85734ad35573 2158 /** Read double word (4 bytes) from external sensor data registers.
Gaetios 2:85734ad35573 2159 * @param position Starting position (0-20)
Gaetios 2:85734ad35573 2160 * @return Double word read from registers
Gaetios 2:85734ad35573 2161 * @see getExternalSensorByte()
Gaetios 2:85734ad35573 2162 */
Gaetios 2:85734ad35573 2163 uint32_t MPU60503::getExternalSensorDWord(int position)
Gaetios 2:85734ad35573 2164 {
Gaetios 2:85734ad35573 2165 i2Cdev.readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 4, buffer);
Gaetios 2:85734ad35573 2166 return (((uint32_t)buffer[0]) << 24) | (((uint32_t)buffer[1]) << 16) | (((uint16_t)buffer[2]) << 8) | buffer[3];
Gaetios 2:85734ad35573 2167 }
Gaetios 2:85734ad35573 2168
Gaetios 2:85734ad35573 2169 // MOT_DETECT_STATUS register
Gaetios 2:85734ad35573 2170
Gaetios 2:85734ad35573 2171 /** Get X-axis negative motion detection interrupt status.
Gaetios 2:85734ad35573 2172 * @return Motion detection status
Gaetios 2:85734ad35573 2173 * @see MPU6050_RA_MOT_DETECT_STATUS
Gaetios 2:85734ad35573 2174 * @see MPU6050_MOTION_MOT_XNEG_BIT
Gaetios 2:85734ad35573 2175 */
Gaetios 2:85734ad35573 2176 bool MPU60503::getXNegMotionDetected()
Gaetios 2:85734ad35573 2177 {
Gaetios 2:85734ad35573 2178 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XNEG_BIT, buffer);
Gaetios 2:85734ad35573 2179 return buffer[0];
Gaetios 2:85734ad35573 2180 }
Gaetios 2:85734ad35573 2181 /** Get X-axis positive motion detection interrupt status.
Gaetios 2:85734ad35573 2182 * @return Motion detection status
Gaetios 2:85734ad35573 2183 * @see MPU6050_RA_MOT_DETECT_STATUS
Gaetios 2:85734ad35573 2184 * @see MPU6050_MOTION_MOT_XPOS_BIT
Gaetios 2:85734ad35573 2185 */
Gaetios 2:85734ad35573 2186 bool MPU60503::getXPosMotionDetected()
Gaetios 2:85734ad35573 2187 {
Gaetios 2:85734ad35573 2188 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XPOS_BIT, buffer);
Gaetios 2:85734ad35573 2189 return buffer[0];
Gaetios 2:85734ad35573 2190 }
Gaetios 2:85734ad35573 2191 /** Get Y-axis negative motion detection interrupt status.
Gaetios 2:85734ad35573 2192 * @return Motion detection status
Gaetios 2:85734ad35573 2193 * @see MPU6050_RA_MOT_DETECT_STATUS
Gaetios 2:85734ad35573 2194 * @see MPU6050_MOTION_MOT_YNEG_BIT
Gaetios 2:85734ad35573 2195 */
Gaetios 2:85734ad35573 2196 bool MPU60503::getYNegMotionDetected()
Gaetios 2:85734ad35573 2197 {
Gaetios 2:85734ad35573 2198 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YNEG_BIT, buffer);
Gaetios 2:85734ad35573 2199 return buffer[0];
Gaetios 2:85734ad35573 2200 }
Gaetios 2:85734ad35573 2201 /** Get Y-axis positive motion detection interrupt status.
Gaetios 2:85734ad35573 2202 * @return Motion detection status
Gaetios 2:85734ad35573 2203 * @see MPU6050_RA_MOT_DETECT_STATUS
Gaetios 2:85734ad35573 2204 * @see MPU6050_MOTION_MOT_YPOS_BIT
Gaetios 2:85734ad35573 2205 */
Gaetios 2:85734ad35573 2206 bool MPU60503::getYPosMotionDetected()
Gaetios 2:85734ad35573 2207 {
Gaetios 2:85734ad35573 2208 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YPOS_BIT, buffer);
Gaetios 2:85734ad35573 2209 return buffer[0];
Gaetios 2:85734ad35573 2210 }
Gaetios 2:85734ad35573 2211 /** Get Z-axis negative motion detection interrupt status.
Gaetios 2:85734ad35573 2212 * @return Motion detection status
Gaetios 2:85734ad35573 2213 * @see MPU6050_RA_MOT_DETECT_STATUS
Gaetios 2:85734ad35573 2214 * @see MPU6050_MOTION_MOT_ZNEG_BIT
Gaetios 2:85734ad35573 2215 */
Gaetios 2:85734ad35573 2216 bool MPU60503::getZNegMotionDetected()
Gaetios 2:85734ad35573 2217 {
Gaetios 2:85734ad35573 2218 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZNEG_BIT, buffer);
Gaetios 2:85734ad35573 2219 return buffer[0];
Gaetios 2:85734ad35573 2220 }
Gaetios 2:85734ad35573 2221 /** Get Z-axis positive motion detection interrupt status.
Gaetios 2:85734ad35573 2222 * @return Motion detection status
Gaetios 2:85734ad35573 2223 * @see MPU6050_RA_MOT_DETECT_STATUS
Gaetios 2:85734ad35573 2224 * @see MPU6050_MOTION_MOT_ZPOS_BIT
Gaetios 2:85734ad35573 2225 */
Gaetios 2:85734ad35573 2226 bool MPU60503::getZPosMotionDetected()
Gaetios 2:85734ad35573 2227 {
Gaetios 2:85734ad35573 2228 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZPOS_BIT, buffer);
Gaetios 2:85734ad35573 2229 return buffer[0];
Gaetios 2:85734ad35573 2230 }
Gaetios 2:85734ad35573 2231 /** Get zero motion detection interrupt status.
Gaetios 2:85734ad35573 2232 * @return Motion detection status
Gaetios 2:85734ad35573 2233 * @see MPU6050_RA_MOT_DETECT_STATUS
Gaetios 2:85734ad35573 2234 * @see MPU6050_MOTION_MOT_ZRMOT_BIT
Gaetios 2:85734ad35573 2235 */
Gaetios 2:85734ad35573 2236 bool MPU60503::getZeroMotionDetected()
Gaetios 2:85734ad35573 2237 {
Gaetios 2:85734ad35573 2238 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZRMOT_BIT, buffer);
Gaetios 2:85734ad35573 2239 return buffer[0];
Gaetios 2:85734ad35573 2240 }
Gaetios 2:85734ad35573 2241
Gaetios 2:85734ad35573 2242 // I2C_SLV*_DO register
Gaetios 2:85734ad35573 2243
Gaetios 2:85734ad35573 2244 /** Write byte to Data Output container for specified slave.
Gaetios 2:85734ad35573 2245 * This register holds the output data written into Slave when Slave is set to
Gaetios 2:85734ad35573 2246 * write mode. For further information regarding Slave control, please
Gaetios 2:85734ad35573 2247 * refer to Registers 37 to 39 and immediately following.
Gaetios 2:85734ad35573 2248 * @param num Slave number (0-3)
Gaetios 2:85734ad35573 2249 * @param data Byte to write
Gaetios 2:85734ad35573 2250 * @see MPU6050_RA_I2C_SLV0_DO
Gaetios 2:85734ad35573 2251 */
Gaetios 2:85734ad35573 2252 void MPU60503::setSlaveOutputByte(uint8_t num, uint8_t data)
Gaetios 2:85734ad35573 2253 {
Gaetios 2:85734ad35573 2254 if (num > 3) return;
Gaetios 2:85734ad35573 2255 i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV0_DO + num, data);
Gaetios 2:85734ad35573 2256 }
Gaetios 2:85734ad35573 2257
Gaetios 2:85734ad35573 2258 // I2C_MST_DELAY_CTRL register
Gaetios 2:85734ad35573 2259
Gaetios 2:85734ad35573 2260 /** Get external data shadow delay enabled status.
Gaetios 2:85734ad35573 2261 * This register is used to specify the timing of external sensor data
Gaetios 2:85734ad35573 2262 * shadowing. When DELAY_ES_SHADOW is set to 1, shadowing of external
Gaetios 2:85734ad35573 2263 * sensor data is delayed until all data has been received.
Gaetios 2:85734ad35573 2264 * @return Current external data shadow delay enabled status.
Gaetios 2:85734ad35573 2265 * @see MPU6050_RA_I2C_MST_DELAY_CTRL
Gaetios 2:85734ad35573 2266 * @see MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT
Gaetios 2:85734ad35573 2267 */
Gaetios 2:85734ad35573 2268 bool MPU60503::getExternalShadowDelayEnabled()
Gaetios 2:85734ad35573 2269 {
Gaetios 2:85734ad35573 2270 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT, buffer);
Gaetios 2:85734ad35573 2271 return buffer[0];
Gaetios 2:85734ad35573 2272 }
Gaetios 2:85734ad35573 2273 /** Set external data shadow delay enabled status.
Gaetios 2:85734ad35573 2274 * @param enabled New external data shadow delay enabled status.
Gaetios 2:85734ad35573 2275 * @see getExternalShadowDelayEnabled()
Gaetios 2:85734ad35573 2276 * @see MPU6050_RA_I2C_MST_DELAY_CTRL
Gaetios 2:85734ad35573 2277 * @see MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT
Gaetios 2:85734ad35573 2278 */
Gaetios 2:85734ad35573 2279 void MPU60503::setExternalShadowDelayEnabled(bool enabled)
Gaetios 2:85734ad35573 2280 {
Gaetios 2:85734ad35573 2281 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT, enabled);
Gaetios 2:85734ad35573 2282 }
Gaetios 2:85734ad35573 2283 /** Get slave delay enabled status.
Gaetios 2:85734ad35573 2284 * When a particular slave delay is enabled, the rate of access for the that
Gaetios 2:85734ad35573 2285 * slave device is reduced. When a slave's access rate is decreased relative to
Gaetios 2:85734ad35573 2286 * the Sample Rate, the slave is accessed every:
Gaetios 2:85734ad35573 2287 *
Gaetios 2:85734ad35573 2288 * 1 / (1 + I2C_MST_DLY) Samples
Gaetios 2:85734ad35573 2289 *
Gaetios 2:85734ad35573 2290 * This base Sample Rate in turn is determined by SMPLRT_DIV (register * 25)
Gaetios 2:85734ad35573 2291 * and DLPF_CFG (register 26).
Gaetios 2:85734ad35573 2292 *
Gaetios 2:85734ad35573 2293 * For further information regarding I2C_MST_DLY, please refer to register 52.
Gaetios 2:85734ad35573 2294 * For further information regarding the Sample Rate, please refer to register 25.
Gaetios 2:85734ad35573 2295 *
Gaetios 2:85734ad35573 2296 * @param num Slave number (0-4)
Gaetios 2:85734ad35573 2297 * @return Current slave delay enabled status.
Gaetios 2:85734ad35573 2298 * @see MPU6050_RA_I2C_MST_DELAY_CTRL
Gaetios 2:85734ad35573 2299 * @see MPU6050_DELAYCTRL_I2C_SLV0_DLY_EN_BIT
Gaetios 2:85734ad35573 2300 */
Gaetios 2:85734ad35573 2301 bool MPU60503::getSlaveDelayEnabled(uint8_t num)
Gaetios 2:85734ad35573 2302 {
Gaetios 2:85734ad35573 2303 // MPU6050_DELAYCTRL_I2C_SLV4_DLY_EN_BIT is 4, SLV3 is 3, etc.
Gaetios 2:85734ad35573 2304 if (num > 4) return 0;
Gaetios 2:85734ad35573 2305 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, num, buffer);
Gaetios 2:85734ad35573 2306 return buffer[0];
Gaetios 2:85734ad35573 2307 }
Gaetios 2:85734ad35573 2308 /** Set slave delay enabled status.
Gaetios 2:85734ad35573 2309 * @param num Slave number (0-4)
Gaetios 2:85734ad35573 2310 * @param enabled New slave delay enabled status.
Gaetios 2:85734ad35573 2311 * @see MPU6050_RA_I2C_MST_DELAY_CTRL
Gaetios 2:85734ad35573 2312 * @see MPU6050_DELAYCTRL_I2C_SLV0_DLY_EN_BIT
Gaetios 2:85734ad35573 2313 */
Gaetios 2:85734ad35573 2314 void MPU60503::setSlaveDelayEnabled(uint8_t num, bool enabled)
Gaetios 2:85734ad35573 2315 {
Gaetios 2:85734ad35573 2316 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, num, enabled);
Gaetios 2:85734ad35573 2317 }
Gaetios 2:85734ad35573 2318
Gaetios 2:85734ad35573 2319 // SIGNAL_PATH_RESET register
Gaetios 2:85734ad35573 2320
Gaetios 2:85734ad35573 2321 /** Reset gyroscope signal path.
Gaetios 2:85734ad35573 2322 * The reset will revert the signal path analog to digital converters and
Gaetios 2:85734ad35573 2323 * filters to their power up configurations.
Gaetios 2:85734ad35573 2324 * @see MPU6050_RA_SIGNAL_PATH_RESET
Gaetios 2:85734ad35573 2325 * @see MPU6050_PATHRESET_GYRO_RESET_BIT
Gaetios 2:85734ad35573 2326 */
Gaetios 2:85734ad35573 2327 void MPU60503::resetGyroscopePath()
Gaetios 2:85734ad35573 2328 {
Gaetios 2:85734ad35573 2329 i2Cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_GYRO_RESET_BIT, true);
Gaetios 2:85734ad35573 2330 }
Gaetios 2:85734ad35573 2331 /** Reset accelerometer signal path.
Gaetios 2:85734ad35573 2332 * The reset will revert the signal path analog to digital converters and
Gaetios 2:85734ad35573 2333 * filters to their power up configurations.
Gaetios 2:85734ad35573 2334 * @see MPU6050_RA_SIGNAL_PATH_RESET
Gaetios 2:85734ad35573 2335 * @see MPU6050_PATHRESET_ACCEL_RESET_BIT
Gaetios 2:85734ad35573 2336 */
Gaetios 2:85734ad35573 2337 void MPU60503::resetAccelerometerPath()
Gaetios 2:85734ad35573 2338 {
Gaetios 2:85734ad35573 2339 i2Cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_ACCEL_RESET_BIT, true);
Gaetios 2:85734ad35573 2340 }
Gaetios 2:85734ad35573 2341 /** Reset temperature sensor signal path.
Gaetios 2:85734ad35573 2342 * The reset will revert the signal path analog to digital converters and
Gaetios 2:85734ad35573 2343 * filters to their power up configurations.
Gaetios 2:85734ad35573 2344 * @see MPU6050_RA_SIGNAL_PATH_RESET
Gaetios 2:85734ad35573 2345 * @see MPU6050_PATHRESET_TEMP_RESET_BIT
Gaetios 2:85734ad35573 2346 */
Gaetios 2:85734ad35573 2347 void MPU60503::resetTemperaturePath()
Gaetios 2:85734ad35573 2348 {
Gaetios 2:85734ad35573 2349 i2Cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_TEMP_RESET_BIT, true);
Gaetios 2:85734ad35573 2350 }
Gaetios 2:85734ad35573 2351
Gaetios 2:85734ad35573 2352 // MOT_DETECT_CTRL register
Gaetios 2:85734ad35573 2353
Gaetios 2:85734ad35573 2354 /** Get accelerometer power-on delay.
Gaetios 2:85734ad35573 2355 * The accelerometer data path provides samples to the sensor registers, Motion
Gaetios 2:85734ad35573 2356 * detection, Zero Motion detection, and Free Fall detection modules. The
Gaetios 2:85734ad35573 2357 * signal path contains filters which must be flushed on wake-up with new
Gaetios 2:85734ad35573 2358 * samples before the detection modules begin operations. The default wake-up
Gaetios 2:85734ad35573 2359 * delay, of 4ms can be lengthened by up to 3ms. This additional delay is
Gaetios 2:85734ad35573 2360 * specified in ACCEL_ON_DELAY in units of 1 LSB = 1 ms. The user may select
Gaetios 2:85734ad35573 2361 * any value above zero unless instructed otherwise by InvenSense. Please refer
Gaetios 2:85734ad35573 2362 * to Section 8 of the MPU-6000/MPU-6050 Product Specification document for
Gaetios 2:85734ad35573 2363 * further information regarding the detection modules.
Gaetios 2:85734ad35573 2364 * @return Current accelerometer power-on delay
Gaetios 2:85734ad35573 2365 * @see MPU6050_RA_MOT_DETECT_CTRL
Gaetios 2:85734ad35573 2366 * @see MPU6050_DETECT_ACCEL_ON_DELAY_BIT
Gaetios 2:85734ad35573 2367 */
Gaetios 2:85734ad35573 2368 uint8_t MPU60503::getAccelerometerPowerOnDelay()
Gaetios 2:85734ad35573 2369 {
Gaetios 2:85734ad35573 2370 i2Cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_ACCEL_ON_DELAY_BIT, MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH, buffer);
Gaetios 2:85734ad35573 2371 return buffer[0];
Gaetios 2:85734ad35573 2372 }
Gaetios 2:85734ad35573 2373 /** Set accelerometer power-on delay.
Gaetios 2:85734ad35573 2374 * @param delay New accelerometer power-on delay (0-3)
Gaetios 2:85734ad35573 2375 * @see getAccelerometerPowerOnDelay()
Gaetios 2:85734ad35573 2376 * @see MPU6050_RA_MOT_DETECT_CTRL
Gaetios 2:85734ad35573 2377 * @see MPU6050_DETECT_ACCEL_ON_DELAY_BIT
Gaetios 2:85734ad35573 2378 */
Gaetios 2:85734ad35573 2379 void MPU60503::setAccelerometerPowerOnDelay(uint8_t delay)
Gaetios 2:85734ad35573 2380 {
Gaetios 2:85734ad35573 2381 i2Cdev.writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_ACCEL_ON_DELAY_BIT, MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH, delay);
Gaetios 2:85734ad35573 2382 }
Gaetios 2:85734ad35573 2383 /** Get Free Fall detection counter decrement configuration.
Gaetios 2:85734ad35573 2384 * Detection is registered by the Free Fall detection module after accelerometer
Gaetios 2:85734ad35573 2385 * measurements meet their respective threshold conditions over a specified
Gaetios 2:85734ad35573 2386 * number of samples. When the threshold conditions are met, the corresponding
Gaetios 2:85734ad35573 2387 * detection counter increments by 1. The user may control the rate at which the
Gaetios 2:85734ad35573 2388 * detection counter decrements when the threshold condition is not met by
Gaetios 2:85734ad35573 2389 * configuring FF_COUNT. The decrement rate can be set according to the
Gaetios 2:85734ad35573 2390 * following table:
Gaetios 2:85734ad35573 2391 *
Gaetios 2:85734ad35573 2392 * <pre>
Gaetios 2:85734ad35573 2393 * FF_COUNT | Counter Decrement
Gaetios 2:85734ad35573 2394 * ---------+------------------
Gaetios 2:85734ad35573 2395 * 0 | Reset
Gaetios 2:85734ad35573 2396 * 1 | 1
Gaetios 2:85734ad35573 2397 * 2 | 2
Gaetios 2:85734ad35573 2398 * 3 | 4
Gaetios 2:85734ad35573 2399 * </pre>
Gaetios 2:85734ad35573 2400 *
Gaetios 2:85734ad35573 2401 * When FF_COUNT is configured to 0 (reset), any non-qualifying sample will
Gaetios 2:85734ad35573 2402 * reset the counter to 0. For further information on Free Fall detection,
Gaetios 2:85734ad35573 2403 * please refer to Registers 29 to 32.
Gaetios 2:85734ad35573 2404 *
Gaetios 2:85734ad35573 2405 * @return Current decrement configuration
Gaetios 2:85734ad35573 2406 * @see MPU6050_RA_MOT_DETECT_CTRL
Gaetios 2:85734ad35573 2407 * @see MPU6050_DETECT_FF_COUNT_BIT
Gaetios 2:85734ad35573 2408 */
Gaetios 2:85734ad35573 2409 uint8_t MPU60503::getFreefallDetectionCounterDecrement()
Gaetios 2:85734ad35573 2410 {
Gaetios 2:85734ad35573 2411 i2Cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_FF_COUNT_BIT, MPU6050_DETECT_FF_COUNT_LENGTH, buffer);
Gaetios 2:85734ad35573 2412 return buffer[0];
Gaetios 2:85734ad35573 2413 }
Gaetios 2:85734ad35573 2414 /** Set Free Fall detection counter decrement configuration.
Gaetios 2:85734ad35573 2415 * @param decrement New decrement configuration value
Gaetios 2:85734ad35573 2416 * @see getFreefallDetectionCounterDecrement()
Gaetios 2:85734ad35573 2417 * @see MPU6050_RA_MOT_DETECT_CTRL
Gaetios 2:85734ad35573 2418 * @see MPU6050_DETECT_FF_COUNT_BIT
Gaetios 2:85734ad35573 2419 */
Gaetios 2:85734ad35573 2420 void MPU60503::setFreefallDetectionCounterDecrement(uint8_t decrement)
Gaetios 2:85734ad35573 2421 {
Gaetios 2:85734ad35573 2422 i2Cdev.writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_FF_COUNT_BIT, MPU6050_DETECT_FF_COUNT_LENGTH, decrement);
Gaetios 2:85734ad35573 2423 }
Gaetios 2:85734ad35573 2424 /** Get Motion detection counter decrement configuration.
Gaetios 2:85734ad35573 2425 * Detection is registered by the Motion detection module after accelerometer
Gaetios 2:85734ad35573 2426 * measurements meet their respective threshold conditions over a specified
Gaetios 2:85734ad35573 2427 * number of samples. When the threshold conditions are met, the corresponding
Gaetios 2:85734ad35573 2428 * detection counter increments by 1. The user may control the rate at which the
Gaetios 2:85734ad35573 2429 * detection counter decrements when the threshold condition is not met by
Gaetios 2:85734ad35573 2430 * configuring MOT_COUNT. The decrement rate can be set according to the
Gaetios 2:85734ad35573 2431 * following table:
Gaetios 2:85734ad35573 2432 *
Gaetios 2:85734ad35573 2433 * <pre>
Gaetios 2:85734ad35573 2434 * MOT_COUNT | Counter Decrement
Gaetios 2:85734ad35573 2435 * ----------+------------------
Gaetios 2:85734ad35573 2436 * 0 | Reset
Gaetios 2:85734ad35573 2437 * 1 | 1
Gaetios 2:85734ad35573 2438 * 2 | 2
Gaetios 2:85734ad35573 2439 * 3 | 4
Gaetios 2:85734ad35573 2440 * </pre>
Gaetios 2:85734ad35573 2441 *
Gaetios 2:85734ad35573 2442 * When MOT_COUNT is configured to 0 (reset), any non-qualifying sample will
Gaetios 2:85734ad35573 2443 * reset the counter to 0. For further information on Motion detection,
Gaetios 2:85734ad35573 2444 * please refer to Registers 29 to 32.
Gaetios 2:85734ad35573 2445 *
Gaetios 2:85734ad35573 2446 */
Gaetios 2:85734ad35573 2447 uint8_t MPU60503::getMotionDetectionCounterDecrement()
Gaetios 2:85734ad35573 2448 {
Gaetios 2:85734ad35573 2449 i2Cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, buffer);
Gaetios 2:85734ad35573 2450 return buffer[0];
Gaetios 2:85734ad35573 2451 }
Gaetios 2:85734ad35573 2452 /** Set Motion detection counter decrement configuration.
Gaetios 2:85734ad35573 2453 * @param decrement New decrement configuration value
Gaetios 2:85734ad35573 2454 * @see getMotionDetectionCounterDecrement()
Gaetios 2:85734ad35573 2455 * @see MPU6050_RA_MOT_DETECT_CTRL
Gaetios 2:85734ad35573 2456 * @see MPU6050_DETECT_MOT_COUNT_BIT
Gaetios 2:85734ad35573 2457 */
Gaetios 2:85734ad35573 2458 void MPU60503::setMotionDetectionCounterDecrement(uint8_t decrement)
Gaetios 2:85734ad35573 2459 {
Gaetios 2:85734ad35573 2460 i2Cdev.writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, decrement);
Gaetios 2:85734ad35573 2461 }
Gaetios 2:85734ad35573 2462
Gaetios 2:85734ad35573 2463 // USER_CTRL register
Gaetios 2:85734ad35573 2464
Gaetios 2:85734ad35573 2465 /** Get FIFO enabled status.
Gaetios 2:85734ad35573 2466 * When this bit is set to 0, the FIFO buffer is disabled. The FIFO buffer
Gaetios 2:85734ad35573 2467 * cannot be written to or read from while disabled. The FIFO buffer's state
Gaetios 2:85734ad35573 2468 * does not change unless the MPU-60X0 is power cycled.
Gaetios 2:85734ad35573 2469 * @return Current FIFO enabled status
Gaetios 2:85734ad35573 2470 * @see MPU6050_RA_USER_CTRL
Gaetios 2:85734ad35573 2471 * @see MPU6050_USERCTRL_FIFO_EN_BIT
Gaetios 2:85734ad35573 2472 */
Gaetios 2:85734ad35573 2473 bool MPU60503::getFIFOEnabled()
Gaetios 2:85734ad35573 2474 {
Gaetios 2:85734ad35573 2475 i2Cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, buffer);
Gaetios 2:85734ad35573 2476 return buffer[0];
Gaetios 2:85734ad35573 2477 }
Gaetios 2:85734ad35573 2478 /** Set FIFO enabled status.
Gaetios 2:85734ad35573 2479 * @param enabled New FIFO enabled status
Gaetios 2:85734ad35573 2480 * @see getFIFOEnabled()
Gaetios 2:85734ad35573 2481 * @see MPU6050_RA_USER_CTRL
Gaetios 2:85734ad35573 2482 * @see MPU6050_USERCTRL_FIFO_EN_BIT
Gaetios 2:85734ad35573 2483 */
Gaetios 2:85734ad35573 2484 void MPU60503::setFIFOEnabled(bool enabled)
Gaetios 2:85734ad35573 2485 {
Gaetios 2:85734ad35573 2486 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, enabled);
Gaetios 2:85734ad35573 2487 }
Gaetios 2:85734ad35573 2488 /** Get I2C Master Mode enabled status.
Gaetios 2:85734ad35573 2489 * When this mode is enabled, the MPU-60X0 acts as the I2C Master to the
Gaetios 2:85734ad35573 2490 * external sensor slave devices on the auxiliary I2C bus. When this bit is
Gaetios 2:85734ad35573 2491 * cleared to 0, the auxiliary I2C bus lines (AUX_DA and AUX_CL) are logically
Gaetios 2:85734ad35573 2492 * driven by the primary I2C bus (SDA and SCL). This is a precondition to
Gaetios 2:85734ad35573 2493 * enabling Bypass Mode. For further information regarding Bypass Mode, please
Gaetios 2:85734ad35573 2494 * refer to Register 55.
Gaetios 2:85734ad35573 2495 * @return Current I2C Master Mode enabled status
Gaetios 2:85734ad35573 2496 * @see MPU6050_RA_USER_CTRL
Gaetios 2:85734ad35573 2497 * @see MPU6050_USERCTRL_I2C_MST_EN_BIT
Gaetios 2:85734ad35573 2498 */
Gaetios 2:85734ad35573 2499 bool MPU60503::getI2CMasterModeEnabled()
Gaetios 2:85734ad35573 2500 {
Gaetios 2:85734ad35573 2501 i2Cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, buffer);
Gaetios 2:85734ad35573 2502 return buffer[0];
Gaetios 2:85734ad35573 2503 }
Gaetios 2:85734ad35573 2504 /** Set I2C Master Mode enabled status.
Gaetios 2:85734ad35573 2505 * @param enabled New I2C Master Mode enabled status
Gaetios 2:85734ad35573 2506 * @see getI2CMasterModeEnabled()
Gaetios 2:85734ad35573 2507 * @see MPU6050_RA_USER_CTRL
Gaetios 2:85734ad35573 2508 * @see MPU6050_USERCTRL_I2C_MST_EN_BIT
Gaetios 2:85734ad35573 2509 */
Gaetios 2:85734ad35573 2510 void MPU60503::setI2CMasterModeEnabled(bool enabled)
Gaetios 2:85734ad35573 2511 {
Gaetios 2:85734ad35573 2512 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, enabled);
Gaetios 2:85734ad35573 2513 }
Gaetios 2:85734ad35573 2514 /** Switch from I2C to SPI mode (MPU-6000 only)
Gaetios 2:85734ad35573 2515 * If this is set, the primary SPI interface will be enabled in place of the
Gaetios 2:85734ad35573 2516 * disabled primary I2C interface.
Gaetios 2:85734ad35573 2517 */
Gaetios 2:85734ad35573 2518 void MPU60503::switchSPIEnabled(bool enabled)
Gaetios 2:85734ad35573 2519 {
Gaetios 2:85734ad35573 2520 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_IF_DIS_BIT, enabled);
Gaetios 2:85734ad35573 2521 }
Gaetios 2:85734ad35573 2522 /** Reset the FIFO.
Gaetios 2:85734ad35573 2523 * This bit resets the FIFO buffer when set to 1 while FIFO_EN equals 0. This
Gaetios 2:85734ad35573 2524 * bit automatically clears to 0 after the reset has been triggered.
Gaetios 2:85734ad35573 2525 * @see MPU6050_RA_USER_CTRL
Gaetios 2:85734ad35573 2526 * @see MPU6050_USERCTRL_FIFO_RESET_BIT
Gaetios 2:85734ad35573 2527 */
Gaetios 2:85734ad35573 2528 void MPU60503::resetFIFO()
Gaetios 2:85734ad35573 2529 {
Gaetios 2:85734ad35573 2530 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_RESET_BIT, true);
Gaetios 2:85734ad35573 2531 }
Gaetios 2:85734ad35573 2532 /** Reset the I2C Master.
Gaetios 2:85734ad35573 2533 * This bit resets the I2C Master when set to 1 while I2C_MST_EN equals 0.
Gaetios 2:85734ad35573 2534 * This bit automatically clears to 0 after the reset has been triggered.
Gaetios 2:85734ad35573 2535 * @see MPU6050_RA_USER_CTRL
Gaetios 2:85734ad35573 2536 * @see MPU6050_USERCTRL_I2C_MST_RESET_BIT
Gaetios 2:85734ad35573 2537 */
Gaetios 2:85734ad35573 2538 void MPU60503::resetI2CMaster()
Gaetios 2:85734ad35573 2539 {
Gaetios 2:85734ad35573 2540 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_RESET_BIT, true);
Gaetios 2:85734ad35573 2541 }
Gaetios 2:85734ad35573 2542 /** Reset all sensor registers and signal paths.
Gaetios 2:85734ad35573 2543 * When set to 1, this bit resets the signal paths for all sensors (gyroscopes,
Gaetios 2:85734ad35573 2544 * accelerometers, and temperature sensor). This operation will also clear the
Gaetios 2:85734ad35573 2545 * sensor registers. This bit automatically clears to 0 after the reset has been
Gaetios 2:85734ad35573 2546 * triggered.
Gaetios 2:85734ad35573 2547 *
Gaetios 2:85734ad35573 2548 * When resetting only the signal path (and not the sensor registers), please
Gaetios 2:85734ad35573 2549 * use Register 104, SIGNAL_PATH_RESET.
Gaetios 2:85734ad35573 2550 *
Gaetios 2:85734ad35573 2551 * @see MPU6050_RA_USER_CTRL
Gaetios 2:85734ad35573 2552 * @see MPU6050_USERCTRL_SIG_COND_RESET_BIT
Gaetios 2:85734ad35573 2553 */
Gaetios 2:85734ad35573 2554 void MPU60503::resetSensors()
Gaetios 2:85734ad35573 2555 {
Gaetios 2:85734ad35573 2556 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_SIG_COND_RESET_BIT, true);
Gaetios 2:85734ad35573 2557 }
Gaetios 2:85734ad35573 2558
Gaetios 2:85734ad35573 2559 // PWR_MGMT_1 register
Gaetios 2:85734ad35573 2560
Gaetios 2:85734ad35573 2561 /** Trigger a full device reset.
Gaetios 2:85734ad35573 2562 * A small delay of ~50ms may be desirable after triggering a reset.
Gaetios 2:85734ad35573 2563 * @see MPU6050_RA_PWR_MGMT_1
Gaetios 2:85734ad35573 2564 * @see MPU6050_PWR1_DEVICE_RESET_BIT
Gaetios 2:85734ad35573 2565 */
Gaetios 2:85734ad35573 2566 void MPU60503::reset()
Gaetios 2:85734ad35573 2567 {
Gaetios 2:85734ad35573 2568 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_DEVICE_RESET_BIT, true);
Gaetios 2:85734ad35573 2569 }
Gaetios 2:85734ad35573 2570 /** Get sleep mode status.
Gaetios 2:85734ad35573 2571 * Setting the SLEEP bit in the register puts the device into very low power
Gaetios 2:85734ad35573 2572 * sleep mode. In this mode, only the serial interface and internal registers
Gaetios 2:85734ad35573 2573 * remain active, allowing for a very low standby current. Clearing this bit
Gaetios 2:85734ad35573 2574 * puts the device back into normal mode. To save power, the individual standby
Gaetios 2:85734ad35573 2575 * selections for each of the gyros should be used if any gyro axis is not used
Gaetios 2:85734ad35573 2576 * by the application.
Gaetios 2:85734ad35573 2577 * @return Current sleep mode enabled status
Gaetios 2:85734ad35573 2578 * @see MPU6050_RA_PWR_MGMT_1
Gaetios 2:85734ad35573 2579 * @see MPU6050_PWR1_SLEEP_BIT
Gaetios 2:85734ad35573 2580 */
Gaetios 2:85734ad35573 2581 bool MPU60503::getSleepEnabled()
Gaetios 2:85734ad35573 2582 {
Gaetios 2:85734ad35573 2583 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, buffer);
Gaetios 2:85734ad35573 2584 return buffer[0];
Gaetios 2:85734ad35573 2585 }
Gaetios 2:85734ad35573 2586 /** Set sleep mode status.
Gaetios 2:85734ad35573 2587 * @param enabled New sleep mode enabled status
Gaetios 2:85734ad35573 2588 * @see getSleepEnabled()
Gaetios 2:85734ad35573 2589 * @see MPU6050_RA_PWR_MGMT_1
Gaetios 2:85734ad35573 2590 * @see MPU6050_PWR1_SLEEP_BIT
Gaetios 2:85734ad35573 2591 */
Gaetios 2:85734ad35573 2592 void MPU60503::setSleepEnabled(bool enabled)
Gaetios 2:85734ad35573 2593 {
Gaetios 2:85734ad35573 2594 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, enabled);
Gaetios 2:85734ad35573 2595 }
Gaetios 2:85734ad35573 2596 /** Get wake cycle enabled status.
Gaetios 2:85734ad35573 2597 * When this bit is set to 1 and SLEEP is disabled, the MPU-60X0 will cycle
Gaetios 2:85734ad35573 2598 * between sleep mode and waking up to take a single sample of data from active
Gaetios 2:85734ad35573 2599 * sensors at a rate determined by LP_WAKE_CTRL (register 108).
Gaetios 2:85734ad35573 2600 * @return Current sleep mode enabled status
Gaetios 2:85734ad35573 2601 * @see MPU6050_RA_PWR_MGMT_1
Gaetios 2:85734ad35573 2602 * @see MPU6050_PWR1_CYCLE_BIT
Gaetios 2:85734ad35573 2603 */
Gaetios 2:85734ad35573 2604 bool MPU60503::getWakeCycleEnabled()
Gaetios 2:85734ad35573 2605 {
Gaetios 2:85734ad35573 2606 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, buffer);
Gaetios 2:85734ad35573 2607 return buffer[0];
Gaetios 2:85734ad35573 2608 }
Gaetios 2:85734ad35573 2609 /** Set wake cycle enabled status.
Gaetios 2:85734ad35573 2610 * @param enabled New sleep mode enabled status
Gaetios 2:85734ad35573 2611 * @see getWakeCycleEnabled()
Gaetios 2:85734ad35573 2612 * @see MPU6050_RA_PWR_MGMT_1
Gaetios 2:85734ad35573 2613 * @see MPU6050_PWR1_CYCLE_BIT
Gaetios 2:85734ad35573 2614 */
Gaetios 2:85734ad35573 2615 void MPU60503::setWakeCycleEnabled(bool enabled)
Gaetios 2:85734ad35573 2616 {
Gaetios 2:85734ad35573 2617 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, enabled);
Gaetios 2:85734ad35573 2618 }
Gaetios 2:85734ad35573 2619 /** Get temperature sensor enabled status.
Gaetios 2:85734ad35573 2620 * Control the usage of the internal temperature sensor.
Gaetios 2:85734ad35573 2621 *
Gaetios 2:85734ad35573 2622 * Note: this register stores the *disabled* value, but for consistency with the
Gaetios 2:85734ad35573 2623 * rest of the code, the function is named and used with standard true/false
Gaetios 2:85734ad35573 2624 * values to indicate whether the sensor is enabled or disabled, respectively.
Gaetios 2:85734ad35573 2625 *
Gaetios 2:85734ad35573 2626 * @return Current temperature sensor enabled status
Gaetios 2:85734ad35573 2627 * @see MPU6050_RA_PWR_MGMT_1
Gaetios 2:85734ad35573 2628 * @see MPU6050_PWR1_TEMP_DIS_BIT
Gaetios 2:85734ad35573 2629 */
Gaetios 2:85734ad35573 2630 bool MPU60503::getTempSensorEnabled()
Gaetios 2:85734ad35573 2631 {
Gaetios 2:85734ad35573 2632 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, buffer);
Gaetios 2:85734ad35573 2633 return buffer[0] == 0; // 1 is actually disabled here
Gaetios 2:85734ad35573 2634 }
Gaetios 2:85734ad35573 2635 /** Set temperature sensor enabled status.
Gaetios 2:85734ad35573 2636 * Note: this register stores the *disabled* value, but for consistency with the
Gaetios 2:85734ad35573 2637 * rest of the code, the function is named and used with standard true/false
Gaetios 2:85734ad35573 2638 * values to indicate whether the sensor is enabled or disabled, respectively.
Gaetios 2:85734ad35573 2639 *
Gaetios 2:85734ad35573 2640 * @param enabled New temperature sensor enabled status
Gaetios 2:85734ad35573 2641 * @see getTempSensorEnabled()
Gaetios 2:85734ad35573 2642 * @see MPU6050_RA_PWR_MGMT_1
Gaetios 2:85734ad35573 2643 * @see MPU6050_PWR1_TEMP_DIS_BIT
Gaetios 2:85734ad35573 2644 */
Gaetios 2:85734ad35573 2645 void MPU60503::setTempSensorEnabled(bool enabled)
Gaetios 2:85734ad35573 2646 {
Gaetios 2:85734ad35573 2647 // 1 is actually disabled here
Gaetios 2:85734ad35573 2648 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, !enabled);
Gaetios 2:85734ad35573 2649 }
Gaetios 2:85734ad35573 2650 /** Get clock source setting.
Gaetios 2:85734ad35573 2651 * @return Current clock source setting
Gaetios 2:85734ad35573 2652 * @see MPU6050_RA_PWR_MGMT_1
Gaetios 2:85734ad35573 2653 * @see MPU6050_PWR1_CLKSEL_BIT
Gaetios 2:85734ad35573 2654 * @see MPU6050_PWR1_CLKSEL_LENGTH
Gaetios 2:85734ad35573 2655 */
Gaetios 2:85734ad35573 2656 uint8_t MPU60503::getClockSource()
Gaetios 2:85734ad35573 2657 {
Gaetios 2:85734ad35573 2658 i2Cdev.readBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, buffer);
Gaetios 2:85734ad35573 2659 return buffer[0];
Gaetios 2:85734ad35573 2660 }
Gaetios 2:85734ad35573 2661 /** Set clock source setting.
Gaetios 2:85734ad35573 2662 * An internal 8MHz oscillator, gyroscope based clock, or external sources can
Gaetios 2:85734ad35573 2663 * be selected as the MPU-60X0 clock source. When the internal 8 MHz oscillator
Gaetios 2:85734ad35573 2664 * or an external source is chosen as the clock source, the MPU-60X0 can operate
Gaetios 2:85734ad35573 2665 * in low power modes with the gyroscopes disabled.
Gaetios 2:85734ad35573 2666 *
Gaetios 2:85734ad35573 2667 * Upon power up, the MPU-60X0 clock source defaults to the internal oscillator.
Gaetios 2:85734ad35573 2668 * However, it is highly recommended that the device be configured to use one of
Gaetios 2:85734ad35573 2669 * the gyroscopes (or an external clock source) as the clock reference for
Gaetios 2:85734ad35573 2670 * improved stability. The clock source can be selected according to the following table:
Gaetios 2:85734ad35573 2671 *
Gaetios 2:85734ad35573 2672 * <pre>
Gaetios 2:85734ad35573 2673 * CLK_SEL | Clock Source
Gaetios 2:85734ad35573 2674 * --------+--------------------------------------
Gaetios 2:85734ad35573 2675 * 0 | Internal oscillator
Gaetios 2:85734ad35573 2676 * 1 | PLL with X Gyro reference
Gaetios 2:85734ad35573 2677 * 2 | PLL with Y Gyro reference
Gaetios 2:85734ad35573 2678 * 3 | PLL with Z Gyro reference
Gaetios 2:85734ad35573 2679 * 4 | PLL with external 32.768kHz reference
Gaetios 2:85734ad35573 2680 * 5 | PLL with external 19.2MHz reference
Gaetios 2:85734ad35573 2681 * 6 | Reserved
Gaetios 2:85734ad35573 2682 * 7 | Stops the clock and keeps the timing generator in reset
Gaetios 2:85734ad35573 2683 * </pre>
Gaetios 2:85734ad35573 2684 *
Gaetios 2:85734ad35573 2685 * @param source New clock source setting
Gaetios 2:85734ad35573 2686 * @see getClockSource()
Gaetios 2:85734ad35573 2687 * @see MPU6050_RA_PWR_MGMT_1
Gaetios 2:85734ad35573 2688 * @see MPU6050_PWR1_CLKSEL_BIT
Gaetios 2:85734ad35573 2689 * @see MPU6050_PWR1_CLKSEL_LENGTH
Gaetios 2:85734ad35573 2690 */
Gaetios 2:85734ad35573 2691 void MPU60503::setClockSource(uint8_t source)
Gaetios 2:85734ad35573 2692 {
Gaetios 2:85734ad35573 2693 i2Cdev.writeBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, source);
Gaetios 2:85734ad35573 2694 }
Gaetios 2:85734ad35573 2695
Gaetios 2:85734ad35573 2696 // PWR_MGMT_2 register
Gaetios 2:85734ad35573 2697
Gaetios 2:85734ad35573 2698 /** Get wake frequency in Accel-Only Low Power Mode.
Gaetios 2:85734ad35573 2699 * The MPU-60X0 can be put into Accerlerometer Only Low Power Mode by setting
Gaetios 2:85734ad35573 2700 * PWRSEL to 1 in the Power Management 1 register (Register 107). In this mode,
Gaetios 2:85734ad35573 2701 * the device will power off all devices except for the primary I2C interface,
Gaetios 2:85734ad35573 2702 * waking only the accelerometer at fixed intervals to take a single
Gaetios 2:85734ad35573 2703 * measurement. The frequency of wake-ups can be configured with LP_WAKE_CTRL
Gaetios 2:85734ad35573 2704 * as shown below:
Gaetios 2:85734ad35573 2705 *
Gaetios 2:85734ad35573 2706 * <pre>
Gaetios 2:85734ad35573 2707 * LP_WAKE_CTRL | Wake-up Frequency
Gaetios 2:85734ad35573 2708 * -------------+------------------
Gaetios 2:85734ad35573 2709 * 0 | 1.25 Hz
Gaetios 2:85734ad35573 2710 * 1 | 2.5 Hz
Gaetios 2:85734ad35573 2711 * 2 | 5 Hz
Gaetios 2:85734ad35573 2712 * 3 | 10 Hz
Gaetios 2:85734ad35573 2713 * <pre>
Gaetios 2:85734ad35573 2714 *
Gaetios 2:85734ad35573 2715 * For further information regarding the MPU-60X0's power modes, please refer to
Gaetios 2:85734ad35573 2716 * Register 107.
Gaetios 2:85734ad35573 2717 *
Gaetios 2:85734ad35573 2718 * @return Current wake frequency
Gaetios 2:85734ad35573 2719 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2720 */
Gaetios 2:85734ad35573 2721 uint8_t MPU60503::getWakeFrequency()
Gaetios 2:85734ad35573 2722 {
Gaetios 2:85734ad35573 2723 i2Cdev.readBits(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_LP_WAKE_CTRL_BIT, MPU6050_PWR2_LP_WAKE_CTRL_LENGTH, buffer);
Gaetios 2:85734ad35573 2724 return buffer[0];
Gaetios 2:85734ad35573 2725 }
Gaetios 2:85734ad35573 2726 /** Set wake frequency in Accel-Only Low Power Mode.
Gaetios 2:85734ad35573 2727 * @param frequency New wake frequency
Gaetios 2:85734ad35573 2728 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2729 */
Gaetios 2:85734ad35573 2730 void MPU60503::setWakeFrequency(uint8_t frequency)
Gaetios 2:85734ad35573 2731 {
Gaetios 2:85734ad35573 2732 i2Cdev.writeBits(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_LP_WAKE_CTRL_BIT, MPU6050_PWR2_LP_WAKE_CTRL_LENGTH, frequency);
Gaetios 2:85734ad35573 2733 }
Gaetios 2:85734ad35573 2734
Gaetios 2:85734ad35573 2735 /** Get X-axis accelerometer standby enabled status.
Gaetios 2:85734ad35573 2736 * If enabled, the X-axis will not gather or report data (or use power).
Gaetios 2:85734ad35573 2737 * @return Current X-axis standby enabled status
Gaetios 2:85734ad35573 2738 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2739 * @see MPU6050_PWR2_STBY_XA_BIT
Gaetios 2:85734ad35573 2740 */
Gaetios 2:85734ad35573 2741 bool MPU60503::getStandbyXAccelEnabled()
Gaetios 2:85734ad35573 2742 {
Gaetios 2:85734ad35573 2743 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, buffer);
Gaetios 2:85734ad35573 2744 return buffer[0];
Gaetios 2:85734ad35573 2745 }
Gaetios 2:85734ad35573 2746 /** Set X-axis accelerometer standby enabled status.
Gaetios 2:85734ad35573 2747 * @param New X-axis standby enabled status
Gaetios 2:85734ad35573 2748 * @see getStandbyXAccelEnabled()
Gaetios 2:85734ad35573 2749 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2750 * @see MPU6050_PWR2_STBY_XA_BIT
Gaetios 2:85734ad35573 2751 */
Gaetios 2:85734ad35573 2752 void MPU60503::setStandbyXAccelEnabled(bool enabled)
Gaetios 2:85734ad35573 2753 {
Gaetios 2:85734ad35573 2754 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, enabled);
Gaetios 2:85734ad35573 2755 }
Gaetios 2:85734ad35573 2756 /** Get Y-axis accelerometer standby enabled status.
Gaetios 2:85734ad35573 2757 * If enabled, the Y-axis will not gather or report data (or use power).
Gaetios 2:85734ad35573 2758 * @return Current Y-axis standby enabled status
Gaetios 2:85734ad35573 2759 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2760 * @see MPU6050_PWR2_STBY_YA_BIT
Gaetios 2:85734ad35573 2761 */
Gaetios 2:85734ad35573 2762 bool MPU60503::getStandbyYAccelEnabled()
Gaetios 2:85734ad35573 2763 {
Gaetios 2:85734ad35573 2764 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, buffer);
Gaetios 2:85734ad35573 2765 return buffer[0];
Gaetios 2:85734ad35573 2766 }
Gaetios 2:85734ad35573 2767 /** Set Y-axis accelerometer standby enabled status.
Gaetios 2:85734ad35573 2768 * @param New Y-axis standby enabled status
Gaetios 2:85734ad35573 2769 * @see getStandbyYAccelEnabled()
Gaetios 2:85734ad35573 2770 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2771 * @see MPU6050_PWR2_STBY_YA_BIT
Gaetios 2:85734ad35573 2772 */
Gaetios 2:85734ad35573 2773 void MPU60503::setStandbyYAccelEnabled(bool enabled)
Gaetios 2:85734ad35573 2774 {
Gaetios 2:85734ad35573 2775 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, enabled);
Gaetios 2:85734ad35573 2776 }
Gaetios 2:85734ad35573 2777 /** Get Z-axis accelerometer standby enabled status.
Gaetios 2:85734ad35573 2778 * If enabled, the Z-axis will not gather or report data (or use power).
Gaetios 2:85734ad35573 2779 * @return Current Z-axis standby enabled status
Gaetios 2:85734ad35573 2780 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2781 * @see MPU6050_PWR2_STBY_ZA_BIT
Gaetios 2:85734ad35573 2782 */
Gaetios 2:85734ad35573 2783 bool MPU60503::getStandbyZAccelEnabled()
Gaetios 2:85734ad35573 2784 {
Gaetios 2:85734ad35573 2785 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, buffer);
Gaetios 2:85734ad35573 2786 return buffer[0];
Gaetios 2:85734ad35573 2787 }
Gaetios 2:85734ad35573 2788 /** Set Z-axis accelerometer standby enabled status.
Gaetios 2:85734ad35573 2789 * @param New Z-axis standby enabled status
Gaetios 2:85734ad35573 2790 * @see getStandbyZAccelEnabled()
Gaetios 2:85734ad35573 2791 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2792 * @see MPU6050_PWR2_STBY_ZA_BIT
Gaetios 2:85734ad35573 2793 */
Gaetios 2:85734ad35573 2794 void MPU60503::setStandbyZAccelEnabled(bool enabled)
Gaetios 2:85734ad35573 2795 {
Gaetios 2:85734ad35573 2796 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, enabled);
Gaetios 2:85734ad35573 2797 }
Gaetios 2:85734ad35573 2798 /** Get X-axis gyroscope standby enabled status.
Gaetios 2:85734ad35573 2799 * If enabled, the X-axis will not gather or report data (or use power).
Gaetios 2:85734ad35573 2800 * @return Current X-axis standby enabled status
Gaetios 2:85734ad35573 2801 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2802 * @see MPU6050_PWR2_STBY_XG_BIT
Gaetios 2:85734ad35573 2803 */
Gaetios 2:85734ad35573 2804 bool MPU60503::getStandbyXGyroEnabled()
Gaetios 2:85734ad35573 2805 {
Gaetios 2:85734ad35573 2806 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, buffer);
Gaetios 2:85734ad35573 2807 return buffer[0];
Gaetios 2:85734ad35573 2808 }
Gaetios 2:85734ad35573 2809 /** Set X-axis gyroscope standby enabled status.
Gaetios 2:85734ad35573 2810 * @param New X-axis standby enabled status
Gaetios 2:85734ad35573 2811 * @see getStandbyXGyroEnabled()
Gaetios 2:85734ad35573 2812 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2813 * @see MPU6050_PWR2_STBY_XG_BIT
Gaetios 2:85734ad35573 2814 */
Gaetios 2:85734ad35573 2815 void MPU60503::setStandbyXGyroEnabled(bool enabled)
Gaetios 2:85734ad35573 2816 {
Gaetios 2:85734ad35573 2817 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, enabled);
Gaetios 2:85734ad35573 2818 }
Gaetios 2:85734ad35573 2819 /** Get Y-axis gyroscope standby enabled status.
Gaetios 2:85734ad35573 2820 * If enabled, the Y-axis will not gather or report data (or use power).
Gaetios 2:85734ad35573 2821 * @return Current Y-axis standby enabled status
Gaetios 2:85734ad35573 2822 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2823 * @see MPU6050_PWR2_STBY_YG_BIT
Gaetios 2:85734ad35573 2824 */
Gaetios 2:85734ad35573 2825 bool MPU60503::getStandbyYGyroEnabled()
Gaetios 2:85734ad35573 2826 {
Gaetios 2:85734ad35573 2827 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, buffer);
Gaetios 2:85734ad35573 2828 return buffer[0];
Gaetios 2:85734ad35573 2829 }
Gaetios 2:85734ad35573 2830 /** Set Y-axis gyroscope standby enabled status.
Gaetios 2:85734ad35573 2831 * @param New Y-axis standby enabled status
Gaetios 2:85734ad35573 2832 * @see getStandbyYGyroEnabled()
Gaetios 2:85734ad35573 2833 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2834 * @see MPU6050_PWR2_STBY_YG_BIT
Gaetios 2:85734ad35573 2835 */
Gaetios 2:85734ad35573 2836 void MPU60503::setStandbyYGyroEnabled(bool enabled)
Gaetios 2:85734ad35573 2837 {
Gaetios 2:85734ad35573 2838 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, enabled);
Gaetios 2:85734ad35573 2839 }
Gaetios 2:85734ad35573 2840 /** Get Z-axis gyroscope standby enabled status.
Gaetios 2:85734ad35573 2841 * If enabled, the Z-axis will not gather or report data (or use power).
Gaetios 2:85734ad35573 2842 * @return Current Z-axis standby enabled status
Gaetios 2:85734ad35573 2843 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2844 * @see MPU6050_PWR2_STBY_ZG_BIT
Gaetios 2:85734ad35573 2845 */
Gaetios 2:85734ad35573 2846 bool MPU60503::getStandbyZGyroEnabled()
Gaetios 2:85734ad35573 2847 {
Gaetios 2:85734ad35573 2848 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, buffer);
Gaetios 2:85734ad35573 2849 return buffer[0];
Gaetios 2:85734ad35573 2850 }
Gaetios 2:85734ad35573 2851 /** Set Z-axis gyroscope standby enabled status.
Gaetios 2:85734ad35573 2852 * @param New Z-axis standby enabled status
Gaetios 2:85734ad35573 2853 * @see getStandbyZGyroEnabled()
Gaetios 2:85734ad35573 2854 * @see MPU6050_RA_PWR_MGMT_2
Gaetios 2:85734ad35573 2855 * @see MPU6050_PWR2_STBY_ZG_BIT
Gaetios 2:85734ad35573 2856 */
Gaetios 2:85734ad35573 2857 void MPU60503::setStandbyZGyroEnabled(bool enabled)
Gaetios 2:85734ad35573 2858 {
Gaetios 2:85734ad35573 2859 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, enabled);
Gaetios 2:85734ad35573 2860 }
Gaetios 2:85734ad35573 2861
Gaetios 2:85734ad35573 2862 // FIFO_COUNT* registers
Gaetios 2:85734ad35573 2863
Gaetios 2:85734ad35573 2864 /** Get current FIFO buffer size.
Gaetios 2:85734ad35573 2865 * This value indicates the number of bytes stored in the FIFO buffer. This
Gaetios 2:85734ad35573 2866 * number is in turn the number of bytes that can be read from the FIFO buffer
Gaetios 2:85734ad35573 2867 * and it is directly proportional to the number of samples available given the
Gaetios 2:85734ad35573 2868 * set of sensor data bound to be stored in the FIFO (register 35 and 36).
Gaetios 2:85734ad35573 2869 * @return Current FIFO buffer size
Gaetios 2:85734ad35573 2870 */
Gaetios 2:85734ad35573 2871 uint16_t MPU60503::getFIFOCount()
Gaetios 2:85734ad35573 2872 {
Gaetios 2:85734ad35573 2873 i2Cdev.readBytes(devAddr, MPU6050_RA_FIFO_COUNTH, 2, buffer);
Gaetios 2:85734ad35573 2874 return (((uint16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 2875 }
Gaetios 2:85734ad35573 2876
Gaetios 2:85734ad35573 2877 // FIFO_R_W register
Gaetios 2:85734ad35573 2878
Gaetios 2:85734ad35573 2879 /** Get byte from FIFO buffer.
Gaetios 2:85734ad35573 2880 * This register is used to read and write data from the FIFO buffer. Data is
Gaetios 2:85734ad35573 2881 * written to the FIFO in order of register number (from lowest to highest). If
Gaetios 2:85734ad35573 2882 * all the FIFO enable flags (see below) are enabled and all External Sensor
Gaetios 2:85734ad35573 2883 * Data registers (Registers 73 to 96) are associated with a Slave device, the
Gaetios 2:85734ad35573 2884 * contents of registers 59 through 96 will be written in order at the Sample
Gaetios 2:85734ad35573 2885 * Rate.
Gaetios 2:85734ad35573 2886 *
Gaetios 2:85734ad35573 2887 * The contents of the sensor data registers (Registers 59 to 96) are written
Gaetios 2:85734ad35573 2888 * into the FIFO buffer when their corresponding FIFO enable flags are set to 1
Gaetios 2:85734ad35573 2889 * in FIFO_EN (Register 35). An additional flag for the sensor data registers
Gaetios 2:85734ad35573 2890 * associated with I2C Slave 3 can be found in I2C_MST_CTRL (Register 36).
Gaetios 2:85734ad35573 2891 *
Gaetios 2:85734ad35573 2892 * If the FIFO buffer has overflowed, the status bit FIFO_OFLOW_INT is
Gaetios 2:85734ad35573 2893 * automatically set to 1. This bit is located in INT_STATUS (Register 58).
Gaetios 2:85734ad35573 2894 * When the FIFO buffer has overflowed, the oldest data will be lost and new
Gaetios 2:85734ad35573 2895 * data will be written to the FIFO.
Gaetios 2:85734ad35573 2896 *
Gaetios 2:85734ad35573 2897 * If the FIFO buffer is empty, reading this register will return the last byte
Gaetios 2:85734ad35573 2898 * that was previously read from the FIFO until new data is available. The user
Gaetios 2:85734ad35573 2899 * should check FIFO_COUNT to ensure that the FIFO buffer is not read when
Gaetios 2:85734ad35573 2900 * empty.
Gaetios 2:85734ad35573 2901 *
Gaetios 2:85734ad35573 2902 * @return Byte from FIFO buffer
Gaetios 2:85734ad35573 2903 */
Gaetios 2:85734ad35573 2904 uint8_t MPU60503::getFIFOByte()
Gaetios 2:85734ad35573 2905 {
Gaetios 2:85734ad35573 2906 i2Cdev.readByte(devAddr, MPU6050_RA_FIFO_R_W, buffer);
Gaetios 2:85734ad35573 2907 return buffer[0];
Gaetios 2:85734ad35573 2908 }
Gaetios 2:85734ad35573 2909 void MPU60503::getFIFOBytes(uint8_t *data, uint8_t length)
Gaetios 2:85734ad35573 2910 {
Gaetios 2:85734ad35573 2911 i2Cdev.readBytes(devAddr, MPU6050_RA_FIFO_R_W, length, data);
Gaetios 2:85734ad35573 2912 }
Gaetios 2:85734ad35573 2913 /** Write byte to FIFO buffer.
Gaetios 2:85734ad35573 2914 * @see getFIFOByte()
Gaetios 2:85734ad35573 2915 * @see MPU6050_RA_FIFO_R_W
Gaetios 2:85734ad35573 2916 */
Gaetios 2:85734ad35573 2917 void MPU60503::setFIFOByte(uint8_t data)
Gaetios 2:85734ad35573 2918 {
Gaetios 2:85734ad35573 2919 i2Cdev.writeByte(devAddr, MPU6050_RA_FIFO_R_W, data);
Gaetios 2:85734ad35573 2920 }
Gaetios 2:85734ad35573 2921
Gaetios 2:85734ad35573 2922 // WHO_AM_I register
Gaetios 2:85734ad35573 2923
Gaetios 2:85734ad35573 2924 /** Get Device ID.
Gaetios 2:85734ad35573 2925 * This register is used to verify the identity of the device (0b110100, 0x34).
Gaetios 2:85734ad35573 2926 * @return Device ID (6 bits only! should be 0x34)
Gaetios 2:85734ad35573 2927 * @see MPU6050_RA_WHO_AM_I
Gaetios 2:85734ad35573 2928 * @see MPU6050_WHO_AM_I_BIT
Gaetios 2:85734ad35573 2929 * @see MPU6050_WHO_AM_I_LENGTH
Gaetios 2:85734ad35573 2930 */
Gaetios 2:85734ad35573 2931 uint8_t MPU60503::getDeviceID()
Gaetios 2:85734ad35573 2932 {
Gaetios 2:85734ad35573 2933 i2Cdev.readBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, buffer);
Gaetios 2:85734ad35573 2934 return buffer[0];
Gaetios 2:85734ad35573 2935 }
Gaetios 2:85734ad35573 2936 /** Set Device ID.
Gaetios 2:85734ad35573 2937 * Write a new ID into the WHO_AM_I register (no idea why this should ever be
Gaetios 2:85734ad35573 2938 * necessary though).
Gaetios 2:85734ad35573 2939 * @param id New device ID to set.
Gaetios 2:85734ad35573 2940 * @see getDeviceID()
Gaetios 2:85734ad35573 2941 * @see MPU6050_RA_WHO_AM_I
Gaetios 2:85734ad35573 2942 * @see MPU6050_WHO_AM_I_BIT
Gaetios 2:85734ad35573 2943 * @see MPU6050_WHO_AM_I_LENGTH
Gaetios 2:85734ad35573 2944 */
Gaetios 2:85734ad35573 2945 void MPU60503::setDeviceID(uint8_t id)
Gaetios 2:85734ad35573 2946 {
Gaetios 2:85734ad35573 2947 i2Cdev.writeBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, id);
Gaetios 2:85734ad35573 2948 }
Gaetios 2:85734ad35573 2949
Gaetios 2:85734ad35573 2950 // ======== UNDOCUMENTED/DMP REGISTERS/METHODS ========
Gaetios 2:85734ad35573 2951
Gaetios 2:85734ad35573 2952 // XG_OFFS_TC register
Gaetios 2:85734ad35573 2953
Gaetios 2:85734ad35573 2954 uint8_t MPU60503::getOTPBankValid()
Gaetios 2:85734ad35573 2955 {
Gaetios 2:85734ad35573 2956 i2Cdev.readBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, buffer);
Gaetios 2:85734ad35573 2957 return buffer[0];
Gaetios 2:85734ad35573 2958 }
Gaetios 2:85734ad35573 2959 void MPU60503::setOTPBankValid(bool enabled)
Gaetios 2:85734ad35573 2960 {
Gaetios 2:85734ad35573 2961 i2Cdev.writeBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, enabled);
Gaetios 2:85734ad35573 2962 }
Gaetios 2:85734ad35573 2963 int8_t MPU60503::getXGyroOffset()
Gaetios 2:85734ad35573 2964 {
Gaetios 2:85734ad35573 2965 i2Cdev.readBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer);
Gaetios 2:85734ad35573 2966 return buffer[0];
Gaetios 2:85734ad35573 2967 }
Gaetios 2:85734ad35573 2968 void MPU60503::setXGyroOffset(int8_t offset)
Gaetios 2:85734ad35573 2969 {
Gaetios 2:85734ad35573 2970 i2Cdev.writeBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset);
Gaetios 2:85734ad35573 2971 }
Gaetios 2:85734ad35573 2972
Gaetios 2:85734ad35573 2973 // YG_OFFS_TC register
Gaetios 2:85734ad35573 2974
Gaetios 2:85734ad35573 2975 int8_t MPU60503::getYGyroOffset()
Gaetios 2:85734ad35573 2976 {
Gaetios 2:85734ad35573 2977 i2Cdev.readBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer);
Gaetios 2:85734ad35573 2978 return buffer[0];
Gaetios 2:85734ad35573 2979 }
Gaetios 2:85734ad35573 2980 void MPU60503::setYGyroOffset(int8_t offset)
Gaetios 2:85734ad35573 2981 {
Gaetios 2:85734ad35573 2982 i2Cdev.writeBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset);
Gaetios 2:85734ad35573 2983 }
Gaetios 2:85734ad35573 2984
Gaetios 2:85734ad35573 2985 // ZG_OFFS_TC register
Gaetios 2:85734ad35573 2986
Gaetios 2:85734ad35573 2987 int8_t MPU60503::getZGyroOffset()
Gaetios 2:85734ad35573 2988 {
Gaetios 2:85734ad35573 2989 i2Cdev.readBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer);
Gaetios 2:85734ad35573 2990 return buffer[0];
Gaetios 2:85734ad35573 2991 }
Gaetios 2:85734ad35573 2992 void MPU60503::setZGyroOffset(int8_t offset)
Gaetios 2:85734ad35573 2993 {
Gaetios 2:85734ad35573 2994 i2Cdev.writeBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset);
Gaetios 2:85734ad35573 2995 }
Gaetios 2:85734ad35573 2996
Gaetios 2:85734ad35573 2997 // X_FINE_GAIN register
Gaetios 2:85734ad35573 2998
Gaetios 2:85734ad35573 2999 int8_t MPU60503::getXFineGain()
Gaetios 2:85734ad35573 3000 {
Gaetios 2:85734ad35573 3001 i2Cdev.readByte(devAddr, MPU6050_RA_X_FINE_GAIN, buffer);
Gaetios 2:85734ad35573 3002 return buffer[0];
Gaetios 2:85734ad35573 3003 }
Gaetios 2:85734ad35573 3004 void MPU60503::setXFineGain(int8_t gain)
Gaetios 2:85734ad35573 3005 {
Gaetios 2:85734ad35573 3006 i2Cdev.writeByte(devAddr, MPU6050_RA_X_FINE_GAIN, gain);
Gaetios 2:85734ad35573 3007 }
Gaetios 2:85734ad35573 3008
Gaetios 2:85734ad35573 3009 // Y_FINE_GAIN register
Gaetios 2:85734ad35573 3010
Gaetios 2:85734ad35573 3011 int8_t MPU60503::getYFineGain()
Gaetios 2:85734ad35573 3012 {
Gaetios 2:85734ad35573 3013 i2Cdev.readByte(devAddr, MPU6050_RA_Y_FINE_GAIN, buffer);
Gaetios 2:85734ad35573 3014 return buffer[0];
Gaetios 2:85734ad35573 3015 }
Gaetios 2:85734ad35573 3016 void MPU60503::setYFineGain(int8_t gain)
Gaetios 2:85734ad35573 3017 {
Gaetios 2:85734ad35573 3018 i2Cdev.writeByte(devAddr, MPU6050_RA_Y_FINE_GAIN, gain);
Gaetios 2:85734ad35573 3019 }
Gaetios 2:85734ad35573 3020
Gaetios 2:85734ad35573 3021 // Z_FINE_GAIN register
Gaetios 2:85734ad35573 3022
Gaetios 2:85734ad35573 3023 int8_t MPU60503::getZFineGain()
Gaetios 2:85734ad35573 3024 {
Gaetios 2:85734ad35573 3025 i2Cdev.readByte(devAddr, MPU6050_RA_Z_FINE_GAIN, buffer);
Gaetios 2:85734ad35573 3026 return buffer[0];
Gaetios 2:85734ad35573 3027 }
Gaetios 2:85734ad35573 3028 void MPU60503::setZFineGain(int8_t gain)
Gaetios 2:85734ad35573 3029 {
Gaetios 2:85734ad35573 3030 i2Cdev.writeByte(devAddr, MPU6050_RA_Z_FINE_GAIN, gain);
Gaetios 2:85734ad35573 3031 }
Gaetios 2:85734ad35573 3032
Gaetios 2:85734ad35573 3033 // XA_OFFS_* registers
Gaetios 2:85734ad35573 3034
Gaetios 2:85734ad35573 3035 int16_t MPU60503::getXAccelOffset()
Gaetios 2:85734ad35573 3036 {
Gaetios 2:85734ad35573 3037 i2Cdev.readBytes(devAddr, MPU6050_RA_XA_OFFS_H, 2, buffer);
Gaetios 2:85734ad35573 3038 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 3039 }
Gaetios 2:85734ad35573 3040 void MPU60503::setXAccelOffset(int16_t offset)
Gaetios 2:85734ad35573 3041 {
Gaetios 2:85734ad35573 3042 i2Cdev.writeWord(devAddr, MPU6050_RA_XA_OFFS_H, offset);
Gaetios 2:85734ad35573 3043 }
Gaetios 2:85734ad35573 3044
Gaetios 2:85734ad35573 3045 // YA_OFFS_* register
Gaetios 2:85734ad35573 3046
Gaetios 2:85734ad35573 3047 int16_t MPU60503::getYAccelOffset()
Gaetios 2:85734ad35573 3048 {
Gaetios 2:85734ad35573 3049 i2Cdev.readBytes(devAddr, MPU6050_RA_YA_OFFS_H, 2, buffer);
Gaetios 2:85734ad35573 3050 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 3051 }
Gaetios 2:85734ad35573 3052 void MPU60503::setYAccelOffset(int16_t offset)
Gaetios 2:85734ad35573 3053 {
Gaetios 2:85734ad35573 3054 i2Cdev.writeWord(devAddr, MPU6050_RA_YA_OFFS_H, offset);
Gaetios 2:85734ad35573 3055 }
Gaetios 2:85734ad35573 3056
Gaetios 2:85734ad35573 3057 // ZA_OFFS_* register
Gaetios 2:85734ad35573 3058
Gaetios 2:85734ad35573 3059 int16_t MPU60503::getZAccelOffset()
Gaetios 2:85734ad35573 3060 {
Gaetios 2:85734ad35573 3061 i2Cdev.readBytes(devAddr, MPU6050_RA_ZA_OFFS_H, 2, buffer);
Gaetios 2:85734ad35573 3062 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 3063 }
Gaetios 2:85734ad35573 3064 void MPU60503::setZAccelOffset(int16_t offset)
Gaetios 2:85734ad35573 3065 {
Gaetios 2:85734ad35573 3066 i2Cdev.writeWord(devAddr, MPU6050_RA_ZA_OFFS_H, offset);
Gaetios 2:85734ad35573 3067 }
Gaetios 2:85734ad35573 3068
Gaetios 2:85734ad35573 3069 // XG_OFFS_USR* registers
Gaetios 2:85734ad35573 3070
Gaetios 2:85734ad35573 3071 int16_t MPU60503::getXGyroOffsetUser()
Gaetios 2:85734ad35573 3072 {
Gaetios 2:85734ad35573 3073 i2Cdev.readBytes(devAddr, MPU6050_RA_XG_OFFS_USRH, 2, buffer);
Gaetios 2:85734ad35573 3074 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 3075 }
Gaetios 2:85734ad35573 3076 void MPU60503::setXGyroOffsetUser(int16_t offset)
Gaetios 2:85734ad35573 3077 {
Gaetios 2:85734ad35573 3078 i2Cdev.writeWord(devAddr, MPU6050_RA_XG_OFFS_USRH, offset);
Gaetios 2:85734ad35573 3079 }
Gaetios 2:85734ad35573 3080
Gaetios 2:85734ad35573 3081 // YG_OFFS_USR* register
Gaetios 2:85734ad35573 3082
Gaetios 2:85734ad35573 3083 int16_t MPU60503::getYGyroOffsetUser()
Gaetios 2:85734ad35573 3084 {
Gaetios 2:85734ad35573 3085 i2Cdev.readBytes(devAddr, MPU6050_RA_YG_OFFS_USRH, 2, buffer);
Gaetios 2:85734ad35573 3086 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 3087 }
Gaetios 2:85734ad35573 3088 void MPU60503::setYGyroOffsetUser(int16_t offset)
Gaetios 2:85734ad35573 3089 {
Gaetios 2:85734ad35573 3090 i2Cdev.writeWord(devAddr, MPU6050_RA_YG_OFFS_USRH, offset);
Gaetios 2:85734ad35573 3091 }
Gaetios 2:85734ad35573 3092
Gaetios 2:85734ad35573 3093 // ZG_OFFS_USR* register
Gaetios 2:85734ad35573 3094
Gaetios 2:85734ad35573 3095 int16_t MPU60503::getZGyroOffsetUser()
Gaetios 2:85734ad35573 3096 {
Gaetios 2:85734ad35573 3097 i2Cdev.readBytes(devAddr, MPU6050_RA_ZG_OFFS_USRH, 2, buffer);
Gaetios 2:85734ad35573 3098 return (((int16_t)buffer[0]) << 8) | buffer[1];
Gaetios 2:85734ad35573 3099 }
Gaetios 2:85734ad35573 3100 void MPU60503::setZGyroOffsetUser(int16_t offset)
Gaetios 2:85734ad35573 3101 {
Gaetios 2:85734ad35573 3102 i2Cdev.writeWord(devAddr, MPU6050_RA_ZG_OFFS_USRH, offset);
Gaetios 2:85734ad35573 3103 }
Gaetios 2:85734ad35573 3104
Gaetios 2:85734ad35573 3105 // INT_ENABLE register (DMP functions)
Gaetios 2:85734ad35573 3106
Gaetios 2:85734ad35573 3107 bool MPU60503::getIntPLLReadyEnabled()
Gaetios 2:85734ad35573 3108 {
Gaetios 2:85734ad35573 3109 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, buffer);
Gaetios 2:85734ad35573 3110 return buffer[0];
Gaetios 2:85734ad35573 3111 }
Gaetios 2:85734ad35573 3112 void MPU60503::setIntPLLReadyEnabled(bool enabled)
Gaetios 2:85734ad35573 3113 {
Gaetios 2:85734ad35573 3114 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, enabled);
Gaetios 2:85734ad35573 3115 }
Gaetios 2:85734ad35573 3116 bool MPU60503::getIntDMPEnabled()
Gaetios 2:85734ad35573 3117 {
Gaetios 2:85734ad35573 3118 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DMP_INT_BIT, buffer);
Gaetios 2:85734ad35573 3119 return buffer[0];
Gaetios 2:85734ad35573 3120 }
Gaetios 2:85734ad35573 3121 void MPU60503::setIntDMPEnabled(bool enabled)
Gaetios 2:85734ad35573 3122 {
Gaetios 2:85734ad35573 3123 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DMP_INT_BIT, enabled);
Gaetios 2:85734ad35573 3124 }
Gaetios 2:85734ad35573 3125
Gaetios 2:85734ad35573 3126 // DMP_INT_STATUS
Gaetios 2:85734ad35573 3127
Gaetios 2:85734ad35573 3128 bool MPU60503::getDMPInt5Status()
Gaetios 2:85734ad35573 3129 {
Gaetios 2:85734ad35573 3130 i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_5_BIT, buffer);
Gaetios 2:85734ad35573 3131 return buffer[0];
Gaetios 2:85734ad35573 3132 }
Gaetios 2:85734ad35573 3133 bool MPU60503::getDMPInt4Status()
Gaetios 2:85734ad35573 3134 {
Gaetios 2:85734ad35573 3135 i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_4_BIT, buffer);
Gaetios 2:85734ad35573 3136 return buffer[0];
Gaetios 2:85734ad35573 3137 }
Gaetios 2:85734ad35573 3138 bool MPU60503::getDMPInt3Status()
Gaetios 2:85734ad35573 3139 {
Gaetios 2:85734ad35573 3140 i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_3_BIT, buffer);
Gaetios 2:85734ad35573 3141 return buffer[0];
Gaetios 2:85734ad35573 3142 }
Gaetios 2:85734ad35573 3143 bool MPU60503::getDMPInt2Status()
Gaetios 2:85734ad35573 3144 {
Gaetios 2:85734ad35573 3145 i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_2_BIT, buffer);
Gaetios 2:85734ad35573 3146 return buffer[0];
Gaetios 2:85734ad35573 3147 }
Gaetios 2:85734ad35573 3148 bool MPU60503::getDMPInt1Status()
Gaetios 2:85734ad35573 3149 {
Gaetios 2:85734ad35573 3150 i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_1_BIT, buffer);
Gaetios 2:85734ad35573 3151 return buffer[0];
Gaetios 2:85734ad35573 3152 }
Gaetios 2:85734ad35573 3153 bool MPU60503::getDMPInt0Status()
Gaetios 2:85734ad35573 3154 {
Gaetios 2:85734ad35573 3155 i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_0_BIT, buffer);
Gaetios 2:85734ad35573 3156 return buffer[0];
Gaetios 2:85734ad35573 3157 }
Gaetios 2:85734ad35573 3158
Gaetios 2:85734ad35573 3159 // INT_STATUS register (DMP functions)
Gaetios 2:85734ad35573 3160
Gaetios 2:85734ad35573 3161 bool MPU60503::getIntPLLReadyStatus()
Gaetios 2:85734ad35573 3162 {
Gaetios 2:85734ad35573 3163 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, buffer);
Gaetios 2:85734ad35573 3164 return buffer[0];
Gaetios 2:85734ad35573 3165 }
Gaetios 2:85734ad35573 3166 bool MPU60503::getIntDMPStatus()
Gaetios 2:85734ad35573 3167 {
Gaetios 2:85734ad35573 3168 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DMP_INT_BIT, buffer);
Gaetios 2:85734ad35573 3169 return buffer[0];
Gaetios 2:85734ad35573 3170 }
Gaetios 2:85734ad35573 3171
Gaetios 2:85734ad35573 3172 // USER_CTRL register (DMP functions)
Gaetios 2:85734ad35573 3173
Gaetios 2:85734ad35573 3174 bool MPU60503::getDMPEnabled()
Gaetios 2:85734ad35573 3175 {
Gaetios 2:85734ad35573 3176 i2Cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_EN_BIT, buffer);
Gaetios 2:85734ad35573 3177 return buffer[0];
Gaetios 2:85734ad35573 3178 }
Gaetios 2:85734ad35573 3179 void MPU60503::setDMPEnabled(bool enabled)
Gaetios 2:85734ad35573 3180 {
Gaetios 2:85734ad35573 3181 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_EN_BIT, enabled);
Gaetios 2:85734ad35573 3182 }
Gaetios 2:85734ad35573 3183 void MPU60503::resetDMP()
Gaetios 2:85734ad35573 3184 {
Gaetios 2:85734ad35573 3185 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_RESET_BIT, true);
Gaetios 2:85734ad35573 3186 }
Gaetios 2:85734ad35573 3187
Gaetios 2:85734ad35573 3188 // BANK_SEL register
Gaetios 2:85734ad35573 3189
Gaetios 2:85734ad35573 3190 void MPU60503::setMemoryBank(uint8_t bank, bool prefetchEnabled, bool userBank)
Gaetios 2:85734ad35573 3191 {
Gaetios 2:85734ad35573 3192 bank &= 0x1F;
Gaetios 2:85734ad35573 3193 if (userBank) bank |= 0x20;
Gaetios 2:85734ad35573 3194 if (prefetchEnabled) bank |= 0x40;
Gaetios 2:85734ad35573 3195 i2Cdev.writeByte(devAddr, MPU6050_RA_BANK_SEL, bank);
Gaetios 2:85734ad35573 3196 }
Gaetios 2:85734ad35573 3197
Gaetios 2:85734ad35573 3198 // MEM_START_ADDR register
Gaetios 2:85734ad35573 3199
Gaetios 2:85734ad35573 3200 void MPU60503::setMemoryStartAddress(uint8_t address)
Gaetios 2:85734ad35573 3201 {
Gaetios 2:85734ad35573 3202 i2Cdev.writeByte(devAddr, MPU6050_RA_MEM_START_ADDR, address);
Gaetios 2:85734ad35573 3203 }
Gaetios 2:85734ad35573 3204
Gaetios 2:85734ad35573 3205 // MEM_R_W register
Gaetios 2:85734ad35573 3206
Gaetios 2:85734ad35573 3207 uint8_t MPU60503::readMemoryByte()
Gaetios 2:85734ad35573 3208 {
Gaetios 2:85734ad35573 3209 i2Cdev.readByte(devAddr, MPU6050_RA_MEM_R_W, buffer);
Gaetios 2:85734ad35573 3210 return buffer[0];
Gaetios 2:85734ad35573 3211 }
Gaetios 2:85734ad35573 3212 void MPU60503::writeMemoryByte(uint8_t data)
Gaetios 2:85734ad35573 3213 {
Gaetios 2:85734ad35573 3214 i2Cdev.writeByte(devAddr, MPU6050_RA_MEM_R_W, data);
Gaetios 2:85734ad35573 3215 }
Gaetios 2:85734ad35573 3216 void MPU60503::readMemoryBlock(uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address)
Gaetios 2:85734ad35573 3217 {
Gaetios 2:85734ad35573 3218 setMemoryBank(bank);
Gaetios 2:85734ad35573 3219 setMemoryStartAddress(address);
Gaetios 2:85734ad35573 3220 uint8_t chunkSize;
Gaetios 2:85734ad35573 3221 for (uint16_t i = 0; i < dataSize;) {
Gaetios 2:85734ad35573 3222 // determine correct chunk size according to bank position and data size
Gaetios 2:85734ad35573 3223 chunkSize = MPU6050_DMP_MEMORY_CHUNK_SIZE;
Gaetios 2:85734ad35573 3224
Gaetios 2:85734ad35573 3225 // make sure we don't go past the data size
Gaetios 2:85734ad35573 3226 if (i + chunkSize > dataSize) chunkSize = dataSize - i;
Gaetios 2:85734ad35573 3227
Gaetios 2:85734ad35573 3228 // make sure this chunk doesn't go past the bank boundary (256 bytes)
Gaetios 2:85734ad35573 3229 if (chunkSize > 256 - address) chunkSize = 256 - address;
Gaetios 2:85734ad35573 3230
Gaetios 2:85734ad35573 3231 // read the chunk of data as specified
Gaetios 2:85734ad35573 3232 i2Cdev.readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, data + i);
Gaetios 2:85734ad35573 3233
Gaetios 2:85734ad35573 3234 // increase byte index by [chunkSize]
Gaetios 2:85734ad35573 3235 i += chunkSize;
Gaetios 2:85734ad35573 3236
Gaetios 2:85734ad35573 3237 // uint8_t automatically wraps to 0 at 256
Gaetios 2:85734ad35573 3238 address += chunkSize;
Gaetios 2:85734ad35573 3239
Gaetios 2:85734ad35573 3240 // if we aren't done, update bank (if necessary) and address
Gaetios 2:85734ad35573 3241 if (i < dataSize) {
Gaetios 2:85734ad35573 3242 if (address == 0) bank++;
Gaetios 2:85734ad35573 3243 setMemoryBank(bank);
Gaetios 2:85734ad35573 3244 setMemoryStartAddress(address);
Gaetios 2:85734ad35573 3245 }
Gaetios 2:85734ad35573 3246 }
Gaetios 2:85734ad35573 3247 }
Gaetios 2:85734ad35573 3248 bool MPU60503::writeMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify, bool useProgMem)
Gaetios 2:85734ad35573 3249 {
Gaetios 2:85734ad35573 3250 setMemoryBank(bank);
Gaetios 2:85734ad35573 3251 setMemoryStartAddress(address);
Gaetios 2:85734ad35573 3252 uint8_t chunkSize;
Gaetios 2:85734ad35573 3253 uint8_t *verifyBuffer;
Gaetios 2:85734ad35573 3254 uint8_t *progBuffer;
Gaetios 2:85734ad35573 3255 uint16_t i;
Gaetios 2:85734ad35573 3256 uint8_t j;
Gaetios 2:85734ad35573 3257 if (verify) verifyBuffer = (uint8_t *)malloc(MPU6050_DMP_MEMORY_CHUNK_SIZE);
Gaetios 2:85734ad35573 3258 if (useProgMem) progBuffer = (uint8_t *)malloc(MPU6050_DMP_MEMORY_CHUNK_SIZE);
Gaetios 2:85734ad35573 3259 for (i = 0; i < dataSize;) {
Gaetios 2:85734ad35573 3260 // determine correct chunk size according to bank position and data size
Gaetios 2:85734ad35573 3261 chunkSize = MPU6050_DMP_MEMORY_CHUNK_SIZE;
Gaetios 2:85734ad35573 3262
Gaetios 2:85734ad35573 3263 // make sure we don't go past the data size
Gaetios 2:85734ad35573 3264 if (i + chunkSize > dataSize) chunkSize = dataSize - i;
Gaetios 2:85734ad35573 3265
Gaetios 2:85734ad35573 3266 // make sure this chunk doesn't go past the bank boundary (256 bytes)
Gaetios 2:85734ad35573 3267 if (chunkSize > 256 - address) chunkSize = 256 - address;
Gaetios 2:85734ad35573 3268
Gaetios 2:85734ad35573 3269 if (useProgMem) {
Gaetios 2:85734ad35573 3270 // write the chunk of data as specified
Gaetios 2:85734ad35573 3271 for (j = 0; j < chunkSize; j++) progBuffer[j] = pgm_read_byte(data + i + j);
Gaetios 2:85734ad35573 3272 } else {
Gaetios 2:85734ad35573 3273 // write the chunk of data as specified
Gaetios 2:85734ad35573 3274 progBuffer = (uint8_t *)data + i;
Gaetios 2:85734ad35573 3275 }
Gaetios 2:85734ad35573 3276
Gaetios 2:85734ad35573 3277 i2Cdev.writeBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, progBuffer);
Gaetios 2:85734ad35573 3278
Gaetios 2:85734ad35573 3279 // verify data if needed
Gaetios 2:85734ad35573 3280 if (verify && verifyBuffer) {
Gaetios 2:85734ad35573 3281 setMemoryBank(bank);
Gaetios 2:85734ad35573 3282 setMemoryStartAddress(address);
Gaetios 2:85734ad35573 3283 i2Cdev.readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, verifyBuffer);
Gaetios 2:85734ad35573 3284 if (memcmp(progBuffer, verifyBuffer, chunkSize) != 0) {
Gaetios 2:85734ad35573 3285 /*Serial.print("Block write verification error, bank ");
Gaetios 2:85734ad35573 3286 Serial.print(bank, DEC);
Gaetios 2:85734ad35573 3287 Serial.print(", address ");
Gaetios 2:85734ad35573 3288 Serial.print(address, DEC);
Gaetios 2:85734ad35573 3289 Serial.print("!\nExpected:");
Gaetios 2:85734ad35573 3290 for (j = 0; j < chunkSize; j++) {
Gaetios 2:85734ad35573 3291 Serial.print(" 0x");
Gaetios 2:85734ad35573 3292 if (progBuffer[j] < 16) Serial.print("0");
Gaetios 2:85734ad35573 3293 Serial.print(progBuffer[j], HEX);
Gaetios 2:85734ad35573 3294 }
Gaetios 2:85734ad35573 3295 Serial.print("\nReceived:");
Gaetios 2:85734ad35573 3296 for (uint8_t j = 0; j < chunkSize; j++) {
Gaetios 2:85734ad35573 3297 Serial.print(" 0x");
Gaetios 2:85734ad35573 3298 if (verifyBuffer[i + j] < 16) Serial.print("0");
Gaetios 2:85734ad35573 3299 Serial.print(verifyBuffer[i + j], HEX);
Gaetios 2:85734ad35573 3300 }
Gaetios 2:85734ad35573 3301 Serial.print("\n");*/
Gaetios 2:85734ad35573 3302 free(verifyBuffer);
Gaetios 2:85734ad35573 3303 if (useProgMem) free(progBuffer);
Gaetios 2:85734ad35573 3304 return false; // uh oh.
Gaetios 2:85734ad35573 3305 }
Gaetios 2:85734ad35573 3306 }
Gaetios 2:85734ad35573 3307
Gaetios 2:85734ad35573 3308 // increase byte index by [chunkSize]
Gaetios 2:85734ad35573 3309 i += chunkSize;
Gaetios 2:85734ad35573 3310
Gaetios 2:85734ad35573 3311 // uint8_t automatically wraps to 0 at 256
Gaetios 2:85734ad35573 3312 address += chunkSize;
Gaetios 2:85734ad35573 3313
Gaetios 2:85734ad35573 3314 // if we aren't done, update bank (if necessary) and address
Gaetios 2:85734ad35573 3315 if (i < dataSize) {
Gaetios 2:85734ad35573 3316 if (address == 0) bank++;
Gaetios 2:85734ad35573 3317 setMemoryBank(bank);
Gaetios 2:85734ad35573 3318 setMemoryStartAddress(address);
Gaetios 2:85734ad35573 3319 }
Gaetios 2:85734ad35573 3320 }
Gaetios 2:85734ad35573 3321 if (verify) free(verifyBuffer);
Gaetios 2:85734ad35573 3322 if (useProgMem) free(progBuffer);
Gaetios 2:85734ad35573 3323 return true;
Gaetios 2:85734ad35573 3324 }
Gaetios 2:85734ad35573 3325 bool MPU60503::writeProgMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify)
Gaetios 2:85734ad35573 3326 {
Gaetios 2:85734ad35573 3327 return writeMemoryBlock(data, dataSize, bank, address, verify, true);
Gaetios 2:85734ad35573 3328 }
Gaetios 2:85734ad35573 3329 bool MPU60503::writeDMPConfigurationSet(const uint8_t *data, uint16_t dataSize, bool useProgMem)
Gaetios 2:85734ad35573 3330 {
Gaetios 2:85734ad35573 3331 uint8_t *progBuffer, success, special;
Gaetios 2:85734ad35573 3332 uint16_t i, j;
Gaetios 2:85734ad35573 3333 if (useProgMem) {
Gaetios 2:85734ad35573 3334 progBuffer = (uint8_t *)malloc(8); // assume 8-byte blocks, realloc later if necessary
Gaetios 2:85734ad35573 3335 }
Gaetios 2:85734ad35573 3336
Gaetios 2:85734ad35573 3337 // config set data is a long string of blocks with the following structure:
Gaetios 2:85734ad35573 3338 // [bank] [offset] [length] [byte[0], byte[1], ..., byte[length]]
Gaetios 2:85734ad35573 3339 uint8_t bank, offset, length;
Gaetios 2:85734ad35573 3340 for (i = 0; i < dataSize;) {
Gaetios 2:85734ad35573 3341 if (useProgMem) {
Gaetios 2:85734ad35573 3342 bank = pgm_read_byte(data + i++);
Gaetios 2:85734ad35573 3343 offset = pgm_read_byte(data + i++);
Gaetios 2:85734ad35573 3344 length = pgm_read_byte(data + i++);
Gaetios 2:85734ad35573 3345 } else {
Gaetios 2:85734ad35573 3346 bank = data[i++];
Gaetios 2:85734ad35573 3347 offset = data[i++];
Gaetios 2:85734ad35573 3348 length = data[i++];
Gaetios 2:85734ad35573 3349 }
Gaetios 2:85734ad35573 3350
Gaetios 2:85734ad35573 3351 // write data or perform special action
Gaetios 2:85734ad35573 3352 if (length > 0) {
Gaetios 2:85734ad35573 3353 // regular block of data to write
Gaetios 2:85734ad35573 3354 /*Serial.print("Writing config block to bank ");
Gaetios 2:85734ad35573 3355 Serial.print(bank);
Gaetios 2:85734ad35573 3356 Serial.print(", offset ");
Gaetios 2:85734ad35573 3357 Serial.print(offset);
Gaetios 2:85734ad35573 3358 Serial.print(", length=");
Gaetios 2:85734ad35573 3359 Serial.println(length);*/
Gaetios 2:85734ad35573 3360 if (useProgMem) {
Gaetios 2:85734ad35573 3361 if (sizeof(progBuffer) < length) progBuffer = (uint8_t *)realloc(progBuffer, length);
Gaetios 2:85734ad35573 3362 for (j = 0; j < length; j++) progBuffer[j] = pgm_read_byte(data + i + j);
Gaetios 2:85734ad35573 3363 } else {
Gaetios 2:85734ad35573 3364 progBuffer = (uint8_t *)data + i;
Gaetios 2:85734ad35573 3365 }
Gaetios 2:85734ad35573 3366 success = writeMemoryBlock(progBuffer, length, bank, offset, true);
Gaetios 2:85734ad35573 3367 i += length;
Gaetios 2:85734ad35573 3368 } else {
Gaetios 2:85734ad35573 3369 // special instruction
Gaetios 2:85734ad35573 3370 // NOTE: this kind of behavior (what and when to do certain things)
Gaetios 2:85734ad35573 3371 // is totally undocumented. This code is in here based on observed
Gaetios 2:85734ad35573 3372 // behavior only, and exactly why (or even whether) it has to be here
Gaetios 2:85734ad35573 3373 // is anybody's guess for now.
Gaetios 2:85734ad35573 3374 if (useProgMem) {
Gaetios 2:85734ad35573 3375 special = pgm_read_byte(data + i++);
Gaetios 2:85734ad35573 3376 } else {
Gaetios 2:85734ad35573 3377 special = data[i++];
Gaetios 2:85734ad35573 3378 }
Gaetios 2:85734ad35573 3379 /*Serial.print("Special command code ");
Gaetios 2:85734ad35573 3380 Serial.print(special, HEX);
Gaetios 2:85734ad35573 3381 Serial.println(" found...");*/
Gaetios 2:85734ad35573 3382 if (special == 0x01) {
Gaetios 2:85734ad35573 3383 // enable DMP-related interrupts
Gaetios 2:85734ad35573 3384
Gaetios 2:85734ad35573 3385 //setIntZeroMotionEnabled(true);
Gaetios 2:85734ad35573 3386 //setIntFIFOBufferOverflowEnabled(true);
Gaetios 2:85734ad35573 3387 //setIntDMPEnabled(true);
Gaetios 2:85734ad35573 3388 i2Cdev.writeByte(devAddr, MPU6050_RA_INT_ENABLE, 0x32); // single operation
Gaetios 2:85734ad35573 3389
Gaetios 2:85734ad35573 3390 success = true;
Gaetios 2:85734ad35573 3391 } else {
Gaetios 2:85734ad35573 3392 // unknown special command
Gaetios 2:85734ad35573 3393 success = false;
Gaetios 2:85734ad35573 3394 }
Gaetios 2:85734ad35573 3395 }
Gaetios 2:85734ad35573 3396
Gaetios 2:85734ad35573 3397 if (!success) {
Gaetios 2:85734ad35573 3398 if (useProgMem) free(progBuffer);
Gaetios 2:85734ad35573 3399 return false; // uh oh
Gaetios 2:85734ad35573 3400 }
Gaetios 2:85734ad35573 3401 }
Gaetios 2:85734ad35573 3402 if (useProgMem) free(progBuffer);
Gaetios 2:85734ad35573 3403 return true;
Gaetios 2:85734ad35573 3404 }
Gaetios 2:85734ad35573 3405 bool MPU60503::writeProgDMPConfigurationSet(const uint8_t *data, uint16_t dataSize)
Gaetios 2:85734ad35573 3406 {
Gaetios 2:85734ad35573 3407 return writeDMPConfigurationSet(data, dataSize, false);
Gaetios 2:85734ad35573 3408 }
Gaetios 2:85734ad35573 3409
Gaetios 2:85734ad35573 3410 // DMP_CFG_1 register
Gaetios 2:85734ad35573 3411
Gaetios 2:85734ad35573 3412 uint8_t MPU60503::getDMPConfig1()
Gaetios 2:85734ad35573 3413 {
Gaetios 2:85734ad35573 3414 i2Cdev.readByte(devAddr, MPU6050_RA_DMP_CFG_1, buffer);
Gaetios 2:85734ad35573 3415 return buffer[0];
Gaetios 2:85734ad35573 3416 }
Gaetios 2:85734ad35573 3417 void MPU60503::setDMPConfig1(uint8_t config)
Gaetios 2:85734ad35573 3418 {
Gaetios 2:85734ad35573 3419 i2Cdev.writeByte(devAddr, MPU6050_RA_DMP_CFG_1, config);
Gaetios 2:85734ad35573 3420 }
Gaetios 2:85734ad35573 3421
Gaetios 2:85734ad35573 3422 // DMP_CFG_2 register
Gaetios 2:85734ad35573 3423
Gaetios 2:85734ad35573 3424 uint8_t MPU60503::getDMPConfig2()
Gaetios 2:85734ad35573 3425 {
Gaetios 2:85734ad35573 3426 i2Cdev.readByte(devAddr, MPU6050_RA_DMP_CFG_2, buffer);
Gaetios 2:85734ad35573 3427 return buffer[0];
Gaetios 2:85734ad35573 3428 }
Gaetios 2:85734ad35573 3429 void MPU60503::setDMPConfig2(uint8_t config)
Gaetios 2:85734ad35573 3430 {
Gaetios 2:85734ad35573 3431 i2Cdev.writeByte(devAddr, MPU6050_RA_DMP_CFG_2, config);
Gaetios 2:85734ad35573 3432 }