Balancimg MPU6050 by LEDs on PWM

Dependencies:   mbed

It is possible to observe the MPU6050 data on serial. If serial termimal is not started then still LED application runs.

There are 4 LEDs on LPC1768. So the first 3 LEDs are assign to accelerometer X, Y and Z. The last LED can drive by user. Default it lights a bit. If you want to turn it off then change the value as "190" to "180" on this line: myled4 = cos(190*2.0*3.13/360) * 0.5 + 0.5; If you want to turn it on (full) then change the value as "190" to "0" on above code line.

Committer:
LORDTEK
Date:
Sun Oct 13 12:01:33 2013 +0000
Revision:
0:9a1aae56ed19
Balancing MPU6050 by LEDs

Who changed what in which revision?

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