锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

jrowberg-i2cdevlib-MPU6050库之mpu6050.cpp

时间:2022-11-20 22:30:00 rm7a传感器

index

  • 相关文件
  • mpu6050.cpp

https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050

相关文件

  1. mpu6050.h:
  2. mpu6050.cpp
  3. 示例MPU6050_dmp6.ino

mpu6050.cpp

/* I2Cdev library collection - MPU6050 I2C device class  Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)  8/24/2011 by Jeff Rowberg   Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib   Changelog:   2019-07-08 - Added Auto Calibration routine      ... - ongoing debug release   NOTE: THIS IS ONLY A PARIAL RELEASE. THIS DEVICE CLASS IS CURRENTLY UNDERGOING ACTIVE  DEVELOPMENT AND IS STILL MISSING SOME IMPORTANT FEATURES. PLEASE KEEP THIS IN MIND IF  YOU DECIDE TO USE THIS PARTICULAR CODE FOR ANYTHING. */ /* I2Cdev库集合-MPU6050 I2C设备类   基于InvenSense MPU-6050注册映射文件修订版。 2.0、2011年5月19日(RM-MPU-6000A-00)   2011年8月24日,Jeff Rowberg    更新(希望)应该始终如一https://github.com/jrowberg/i2cdevlib上可用    变更日志:    2019-07-08-添加自动校准例程       ...-正在进行的调试版本    注:这只是部分发布。 目前,该设备类别正在积极开发,仍缺乏一些重要功能。 目前,该设备类别正在积极开发,仍缺乏一些重要功能。 如果您决定将此特殊代码用于任何用途,请记住此。 */ #include "MPU6050.h"  /** Specific address constructor.  * @param address I2C address, uses default I2C address if none is specified  * @see MPU6050_DEFAULT_ADDRESS  * @see MPU6050_ADDRESS_AD0_LOW  * @see MPU6050_ADDRESS_AD0_HIGH  */ MPU6050::MPU6050(uint8_t address):devAddr(address) { }  /** Power on and prepare for general usage.  * This will activate the device and take it out of sleep mode (which must be done after start-up).   * This function also sets both the accelerometer and the gyroscope to their most sensitive settings,   namely  /- 2g and  /- 250 degrees/sec, and setsthe clock source to use the X Gyro for reference,  which is slightly better than the default internal clock source.  */ /**启动并准备一般使用。   *激活设备并退出睡眠模式(必须在启动后完成)。   *激活设备并退出睡眠模式(必须在启动后完成)。   *该功能还将加速度计和陀螺仪设置为最敏感的设置,即 /- 2g和 /- 250度/秒,以X陀螺仪为参考设置时钟源,略好于默认设置 内部时钟源。   */  void MPU6050::initialize() {     setClockSource(MPU6050_CLOCK_PLL_XGYRO);     setFullScaleGyroRange(MPU6050_GYRO_FS_250);     setFullScaleAccelRange(MPU6050_ACCEL_FS_2);     setSleepEnabled(false); // thanks to Jack Elston for pointing this one out! }  /** Verify the I2C connection.  * Make sure the device is connected and responds as expected.  * @return True if connection is valid, false otherwise  */ bool MPU6050::testConnection() {     return getDeviceID() == 0x34; }  // AUX_VDDIO register (InvenSense demo code calls this RA_*G_OFFS_TC)  /** Get the auxiliary I2C supply voltage level.  * When set to 1, the auxiliary I2C bus high logic level is VDD. When cleared to  0, the auxiliary I2C bus high logic level is VLOGIC. This does not apply to the MPU-6000, which does not have a VLOGIC pin.  * @return I2C supply voltage level (0=VLOGIC, 1=VDD)  */ /* 获取辅助I2C电源电压电平。   *设置为1时,辅助I2C总线高逻辑电平为VDD。   *设置为1时,辅助I2C总线高逻辑电平为VDD。 清零时,辅助I2C总线高逻辑电平为VLOGIC。 不适用于没有VLOGIC引脚的MPU-6000。 */ uint8_t MPU6050::getAuxVDDIOLevel() {     I2Cdev::readBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, buffer);     return buffer[0]; } /** Set the auxiliary I2C supply voltage level.  * When set to 1, the auxiliary I2C bus high logic level is VDD. When cleared to   * 0, the auxiliary I2C bus high logic level is VLOGIC. This does not apply to  * the MPU-6000, which does not have a VLOGIC pin.  * @param level I2C supply voltage level (0=VLOGIC, 1=VDD)  */ / **获取辅助I2C电源电压电平。   *设置为1时,辅助I2C总线高逻辑电平为VDD。   *设置为1时,辅助I2C总线高逻辑电平为VDD。 清零时,辅助I2C总线高逻辑电平为VLOGIC。 不适用于没有VLOGIC引脚的MPU-6000。   * @返回I2C电压电平(0 = VLOGIC,1 = VDD)   * / void MPU6050::setAuxVDDIOLevel(uint8_t level) {     I2Cdev::writeBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, level); }  // SMPLRT_DIV register  /** Get gyroscope output rate divider.  * The sensor register output, FIFO output, DMP sampling, Motion detection, Zero  Motion detection, and Free Fall detection are all based on the Sample Rate.  * The Sample Rate is generated by dividing the gyroscope output rate by  SMPLRT_DIV:  *  * Sample Rate = Gyroscope Output Rate / (1   SMPLRT_DIV)  *  * where Gyroscope Output Rate = 8kHz when the DLPF is disabled (DLPF_CFG = 0 or 7), and 1kHz when the DLPF is enabled (see Register 26).  *  * Note: The accelerometer output rate is 1kHz. This means that for a Sample Rate greater than 1kHz, the same accelerometer sample may be output to the FIFO, DMP, and sensor registers more than once.  *  * For a diagram of the gyroscope and accelerometer signal paths, see Setion 8 of the MPU-6000/MPU-6050 Product Specification document.
 *
 * @return Current sample rate
 * @see MPU6050_RA_SMPLRT_DIV
 */
// SMPLRT_DIV寄存器

/ **获取陀螺仪输出速率分配器。
  *传感器寄存器输出,FIFO输出,DMP采样,运动检测,零运动检测和自由落体检测均基于采样率。
  *采样率是通过将陀螺仪的输出率除以SMPLRT_DIV生成的:
  *
  *采样率=陀螺仪输出率/(1 + SMPLRT_DIV)
  *
  *其中,当禁用DLPF时,陀螺仪输出速率= 8kHz(DLPF_CFG = 0或7),而当启用DLPF时,陀螺仪输出速率= 1kHz(见寄存器26)。
  *
  *注意:加速度计的输出速率为1kHz。 这意味着对于大于1kHz的采样率,相同的加速度计采样可能会多次输出到FIFO,DMP和传感器寄存器。
  *
  *有关陀螺仪和加速度计信号路径的图,请参阅MPU-6000 / MPU-6050产品规格文档的第8节。
  *
  * @返回当前采样率
  * @请参阅MPU6050_RA_SMPLRT_DIV
  * /
uint8_t MPU6050::getRate() {
    I2Cdev::readByte(devAddr, MPU6050_RA_SMPLRT_DIV, buffer);
    return buffer[0];
}
/** Set gyroscope sample rate divider.
 * @param rate New sample rate divider
 * @see getRate()
 * @see MPU6050_RA_SMPLRT_DIV
 */
void MPU6050::setRate(uint8_t rate) {
    I2Cdev::writeByte(devAddr, MPU6050_RA_SMPLRT_DIV, rate);
}

// CONFIG register

