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