Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Read Compass in FiFO mode due to bug #38

Open
savejeff opened this issue Dec 28, 2019 · 0 comments
Open

Unable to Read Compass in FiFO mode due to bug #38

savejeff opened this issue Dec 28, 2019 · 0 comments

Comments

@savejeff
Copy link

savejeff commented Dec 28, 2019

There is a bug in the Code in case you want to read Accel and/or Gyro in fifo mode and also read the Compass Data.
The problem is caused because of the internal variable st.chip_cfg.bypass_mode (in inv_mpu.c) is per default True. In Regular Setup (without using FIFO) the Aux I2C is used in Master Mode (bypass disabled). The bypass flag is not used and the register is written directly to.
When switching to FIFO mode with configuring FIFO the st.chip_cfg.bypass_mode flag is used to determine the I2C_MST_EN bit in USER CONTROL register.

That means the AUX I2C port switches to bypass when configuring fifo.

Here the setup that causes the bug:

imu.setSensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS);
imu.setGyroFSR(2000); // Set gyro to 2000 dps
imu.setAccelFSR(2); // Set accel to +/-2g
imu.setLPF(5); // Set LPF corner frequency to 5Hz
imu.setSampleRate(AG_SAMPLE_RATE); // Set sample rate to 10Hz
//MPU9250_USER_CTRL: **00100000**
**imu.configureFifo(INV_XYZ_GYRO | INV_XYZ_ACCEL);**
//MPU9250_USER_CTRL: **01000000**


Solution: Set the st.chip_cfg.bypass_mode flag to false while initializing:
(note: AK89xx_SECONDARY is defined. AK89xx_BYPASS is not defined


int mpu_set_sensors(unsigned char sensors)
{
   [...]
    if (sensors && (sensors != INV_XYZ_ACCEL))
        /* Latched interrupts only used in LP accel mode. */
        mpu_set_int_latched(0);

#ifdef AK89xx_SECONDARY
#ifdef AK89xx_BYPASS
    if (sensors & INV_XYZ_COMPASS)
        mpu_set_bypass(1);
    else
        mpu_set_bypass(0);
#else
	**st.chip_cfg.bypass_mode = 0;**
    if (i2c_read(st.hw->addr, st.reg->user_ctrl, 1, &user_ctrl))
        return -1;
    /* Handle AKM power management. */
    if (sensors & INV_XYZ_COMPASS) {
        data = AKM_SINGLE_MEASUREMENT;
        user_ctrl |= BIT_AUX_IF_EN;
    } else {
        data = AKM_POWER_DOWN;
        user_ctrl &= ~BIT_AUX_IF_EN;
    }
[...]

}

This might not the best fix but it solves my problem. I'm sure there is a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant