うおーるぼっとLEDのワークショップ用

Dependencies:   mbed

Committer:
jksoft
Date:
Sat Feb 04 03:33:08 2017 +0000
Revision:
3:b707c09b4433
Parent:
0:9fcc79b3f00e
????

Who changed what in which revision?

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