/** Get external FSYNC configuration.
 * Configures the external Frame Synchronization (FSYNC) pin sampling. An external signal connected to the FSYNC pin can be sampled by configuring EXT_SYNC_SET. 
 * Signal changes to the FSYNC pin are latched so that short strobes may be captured. The latched FSYNC signal will be sampled at the Sampling Rate, as defined in register 25. 
 * After sampling, the latch will reset to the current FSYNC signal state.
 *
 * The sampled value will be reported in place of the least significant bit in a sensor data register determined by the value of EXT_SYNC_SET according to the following table.
 *
 * 
 * EXT_SYNC_SET | FSYNC Bit Location
 * -------------+-------------------
 * 0            | Input disabled
 * 1            | TEMP_OUT_L[0]
 * 2            | GYRO_XOUT_L[0]
 * 3            | GYRO_YOUT_L[0]
 * 4            | GYRO_ZOUT_L[0]
 * 5            | ACCEL_XOUT_L[0]
 * 6            | ACCEL_YOUT_L[0]
 * 7            | ACCEL_ZOUT_L[0]
 * 
* * @return FSYNC configuration value */ /* 获取外部FSYNC配置。 *配置外部帧同步(FSYNC)引脚采样。 通过配置EXT_SYNC_SET,可以采样连接到FSYNC引脚的外部信号。 * FSYNC引脚的信号变化被存,以便可以捕获短选通脉冲。 锁存的FSYNC信号将按照寄存器25中定义的采样率进行采样。 *采样后,锁存器将重置为当前的FSYNC信号状态。 * *根据下表,将报告采样值,而不是由EXT_SYNC_SET值确定的传感器数据寄存器中的最低有效位。 */ uint8_t MPU6050::getExternalFrameSync() { I2Cdev::readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, buffer); return buffer[0]; } /** Set external FSYNC configuration. * @see getExternalFrameSync() * @see MPU6050_RA_CONFIG * @param sync New FSYNC configuration value */ void MPU6050::setExternalFrameSync(uint8_t sync) { I2Cdev::writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, sync); } /** Get digital low-pass filter configuration. * The DLPF_CFG parameter sets the digital low pass filter configuration. * It also determines the internal sampling rate used by the device as shown in the table below. * * Note: The accelerometer output rate is 1kHz. This means that for a Sample Rate greater than 1kHz, the same accelerometer sample may be output to the FIFO, DMP, and sensor registers more than once. * *
 *          |   ACCELEROMETER    |           GYROSCOPE
 * DLPF_CFG | Bandwidth | Delay  | Bandwidth | Delay  | Sample Rate
 * ---------+-----------+--------+-----------+--------+-------------
 * 0        | 260Hz     | 0ms    | 256Hz     | 0.98ms | 8kHz
 * 1        | 184Hz     | 2.0ms  | 188Hz     | 1.9ms  | 1kHz
 * 2        | 94Hz      | 3.0ms  | 98Hz      | 2.8ms  | 1kHz
 * 3        | 44Hz      | 4.9ms  | 42Hz      | 4.8ms  | 1kHz
 * 4        | 21Hz      | 8.5ms  | 20Hz      | 8.3ms  | 1kHz
 * 5        | 10Hz      | 13.8ms | 10Hz      | 13.4ms | 1kHz
 * 6        | 5Hz       | 19.0ms | 5Hz       | 18.6ms | 1kHz
 * 7        |   -- Reserved --   |   -- Reserved --   | Reserved
 * 
* * @return DLFP configuration * @see MPU6050_RA_CONFIG * @see MPU6050_CFG_DLPF_CFG_BIT * @see MPU6050_CFG_DLPF_CFG_LENGTH */ /* 获取数字低通滤波器配置。 * DLPF_CFG参数设置数字低通滤波器配置。 *还可确定设备使用的内部采样率,如下表所示。 * *注意:加速度计的输出速率为1kHz。 这意味着对于大于1kHz的采样率,相同的加速度计采样可能会多次输出到FIFO,DMP和传感器寄存器。 */ uint8_t MPU6050::getDLPFMode() { I2Cdev::readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, buffer); return buffer[0]; } /** Set digital low-pass filter configuration. * @param mode New DLFP configuration setting * @see getDLPFBandwidth() * @see MPU6050_DLPF_BW_256 * @see MPU6050_RA_CONFIG * @see MPU6050_CFG_DLPF_CFG_BIT * @see MPU6050_CFG_DLPF_CFG_LENGTH */ void MPU6050::setDLPFMode(uint8_t mode) { I2Cdev::writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, mode); } // GYRO_CONFIG register /** Get full-scale gyroscope range. * The FS_SEL parameter allows setting the full-scale range of the gyro sensors, as described in the table below. * *
 * 0 = +/- 250 degrees/sec
 * 1 = +/- 500 degrees/sec
 * 2 = +/- 1000 degrees/sec
 * 3 = +/- 2000 degrees/sec
 * 
* * @return Current full-scale gyroscope range setting * @see MPU6050_GYRO_FS_250 * @see MPU6050_RA_GYRO_CONFIG * @see MPU6050_GCONFIG_FS_SEL_BIT * @see MPU6050_GCONFIG_FS_SEL_LENGTH */ /* 获取完整的陀螺仪范围。 * FS_SEL参数允许设置陀螺仪传感器的满量程范围,如下表所述。 */ uint8_t MPU6050::getFullScaleGyroRange() { I2Cdev::readBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, buffer); return buffer[0]; } /** Set full-scale gyroscope range. * @param range New full-scale gyroscope range value * @see getFullScaleRange() * @see MPU6050_GYRO_FS_250 * @see MPU6050_RA_GYRO_CONFIG * @see MPU6050_GCONFIG_FS_SEL_BIT * @see MPU6050_GCONFIG_FS_SEL_LENGTH */ void MPU6050::setFullScaleGyroRange(uint8_t range) { I2Cdev::writeBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, range); } // SELF TEST FACTORY TRIM VALUES /** Get self-test factory trim value for accelerometer X axis. * @return factory trim value * @see MPU6050_RA_SELF_TEST_X */ uint8_t MPU6050::getAccelXSelfTestFactoryTrim() { I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_X, &buffer[0]); I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_A, &buffer[1]); return (buffer[0]>>3) | ((buffer[1]>>4) & 0x03); } /** Get self-test factory trim value for accelerometer Y axis. * @return factory trim value * @see MPU6050_RA_SELF_TEST_Y */ uint8_t MPU6050::getAccelYSelfTestFactoryTrim() { I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_Y, &buffer[0]); I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_A, &buffer[1]); return (buffer[0]>>3) | ((buffer[1]>>2) & 0x03); } /** Get self-test factory trim value for accelerometer Z axis. * @return factory trim value * @see MPU6050_RA_SELF_TEST_Z */ uint8_t MPU6050::getAccelZSelfTestFactoryTrim() { I2Cdev::readBytes(devAddr, MPU6050_RA_SELF_TEST_Z, 2, buffer); return (buffer[0]>>3) | (buffer[1] & 0x03); } /** Get self-test factory trim value for gyro X axis. * @return factory trim value * @see MPU6050_RA_SELF_TEST_X */ uint8_t MPU6050::getGyroXSelfTestFactoryTrim() { I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_X, buffer); return (buffer[0] & 0x1F); } /** Get self-test factory trim value for gyro Y axis. * @return factory trim value * @see MPU6050_RA_SELF_TEST_Y */ uint8_t MPU6050::getGyroYSelfTestFactoryTrim() { I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_Y, buffer); return (buffer[0] & 0x1F); } /** Get self-test factory trim value for gyro Z axis. * @return factory trim value * @see MPU6050_RA_SELF_TEST_Z */ uint8_t MPU6050::getGyroZSelfTestFactoryTrim() { I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_Z, buffer); return (buffer[0] & 0x1F); } // ACCEL_CONFIG register /** Get self-test enabled setting for accelerometer X axis. * @return Self-test enabled value * @see MPU6050_RA_ACCEL_CONFIG */ bool MPU6050::getAccelXSelfTest() { I2Cdev::readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, buffer); return buffer[0]; } /** Get self-test enabled setting for accelerometer X axis. * @param enabled Self-test enabled value * @see MPU6050_RA_ACCEL_CONFIG */ void MPU6050::setAccelXSelfTest(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, enabled); } /** Get self-test enabled value for accelerometer Y axis. * @return Self-test enabled value * @see MPU6050_RA_ACCEL_CONFIG */ bool MPU6050::getAccelYSelfTest() { I2Cdev::readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, buffer); return buffer[0]; } /** Get self-test enabled value for accelerometer Y axis. * @param enabled Self-test enabled value * @see MPU6050_RA_ACCEL_CONFIG */ void MPU6050::setAccelYSelfTest(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, enabled); } /** Get self-test enabled value for accelerometer Z axis. * @return Self-test enabled value * @see MPU6050_RA_ACCEL_CONFIG */ bool MPU6050::getAccelZSelfTest() { I2Cdev::readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, buffer); return buffer[0]; } /** Set self-test enabled value for accelerometer Z axis. * @param enabled Self-test enabled value * @see MPU6050_RA_ACCEL_CONFIG */ void MPU6050::setAccelZSelfTest(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, enabled); } /** Get full-scale accelerometer range. * The FS_SEL parameter allows setting the full-scale range of the accelerometer sensors, as described in the table below. * *
 * 0 = +/- 2g
 * 1 = +/- 4g
 * 2 = +/- 8g
 * 3 = +/- 16g
 * 
