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