Projet interfaçage

Dependencies:   mbed BSP_DISCO_F746NG

Committer:
anthonyp08
Date:
Tue Jun 22 12:04:16 2021 +0000
Revision:
1:eb044e6a9033
Parent:
0:1c6757f4b61c
projet

Who changed what in which revision?

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