* * @return Current full-scale accelerometer range setting * @see MPU6050_ACCEL_FS_2 * @see MPU6050_RA_ACCEL_CONFIG * @see MPU6050_ACONFIG_AFS_SEL_BIT * @see MPU6050_ACONFIG_AFS_SEL_LENGTH */ /* 获取完整的加速度计范围。 * FS_SEL参数允许设置加速度传感器的满量程范围,如下表所述。 */ uint8_t MPU6050::getFullScaleAccelRange() { I2Cdev::readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, buffer); return buffer[0]; } /** Set full-scale accelerometer range. * @param range New full-scale accelerometer range setting * @see getFullScaleAccelRange() */ void MPU6050::setFullScaleAccelRange(uint8_t range) { I2Cdev::writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, range); } /** Get the high-pass filter configuration. * The DHPF is a filter module in the path leading to motion detectors (Free Fall, Motion threshold, and Zero Motion). * The high pass filter output is not available to the data registers (see Figure in Section 8 of the MPU-6000/ MPU-6050 Product Specification document). * * The high pass filter has three modes: * *
 *    Reset: The filter output settles to zero within one sample. 
 *          This effectively disables the high pass filter. 
 *          This mode may be toggled to quickly settle the filter.
 *
 *    On:    The high pass filter will pass signals above the cut off frequency.
 *
 *    Hold:  When triggered, the filter holds the present sample. 
 *           The filter output will be the difference between the input sample and the held sample.
 * 
* *
 * ACCEL_HPF | Filter Mode | Cut-off Frequency
 * ----------+-------------+------------------
 * 0         | Reset       | None
 * 1         | On          | 5Hz
 * 2         | On          | 2.5Hz
 * 3         | On          | 1.25Hz
 * 4         | On          | 0.63Hz
 * 7         | Hold        | None
 * 
* * @return Current high-pass filter configuration * @see MPU6050_DHPF_RESET * @see MPU6050_RA_ACCEL_CONFIG */ /* 获取高通滤波器配置。 * DHPF是通向运动检测器(自由落体,运动阈值和零运动)的路径中的过滤器模块。 *高通滤波器输出不适用于数据寄存器(请参见MPU-6000 / MPU-6050产品规格文档第8节中的图)。 * *高通滤波器具有三种模式: * *复位:滤波器输出在一个样本内稳定为零。 *这将有效禁用高通滤波器。 *可以切换此模式以快速建立过滤条件。 * *开:高通滤波器将使高于截止频率的信号通过。 * *保留:触发后,过滤器将保留当前样本。 *滤波器输出将是输入样本和保留样本之间的差。 */ uint8_t MPU6050::getDHPFMode() { I2Cdev::readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, buffer); return buffer[0]; } /** Set the high-pass filter configuration. * @param bandwidth New high-pass filter configuration * @see setDHPFMode() * @see MPU6050_DHPF_RESET * @see MPU6050_RA_ACCEL_CONFIG */ void MPU6050::setDHPFMode(uint8_t bandwidth) { I2Cdev::writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, bandwidth); } // FF_THR register /** Get free-fall event acceleration threshold. * This register configures the detection threshold for Free Fall event detection. * The unit of FF_THR is 1LSB = 2mg. * Free Fall is detected when the absolute value of the accelerometer measurements for the three axes are each less than the detection threshold. * This condition increments the Free Fall duration counter (Register 30). * The Free Fall interrupt is triggered when the Free Fall duration counter reaches the time specified in FF_DUR. * * For more details on the Free Fall detection interrupt, see Section 8.2 of the MPU-6000/MPU-6050 Product Specification document as well as Registers 56 and 58 of this document. * * @return Current free-fall acceleration threshold value (LSB = 2mg) * @see MPU6050_RA_FF_THR */ /* 获取自由落体事件加速阈值。 *该寄存器为自由落体事件检测配置检测阈值。 * FF_THR的单位为1LSB = 2mg。 *当三个轴的加速度计测量值的绝对值分别小于检测阈值时,将检测到自由落体。 *此条件使自由落体持续时间计数器(寄存器30)递增。 *自由落体持续时间计数器达到FF_DUR中指定的时间时,将触发自由落体中断。 * *有关自由落体检测中断的更多详细信息,请参见MPU-6000 / MPU-6050产品规范文档的8.2节以及该文档的寄存器56和58。 */ uint8_t MPU6050::getFreefallDetectionThreshold() { I2Cdev::readByte(devAddr, MPU6050_RA_FF_THR, buffer); return buffer[0]; } /** Get free-fall event acceleration threshold. * @param threshold New free-fall acceleration threshold value (LSB = 2mg) * @see getFreefallDetectionThreshold() * @see MPU6050_RA_FF_THR */ void MPU6050::setFreefallDetectionThreshold(uint8_t threshold) { I2Cdev::writeByte(devAddr, MPU6050_RA_FF_THR, threshold); } // FF_DUR register /** Get free-fall event duration threshold. * This register configures the duration counter threshold for Free Fall event detection. * The duration counter ticks at 1kHz, therefore FF_DUR has a unit of 1 LSB = 1 ms. * * The Free Fall duration counter increments while the absolute value of the accelerometer measurements are each less than the detection threshold (Register 29). * The Free Fall interrupt is triggered when the Free Fall duration counter reaches the time specified in this register. * * For more details on the Free Fall detection interrupt, see Section 8.2 of the MPU-6000/MPU-6050 Product Specification document as well as Registers 56 and 58 of this document. * * @return Current free-fall duration threshold value (LSB = 1ms) * @see MPU6050_RA_FF_DUR */ /* 获取自由落体事件持续时间阈值。 *该寄存器为自由落体事件检测配置持续时间计数器阈值。 *持续时间计数器在1kHz处滴答,因此FF_DUR的单位为1 LSB = 1 ms。 * *自由落差持续时间计数器递增,而加速度计测量值的绝对值分别小于检测阈值(寄存器29)。 *当自由落体持续时间计数器达到该寄存器中指定的时间时,将触发自由落体中断。 * *有关自由落体检测中断的更多详细信息,请参见MPU-6000 / MPU-6050产品规范文档的8.2节以及该文档的寄存器56和58。 */ uint8_t MPU6050::getFreefallDetectionDuration() { I2Cdev::readByte(devAddr, MPU6050_RA_FF_DUR, buffer); return buffer[0]; } /** Get free-fall event duration threshold. * @param duration New free-fall duration threshold value (LSB = 1ms) * @see getFreefallDetectionDuration() * @see MPU6050_RA_FF_DUR */ void MPU6050::setFreefallDetectionDuration(uint8_t duration) { I2Cdev::writeByte(devAddr, MPU6050_RA_FF_DUR, duration); } // MOT_THR register /** Get motion detection event acceleration threshold. * This register configures the detection threshold for Motion interrupt generation. The unit of MOT_THR is 1LSB = 2mg. * Motion is detected when the absolute value of any of the accelerometer measurements exceeds this Motion detection threshold. * This condition increments the Motion detection duration counter (Register 32). * The Motion detection interrupt is triggered when the Motion Detection counter reaches the time count specified in MOT_DUR (Register 32). * * The Motion interrupt will indicate the axis and polarity of detected motion in MOT_DETECT_STATUS (Register 97). * * For more details on the Motion detection interrupt, see Section 8.3 of the MPU-6000/MPU-6050 Product Specification document as well as Registers 56 and 58 of this document. * * @return Current motion detection acceleration threshold value (LSB = 2mg) * @see MPU6050_RA_MOT_THR */ /* MOT_THR寄存器 / **获取运动检测事件加速阈值。 *该寄存器配置运动中断产生的检测阈值。 MOT_THR的单位为1LSB = 2mg。 *当任何加速度计测量值的绝对值超过此运动检测阈值时,都会检测到运动。 *此条件将增加运动检测持续时间计数器(寄存器32)。 *当运动检测计数器达到MOT_DUR(寄存器32)中指定的时间计数时,将触发运动检测中断。 * *运动中断将在MOT_DETECT_STATUS(寄存器97)中指示检测到的运动的轴和极性。 * *有关运动检测中断的更多详细信息,请参见MPU-6000 / MPU-6050产品规范文档的8.3节以及该文档的寄存器56和58。 */ uint8_t MPU6050::getMotionDetectionThreshold() { I2Cdev::readByte(devAddr, MPU6050_RA_MOT_THR, buffer); return buffer[0]; } /** Set motion detection event acceleration threshold. * @param threshold New motion detection acceleration threshold value (LSB = 2mg) * @see getMotionDetectionThreshold() * @see MPU6050_RA_MOT_THR */ void MPU6050::setMotionDetectionThreshold(uint8_t threshold) { I2Cdev::writeByte(devAddr, MPU6050_RA_MOT_THR, threshold); } // MOT_DUR register /** Get motion detection event duration threshold. * This register configures the duration counter threshold for Motion interrupt generation. * The duration counter ticks at 1 kHz, therefore MOT_DUR has a unit of 1LSB = 1ms. * The Motion detection duration counter increments when the absolute value of any of the accelerometer measurements exceeds the Motion detection threshold (Register 31). * The Motion detection interrupt is triggered when the Motion detection counter reaches the time count specified in this register. * * For more details on the Motion detection interrupt, see Section 8.3 of the MPU-6000/MPU-6050 Product Specification document. * * @return Current motion detection duration threshold value (LSB = 1ms) * @see MPU6050_RA_MOT_DUR */ /* 获取运动检测事件持续时间阈值。 *该寄存器配置用于产生运动中断的持续时间计数器阈值。 *持续时间计数器在1 kHz处滴答,因此MOT_DUR的单位为1LSB = 1ms。 *当任何加速度计测量值的绝对值超过运动检测阈值(寄存器31)时,运动检测持续时间计数器就会增加。 *当运动检测计数器达到该寄存器中指定的时间计数时,将触发运动检测中断。 * *有关运动检测中断的更多详细信息,请参见MPU-6000 / MPU-6050产品规格文档的8.3节。 */ uint8_t MPU6050::getMotionDetectionDuration() { I2Cdev::readByte(devAddr, MPU6050_RA_MOT_DUR, buffer); return buffer[0]; } /** Set motion detection event duration threshold. * @param duration New motion detection duration threshold value (LSB = 1ms) * @see getMotionDetectionDuration() * @see MPU6050_RA_MOT_DUR */ void MPU6050::setMotionDetectionDuration(uint8_t duration) { I2Cdev::writeByte(devAddr, MPU6050_RA_MOT_DUR, duration); } // ZRMOT_THR register /** Get zero motion detection event acceleration threshold. * This register configures the detection threshold for Zero Motion interrupt generation. * The unit of ZRMOT_THR is 1LSB = 2mg. Zero Motion is detected when the absolute value of the accelerometer measurements for the 3 axes are each less than the detection threshold. * This condition increments the Zero Motion duration counter (Register 34). * The Zero Motion interrupt is triggered when the Zero Motion duration counter reaches the time count specified in ZRMOT_DUR (Register 34). * * Unlike Free Fall or Motion detection, Zero Motion detection triggers an interrupt both when Zero Motion is first detected and when Zero Motion is no longer detected. * * When a zero motion event is detected, a Zero Motion Status will be indicated in the MOT_DETECT_STATUS register (Register 97). * When a motion-to-zero-motion condition is detected, the status bit is set to 1. * When a zero-motion-to- motion condition is detected, the status bit is set to 0. * * For more details on the Zero Motion detection interrupt, see Section 8.4 of the MPU-6000/MPU-6050 Product Specification document as well as Registers 56 and 58 of this document. * * @return Current zero motion detection acceleration threshold value (LSB = 2mg) * @see MPU6050_RA_ZRMOT_THR */ /* 获取零运动检测事件加速阈值。 *该寄存器配置零运动中断产生的检测阈值。 * ZRMOT_THR的单位为1LSB = 2mg。当三个轴的加速度计测量值的绝对值分别小于检测阈值时,将检测到零运动。 *此条件使零运动持续时间计数器(寄存器34)递增。 *当零运动持续时间计数器达到ZRMOT_DUR(寄存器34)中指定的时间计数时,将触发零运动中断。 * *与自由落体或运动检测不同,零运动检测会在首次检测到零运动时和不再检测到零运动时均触发中断。 * *当检测到零运动事件时,将在MOT_DETECT_STATUS寄存器(寄存器97)中指示零运动状态。 *当检测到零运动状态时,状态位设置为1。 *当检测到零运动状态时,状态位设置为0。 * *有关零运动检测中断的更多详细信息,请参见MPU-6000 / MPU-6050产品规格文档的8.4节以及该文档的寄存器56和58。 */ uint8_t MPU6050::getZeroMotionDetectionThreshold() { I2Cdev::readByte(devAddr, MPU6050_RA_ZRMOT_THR, buffer); return buffer[0]; } /** Set zero motion detection event acceleration threshold. * @param threshold New zero motion detection acceleration threshold value (LSB = 2mg) * @see getZeroMotionDetectionThreshold() * @see MPU6050_RA_ZRMOT_THR */ void MPU6050::setZeroMotionDetectionThreshold(uint8_t threshold) { I2Cdev::writeByte(devAddr, MPU6050_RA_ZRMOT_THR, threshold); } // ZRMOT_DUR register /** Get zero motion detection event duration threshold. * This register configures the duration counter threshold for Zero Motion interrupt generation. * The duration counter ticks at 16 Hz, therefore ZRMOT_DUR has a unit of 1 LSB = 64 ms. * The Zero Motion duration counter increments while the absolute value of the accelerometer measurements are * each less than the detection threshold (Register 33). * The Zero Motion interrupt is triggered when the Zero Motion duration counter reaches the time count specified in this register. * * For more details on the Zero Motion detection interrupt, see Section 8.4 of the MPU-6000/MPU-6050 Product Specification document, as well as Registers 56 and 58 of this document. * * @return Current zero motion detection duration threshold value (LSB = 64ms) * @see MPU6050_RA_ZRMOT_DUR */ /* 获取零运动检测事件持续时间阈值。 *该寄存器配置持续时间计数器阈值以产生零运动中断。 *持续时间计数器在16 Hz处滴答,因此ZRMOT_DUR的单位为1 LSB = 64 ms。 *零运动持续时间计数器递增,而加速度计测量值的绝对值则分别小于检测阈值(寄存器33)。 *当零运动持续时间计数器达到该寄存器中指定的时间计数时,将触发零运动中断。 * *有关零运动检测中断的更多详细信息,请参见MPU-6000 / MPU-6050产品规格文档的8.4节,以及该文档的寄存器56和58。 */ uint8_t MPU6050::getZeroMotionDetectionDuration() { I2Cdev::readByte(devAddr, MPU6050_RA_ZRMOT_DUR, buffer); return buffer[0]; } /** Set zero motion detection event duration threshold. * @param duration New zero motion detection duration threshold value (LSB = 1ms) * @see getZeroMotionDetectionDuration() * @see MPU6050_RA_ZRMOT_DUR */ void MPU6050::setZeroMotionDetectionDuration(uint8_t duration) { I2Cdev::writeByte(devAddr, MPU6050_RA_ZRMOT_DUR, duration); } // FIFO_EN register /** Get temperature FIFO enabled value. * When set to 1, this bit enables TEMP_OUT_H and TEMP_OUT_L (Registers 65 and * 66) to be written into the FIFO buffer. * @return Current temperature FIFO enabled value * @see MPU6050_RA_FIFO_EN */ /* 当设置为1时,该位使能将TEMP_OUT_H和TEMP_OUT_L(寄存器65和66)写入FIFO缓冲器。 */ bool MPU6050::getTempFIFOEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set temperature FIFO enabled value. * @param enabled New temperature FIFO enabled value * @see getTempFIFOEnabled() * @see MPU6050_RA_FIFO_EN */ void MPU6050::setTempFIFOEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, enabled); } /** Get gyroscope X-axis FIFO enabled value. * When set to 1, this bit enables GYRO_XOUT_H and GYRO_XOUT_L (Registers 67 and 68) to be written into the FIFO buffer. * @return Current gyroscope X-axis FIFO enabled value * @see MPU6050_RA_FIFO_EN */ /* 获取陀螺仪X轴FIFO启用值。 *设置为1时,该位使GYRO_XOUT_H和GYRO_XOUT_L(寄存器67和68)被写入FIFO缓冲区。 */ bool MPU6050::getXGyroFIFOEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set gyroscope X-axis FIFO enabled value. * @param enabled New gyroscope X-axis FIFO enabled value * @see getXGyroFIFOEnabled() * @see MPU6050_RA_FIFO_EN */ void MPU6050::setXGyroFIFOEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, enabled); } /** Get gyroscope Y-axis FIFO enabled value. * When set to 1, this bit enables GYRO_YOUT_H and GYRO_YOUT_L (Registers 69 and 70) to be written into the FIFO buffer. * @return Current gyroscope Y-axis FIFO enabled value * @see MPU6050_RA_FIFO_EN */ /* 获取陀螺仪Y轴FIFO启用值。 *设置为1时,此位使能GYRO_YOUT_H和GYRO_YOUT_L(寄存器69和70)写入FIFO缓冲区。 */ bool MPU6050::getYGyroFIFOEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set gyroscope Y-axis FIFO enabled value. * @param enabled New gyroscope Y-axis FIFO enabled value * @see getYGyroFIFOEnabled() * @see MPU6050_RA_FIFO_EN */ void MPU6050::setYGyroFIFOEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, enabled); } /** Get gyroscope Z-axis FIFO enabled value. * When set to 1, this bit enables GYRO_ZOUT_H and GYRO_ZOUT_L (Registers 71 and 72) to be written into the FIFO buffer. * @return Current gyroscope Z-axis FIFO enabled value * @see MPU6050_RA_FIFO_EN */ /* 获取陀螺仪Z轴FIFO启用值。 *设置为1时,该位使能GYRO_ZOUT_H和GYRO_ZOUT_L(寄存器71和72)写入FIFO缓冲区。 */ bool MPU6050::getZGyroFIFOEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set gyroscope Z-axis FIFO enabled value. * @param enabled New gyroscope Z-axis FIFO enabled value * @see getZGyroFIFOEnabled() * @see MPU6050_RA_FIFO_EN */ void MPU6050::setZGyroFIFOEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, enabled); } /** Get accelerometer FIFO enabled value. * When set to 1, this bit enables ACCEL_XOUT_H, ACCEL_XOUT_L, ACCEL_YOUT_H, ACCEL_YOUT_L, ACCEL_ZOUT_H, and ACCEL_ZOUT_L (Registers 59 to 64) to be written into the FIFO buffer. * @return Current accelerometer FIFO enabled value * @see MPU6050_RA_FIFO_EN */ /* */ bool MPU6050::getAccelFIFOEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set accelerometer FIFO enabled value. * @param enabled New accelerometer FIFO enabled value * @see getAccelFIFOEnabled() * @see MPU6050_RA_FIFO_EN */ void MPU6050::setAccelFIFOEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, enabled); } /** Get Slave 2 FIFO enabled value. * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96) associated with Slave 2 to be written into the FIFO buffer. * @return Current Slave 2 FIFO enabled value * @see MPU6050_RA_FIFO_EN */ /* 当设置为1时,该位使与从机2相关的EXT_SENS_DATA寄存器(寄存器73至96)被写入FIFO缓冲器。 */ bool MPU6050::getSlave2FIFOEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set Slave 2 FIFO enabled value. * @param enabled New Slave 2 FIFO enabled value * @see getSlave2FIFOEnabled() * @see MPU6050_RA_FIFO_EN */ void MPU6050::setSlave2FIFOEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, enabled); } /** Get Slave 1 FIFO enabled value. * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96) associated with Slave 1 to be written into the FIFO buffer. * @return Current Slave 1 FIFO enabled value * @see MPU6050_RA_FIFO_EN */ /* 获取从机1 FIFO使能值。 *设置为1时,该位使与从机1相关的EXT_SENS_DATA寄存器(寄存器73至96)写入FIFO缓冲区。 */ bool MPU6050::getSlave1FIFOEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set Slave 1 FIFO enabled value. * @param enabled New Slave 1 FIFO enabled value * @see getSlave1FIFOEnabled() * @see MPU6050_RA_FIFO_EN */ void MPU6050::setSlave1FIFOEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, enabled); } /** Get Slave 0 FIFO enabled value. * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96) associated with Slave 0 to be written into the FIFO buffer. * @return Current Slave 0 FIFO enabled value * @see MPU6050_RA_FIFO_EN */ /* 获取从机0 FIFO使能值。 *设置为1时,该位使与从站0相关的EXT_SENS_DATA寄存器(寄存器73至96)写入FIFO缓冲区。 */ bool MPU6050::getSlave0FIFOEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set Slave 0 FIFO enabled value. * @param enabled New Slave 0 FIFO enabled value * @see getSlave0FIFOEnabled() * @see MPU6050_RA_FIFO_EN */ void MPU6050::setSlave0FIFOEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, enabled); } // I2C_MST_CTRL register /** Get multi-master enabled value. * Multi-master capability allows multiple I2C masters to operate on the same bus. * In circuits where multi-master capability is required, set MULT_MST_EN to 1. * This will increase current drawn by approximately 30uA. * * In circuits where multi-master capability is required, the state of the I2C bus must always be monitored by each separate I2C Master. * Before an I2C Master can assume arbitration of the bus, it must first confirm that no other I2C Master has arbitration of the bus. * When MULT_MST_EN is set to 1, the MPU-60X0's bus arbitration detection logic is turned on, enabling it to detect when the bus is available. * * @return Current multi-master enabled value * @see MPU6050_RA_I2C_MST_CTRL */ /* 获取多主机启用值。 *多主设备功能允许多个I2C主设备在同一总线上运行。 *在需要多主机功能的电路中,将MULT_MST_EN设置为1。 *这将使汲取的电流增加约30uA。 * *在需要多主设备功能的电路中,必须始终由每个单独的I2C主设备监视I2C总线的状态。 *在I2C主设备可以承担总线仲裁之前,它必须首先确认没有其他I2C主设备对总线进行仲裁。 *当MULT_MST_EN设置为1时,MPU-60X0的总线仲裁检测逻辑被打开,从而使其能够检测总线何时可用。 */ bool MPU6050::getMultiMasterEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, buffer); return buffer[0]; } /** Set multi-master enabled value. * @param enabled New multi-master enabled value * @see getMultiMasterEnabled() * @see MPU6050_RA_I2C_MST_CTRL */ void MPU6050::setMultiMasterEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, enabled); } /** Get wait-for-external-sensor-data enabled value. * When the WAIT_FOR_ES bit is set to 1, the Data Ready interrupt will be delayed until External Sensor data from the Slave Devices are loaded into the EXT_SENS_DATA registers. * This is used to ensure that both the internal sensor data (i.e. from gyro and accel) and external sensor data have been loaded to their respective data registers (i.e. the data is synced) when the Data Ready interrupt is triggered. * * @return Current wait-for-external-sensor-data enabled value * @see MPU6050_RA_I2C_MST_CTRL */ /* 获取启用外部传感器数据的值。 *当WAIT_FOR_ES位设置为1时,数据就绪中断将延迟,直到从设备中的外部传感器数据加载到EXT_SENS_DATA寄存器中为止。 *这用于确保在触发数据就绪中断时,内部传感器数据(即来自陀螺仪和加速器的传感器)和外部传感器数据均已加载到各自的数据寄存器中(即数据已同步)。 */ bool MPU6050::getWaitForExternalSensorEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, buffer); return buffer[0]; } /** Set wait-for-external-sensor-data enabled value. * @param enabled New wait-for-external-sensor-data enabled value * @see getWaitForExternalSensorEnabled() * @see MPU6050_RA_I2C_MST_CTRL */ void MPU6050::setWaitForExternalSensorEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, enabled); } /** Get Slave 3 FIFO enabled value. * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96) associated with Slave 3 to be written into the FIFO buffer. * @return Current Slave 3 FIFO enabled value * @see MPU6050_RA_MST_CTRL */ bool MPU6050::getSlave3FIFOEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set Slave 3 FIFO enabled value. * @param enabled New Slave 3 FIFO enabled value * @see getSlave3FIFOEnabled() * @see MPU6050_RA_MST_CTRL */ void MPU6050::setSlave3FIFOEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, enabled); } /** Get slave read/write transition enabled value. * The I2C_MST_P_NSR bit configures the I2C Master's transition from one slave read to the next slave read. * If the bit equals 0, there will be a restart between reads. * If the bit equals 1, there will be a stop followed by a start of the following read. * When a write transaction follows a read transaction, the stop followed by a start of the successive write will be always used. * * @return Current slave read/write transition enabled value * @see MPU6050_RA_I2C_MST_CTRL */ /* 获取从站读/写转换启用值。 * I2C_MST_P_NSR位配置I2C主机从一个从设备读取到下一个从设备读取的转换。 *如果该位等于0,则读取之间将重新启动。 *如果该位等于1,将停止并随后开始以下读取。 *当写事务紧跟读事务之后,将始终使用停止,然后开始连续写操作。 */ bool MPU6050::getSlaveReadWriteTransitionEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, buffer); return buffer[0]; } /** Set slave read/write transition enabled value. * @param enabled New slave read/write transition enabled value * @see getSlaveReadWriteTransitionEnabled() * @see MPU6050_RA_I2C_MST_CTRL */ void MPU6050::setSlaveReadWriteTransitionEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, enabled); } /** Get I2C master clock speed. * I2C_MST_CLK is a 4 bit unsigned value which configures a divider on the MPU-60X0 internal 8MHz clock. * It sets the I2C master clock speed according to the following table: * *
 * I2C_MST_CLK | I2C Master Clock Speed | 8MHz Clock Divider
 * ------------+------------------------+-------------------
 * 0           | 348kHz                 | 23
 * 1           | 333kHz                 | 24
 * 2           | 320kHz                 | 25
 * 3           | 308kHz                 | 26
 * 4           | 296kHz                 | 27
 * 5           | 286kHz                 | 28
 * 6           | 276kHz                 | 29
 * 7           | 267kHz                 | 30
 * 8           | 258kHz                 | 31
 * 9           | 500kHz                 | 16
 * 10          | 471kHz                 | 17
 * 11          | 444kHz                 | 18
 * 12          | 421kHz                 | 19
 * 13          | 400kHz                 | 20
 * 14          | 381kHz                 | 21
 * 15          | 364kHz                 | 22
 * 
* * @return Current I2C master clock speed * @see MPU6050_RA_I2C_MST_CTRL */ /* 获取I2C主时钟速度。 * I2C_MST_CLK是一个4位无符号值,它在MPU-60X0内部8MHz时钟上配置一个分频器。 *它根据下表设置I2C主时钟速度: */ uint8_t MPU6050::getMasterClockSpeed() { I2Cdev::readBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, buffer); return buffer[0]; } /** Set I2C master clock speed. * @reparam speed Current I2C master clock speed * @see MPU6050_RA_I2C_MST_CTRL */ void MPU6050::setMasterClockSpeed(uint8_t speed) { I2Cdev::writeBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, speed); } // I2C_SLV* registers (Slave 0-3) /** Get the I2C address of the specified slave (0-3). * Note that Bit 7 (MSB) controls read/write mode. If Bit 7 is set, it's a read operation, and if it is cleared, then it's a write operation. * The remaining bits (6-0) are the 7-bit device address of the slave device. * * In read mode, the result of the read is placed in the lowest available EXT_SENS_DATA register. * For further information regarding the allocation of read results, please refer to the EXT_SENS_DATA register description (Registers 73 - 96). * * The MPU-6050 supports a total of five slaves, but Slave 4 has unique characteristics, and so it has its own functions (getSlave4* and setSlave4*). * * I2C data transactions are performed at the Sample Rate, as defined in Register 25. * The user is responsible for ensuring that I2C data transactions to and from each enabled Slave can be completed within a single period of the Sample Rate. * * The I2C slave access rate can be reduced relative to the Sample Rate. * This reduced access rate is determined by I2C_MST_DLY (Register 52). * Whether a slave's access rate is reduced relative to the Sample Rate is determined by I2C_MST_DELAY_CTRL (Register 103). * * The processing order for the slaves is fixed. The sequence followed for processing the slaves is Slave 0, Slave 1, Slave 2, Slave 3 and Slave 4. * If a particular Slave is disabled it will be skipped. * * Each slave can either be accessed at the sample rate or at a reduced sample rate. * In a case where some slaves are accessed at the Sample Rate and some slaves are accessed at the reduced rate, the sequence of accessing the slaves (Slave 0 to Slave 4) is still followed. * However, the reduced rate slaves will be skipped if their access rate dictates that they should not be accessed during that particular cycle. * For further information regarding the reduced access rate, please refer to Register 52. * Whether a slave is accessed at the Sample Rate or at the reduced rate is determined by the Delay Enable bits in Register 103. * * @param num Slave number (0-3) * @return Current address for specified slave * @see MPU6050_RA_I2C_SLV0_ADDR */ /* 获取指定从站的I2C地址(0-3)。 *请注意,位7(MSB)控制读/写模式。如果设置了位7,则它是读操作,如果清零,则是写操作。 *其余位(6-0)是从站设备的7位设备地址。 * *在读取模式下,读取结果放置在最低可用的EXT_SENS_DATA寄存器中。 *有关读取结果分配的更多信息,请参见EXT_SENS_DATA寄存器说明(寄存器73-96)。 * * MPU-6050总共支持五个从站,但是从站4具有独特的特性,因此具有自己的功能(getSlave4 *和setSlave4 *)。 * * I2C数据事务以寄存器25中定义的采样率执行。 *用户有责任确保在每个采样率的周期内完成与每个已启用的从设备之间的I2C数据事务处理。 * *可以相对于采样率降低I2C从设备访问率。 *降低的访问速率由I2C_MST_DLY(寄存器52)确定。 *从设备的访问速率是否相对于采样速率降低,由I2C_MST_DELAY_CTRL(寄存器103)确定。 * *从站的处理顺序是固定的。处理从站所遵循的顺序是从站0,从站1,从站2,从站3和从站4。 *如果禁用了特定的从站,它将被跳过。 * *可以以采样率或降低的采样率访问每个从站。 *在以采样率访问一些从站而以降低的速率访问一些从站的情况下,仍然遵循访问从站的顺序(从站0到从站4)。 *但是,如果降低速率的从站的访问速率表明在该特定周期内不应访问它们,则将跳过该速率降低的从站。 *有关降低访问率的更多信息,请参阅寄存器52。 *是否以采样率或降低的速率访问从机,取决于寄存器103中的延迟使能位。 */ uint8_t MPU6050::getSlaveAddress(uint8_t num) { if (num > 3) return 0; I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, buffer); return buffer[0]; } /** Set the I2C address of the specified slave (0-3). * @param num Slave number (0-3) * @param address New address for specified slave * @see getSlaveAddress() * @see MPU6050_RA_I2C_SLV0_ADDR */ void MPU6050::setSlaveAddress(uint8_t num, uint8_t address) { if (num > 3) return; I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, address); } /** Get the active internal register for the specified slave (0-3). * Read/write operations for this slave will be done to whatever internal register address is stored in this MPU register. * * The MPU-6050 supports a total of five slaves, but Slave 4 has unique characteristics, and so it has its own functions. * * @param num Slave number (0-3) * @return Current active register for specified slave * @see MPU6050_RA_I2C_SLV0_REG */ /* 获取指定从站(0-3)的活动内部寄存器。 *将对该MPU寄存器中存储的任何内部寄存器地址进行此从设备的读/写操作。 * * MPU-6050总共支持五个从站,但是从站4具有独特的特性,因此具有自己的功能。 */ uint8_t MPU6050::getSlaveRegister(uint8_t num) { if (num > 3) return 0; I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, buffer); return buffer[0]; } /** Set the active internal register for the specified slave (0-3). * @param num Slave number (0-3) * @param reg New active register for specified slave * @see getSlaveRegister() * @see MPU6050_RA_I2C_SLV0_REG */ void MPU6050::setSlaveRegister(uint8_t num, uint8_t reg) { if (num > 3) return; I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, reg); } /** Get the enabled value for the specified slave (0-3). * When set to 1, this bit enables Slave 0 for data transfer operations. * When cleared to 0, this bit disables Slave 0 from data transfer operations. * @param num Slave number (0-3) * @return Current enabled value for specified slave * @see MPU6050_RA_I2C_SLV0_CTRL */ /* 当设置为1时,该位使能从机0进行数据传输操作。 *清除为0时,该位将禁止从0进行数据传输操作。 */ bool MPU6050::getSlaveEnabled(uint8_t num) { if (num > 3) return 0; I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_EN_BIT, buffer); return buffer[0]; } /** Set the enabled value for the specified slave (0-3). * @param num Slave number (0-3) * @param enabled New enabled value for specified slave * @see getSlaveEnabled() * @see MPU6050_RA_I2C_SLV0_CTRL */ void MPU6050::setSlaveEnabled(uint8_t num, bool enabled) { if (num > 3) return; I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_EN_BIT, enabled); } /** Get word pair byte-swapping enabled for the specified slave (0-3). * When set to 1, this bit enables byte swapping. When byte swapping is enabled, the high and low bytes of a word pair are swapped. * Please refer to I2C_SLV0_GRP for the pairing convention of the word pairs. * When cleared to 0, bytes transferred to and from Slave 0 will be written to EXT_SENS_DATA registers in the order they were transferred. * * @param num Slave number (0-3) * @return Current word pair byte-swapping enabled value for specified slave * @see MPU6050_RA_I2C_SLV0_CTRL */ /* 为指定的从站(0-3)获取启用的字对字节交换。 *设置为1时,此位启用字节交换。 启用字节交换后,将交换字对的高字节和低字节。 *有关字对的配对约定,请参考I2C_SLV0_GRP。 *清除为0时,从从0传输和从从0传输的字节将按照传输顺序写入EXT_SENS_DATA寄存器。 */ bool MPU6050::getSlaveWordByteSwap(uint8_t num) { if (num > 3) return 0; I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_BYTE_SW_BIT, buffer); return buffer[0]; } /** Set word pair byte-swapping enabled for the specified slave (0-3). * @param num Slave number (0-3) * @param enabled New word pair byte-swapping enabled value for specified slave * @see getSlaveWordByteSwap() * @see MPU6050_RA_I2C_SLV0_CTRL */ void MPU6050::setSlaveWordByteSwap(uint8_t num, bool enabled) { if (num > 3) return; I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_BYTE_SW_BIT, enabled); } /** Get write mode for the specified slave (0-3). * When set to 1, the transaction will read or write data only. When cleared to 0, the transaction will write a register address prior to reading or writing data. * This should equal 0 when specifying the register address within the Slave device to/from which the ensuing data transaction will take place. * * @param num Slave number (0-3) * @return Current write mode for specified slave (0 = register address + data, 1 = data only) * @see MPU6050_RA_I2C_SLV0_CTRL */ /* 获取指定从站(0-3)的写入模式。 *设置为1时,事务将仅读取或写入数据。 清零时,事务将在读取或写入数据之前写入寄存器地址。 *当指定从设备中将发生数据传输的从设备中的寄存器地址时,该值应等于0。 */ bool MPU6050::getSlaveWriteMode(uint8_t num) { if (num > 3) return 0; I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_REG_DIS_BIT, buffer); return buffer[0]; } /** Set write mode for the specified slave (0-3). * @param num Slave number (0-3) * @param mode New write mode for specified slave (0 = register address + data, 1 = data only) * @see getSlaveWriteMode() * @see MPU6050_RA_I2C_SLV0_CTRL */ void MPU6050::setSlaveWriteMode(uint8_t num, bool mode) { if (num > 3) return; I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_REG_DIS_BIT, mode); } /** Get word pair grouping order offset for the specified slave (0-3). * This sets specifies the grouping order of word pairs received from registers. * When cleared to 0, bytes from register addresses 0 and 1, 2 and 3, etc (even, then odd register addresses) are paired to form a word. * When set to 1, bytes from register addresses are paired 1 and 2, 3 and 4, etc. (odd, then even register addresses) are paired to form a word. * * @param num Slave number (0-3) * @return Current word pair grouping order offset for specified slave * @see MPU6050_RA_I2C_SLV0_CTRL */ /* 获取指定从站(0-3)的单词对分组顺序偏移。 *此设置指定从寄存器接收的单词对的分组顺序。 *清除为0时,来自寄存器地址0和1、2和3等的字节(偶数,然后是奇数寄存器地址)将配对成一个字。 *设置为1时,来自寄存器地址的字节将配对为1、2、3和4等(奇数,然后是偶数寄存器地址)配对以形成一个字。 */ bool MPU6050::getSlaveWordGroupOffset(uint8_t num) { if (num > 3) return 0; I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_GRP_BIT, buffer); return buffer[0]; } /** Set word pair grouping order offset for the specified slave (0-3). * @param num Slave number (0-3) * @param enabled New word pair grouping order offset for specified slave * @see getSlaveWordGroupOffset() * @see MPU6050_RA_I2C_SLV0_CTRL */ void MPU6050::setSlaveWordGroupOffset(uint8_t num, bool enabled) { if (num > 3) return; I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_GRP_BIT, enabled); } /** Get number of bytes to read for the specified slave (0-3). * Specifies the number of bytes transferred to and from Slave 0. Clearing this bit to 0 is equivalent to disabling the register by writing 0 to I2C_SLV0_EN. * @param num Slave number (0-3) * @return Number of bytes to read for specified slave * @see MPU6050_RA_I2C_SLV0_CTRL */ /* 获取要读取的指定从站的字节数(0-3)。 *指定从设备0传输和从设备0传输的字节数。将该位置0等效于通过将0写入I2C_SLV0_EN来禁用寄存器。 */ uint8_t MPU6050::getSlaveDataLength(uint8_t num) { if (num > 3) return 0; I2Cdev::readBits(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_LEN_BIT, MPU6050_I2C_SLV_LEN_LENGTH, buffer); return buffer[0]; } /** Set number of bytes to read for the specified slave (0-3). * @param num Slave number (0-3) * @param length Number of bytes to read for specified slave * @see getSlaveDataLength() * @see MPU6050_RA_I2C_SLV0_CTRL */ void MPU6050::setSlaveDataLength(uint8_t num, uint8_t length) { if (num > 3) return; I2Cdev::writeBits(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_LEN_BIT, MPU6050_I2C_SLV_LEN_LENGTH, length); } // I2C_SLV* registers (Slave 4) /** Get the I2C address of Slave 4. * Note that Bit 7 (MSB) controls read/write mode. If Bit 7 is set, it's a read operation, and if it is cleared, then it's a write operation. * The remaining bits (6-0) are the 7-bit device address of the slave device. * * @return Current address for Slave 4 * @see getSlaveAddress() * @see MPU6050_RA_I2C_SLV4_ADDR */ /* 获取从站4的I2C地址。 *请注意,位7(MSB)控制读/写模式。 如果设置了位7,则它是读操作,如果清零,则是写操作。 *其余位(6-0)是从站设备的7位设备地址。 */ uint8_t MPU6050::getSlave4Address() { I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, buffer); return buffer[0]; } /** Set the I2C address of Slave 4. * @param address New address for Slave 4 * @see getSlave4Address() * @see MPU6050_RA_I2C_SLV4_ADDR */ void MPU6050::setSlave4Address(uint8_t address) { I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, address); } /** Get the active internal register for the Slave 4. * Read/write operations for this slave will be done to whatever internal register address is stored in this MPU register. * * @return Current active register for Slave 4 * @see MPU6050_RA_I2C_SLV4_REG */ uint8_t MPU6050::getSlave4Register() { I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV4_REG, buffer); return buffer[0]; } /** Set the active internal register for Slave 4. * @param reg New active register for Slave 4 * @see getSlave4Register() * @see MPU6050_RA_I2C_SLV4_REG */ void MPU6050::setSlave4Register(uint8_t reg) { I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV4_REG, reg); } /** Set new byte to write to Slave 4. * This register stores the data to be written into the Slave 4. If I2C_SLV4_RW is set 1 (set to read), this register has no effect. * @param data New byte to write to Slave 4 * @see MPU6050_RA_I2C_SLV4_DO */ /* */ void MPU6050::setSlave4OutputByte(uint8_t data) { I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV4_DO, data); } /** Get the enabled value for the Slave 4. * When set to 1, this bit enables Slave 4 for data transfer operations. When cleared to 0, this bit disables Slave 4 from data transfer operations. * @return Current enabled value for Slave 4 * @see MPU6050_RA_I2C_SLV4_CTRL */ /* */ bool MPU6050::getSlave4Enabled() { I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, buffer); return buffer[0]; } /** Set the enabled value for Slave 4. * @param enabled New enabled value for Slave 4 * @see getSlave4Enabled() * @see MPU6050_RA_I2C_SLV4_CTRL */ void MPU6050::setSlave4Enabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, enabled); } /** Get the enabled value for Slave 4 transaction interrupts. * When set to 1, this bit enables the generation of an interrupt signal upon completion of a Slave 4 transaction. * When cleared to 0, this bit disables the generation of an interrupt signal upon completion of a Slave 4 transaction. * The interrupt status can be observed in Register 54. * * @return Current enabled value for Slave 4 transaction interrupts. * @see MPU6050_RA_I2C_SLV4_CTRL */ /* 获取从站4事务中断的启用值。 *当设置为1时,该位使能从设备4事务完成时产生中断信号。 *当清除为0时,该位将禁止从设备4事务完成时产生中断信号。 *中断状态可在寄存器54中观察到。 */ bool MPU6050::getSlave4InterruptEnabled() { I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, buffer); return buffer[0]; } /** Set the enabled value for Slave 4 transaction interrupts. * @param enabled New enabled value for Slave 4 transaction interrupts. * @see getSlave4InterruptEnabled() * @see MPU6050_RA_I2C_SLV4_CTRL */ void MPU6050::setSlave4InterruptEnabled(bool enabled) { I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, enabled); } /** Get write mode for Slave 4. * When set to 1, the transaction will read or write data only. * When cleared to 0, the transaction will write a register address prior to reading or writing data. * This should equal 0 when specifying the register address within the Slave device to/from which the ensuing data transaction will take place. * * @return Current write mode for Slave 4 (0 = register address + data, 1 = data only) * @see MPU6050_RA_I2C_SLV4_CTRL */ /* 获取从站4的写入模式。 *设置为1时,事务将仅读取或写入数据。 *清除为0时,事务将在读取或写入数据之前写入寄存器地址。 *当指定从设备中将发生数据传输的从设备中的寄存器地址时,该值应等于0。 */ bool MPU6050::getSlave4WriteMode() { I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, buffer); return buffer[0]; } /** Set write mode for the Slave 4. * @param mode New write mode for Slave 4 (0 = register address + data, 1 = data only) * @see getSlave4WriteMode() * @see MPU6050_RA_I2C_SLV4_CTRL */ void MPU6050::setSlave4WriteMode(bool mode) { I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, mode); } /** Get Slave 4 master delay value. * This configures the reduced access rate of I2C slaves relative to the Sample Rate. * When a slave's access rate is decreased relative to the Sample Rate, the slave is accessed every: * * 1 / (1 + I2C_MST_DLY) samples * * This base Sample Rate in turn is determined by SMPLRT_DIV (register 25) and DLPF_CFG (register 26). * Whether a slave's access rate is reduced relative to the Sample Rate is determined by I2C_MST_DELAY_CTRL (register 103). * For further information regarding the Sample Rate, please refer to register 25. * * @return Current Slave 4 master delay value * @see MPU6050_RA_I2C_SLV4_CTRL */ /* 获取从站4主站延迟值。 *这将配置I2C从设备相对于采样率降低的访问率。 *当从站的访问速率相对于采样率降低时,将按以下方式访问从站: * * 1 /(1 + I2C_MST_DLY)个样本 * *该基本采样率又由SMPLRT_DIV(寄存器25)和DLPF_CFG(寄存器26)确定。 *从站的访问
锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章