Skip to content

Divide by zero error when FIFO is disabled for MPU9250, calibrateMPU9250 doesn't work. #250

@playztag

Description

@playztag

Following the code examples, if I run IMU.calibrateMPU9250(IMU.gyroBias, IMU.accelBias); to calibrate the bias, my program will crash with a divide-by-zero error. Upon further investigation, I found that

readBytes(MPU9250_ADDRESS, FIFO_COUNTH, 2, &data[0]); // read FIFO sample count fifo_count = ((uint16_t)data[0] << 8) | data[1];

returns 0 and thus the lines 258-260 on MPU9250.cpp below will crash:
accel_bias[0] /= (int32_t) packet_count; // Normalize sums to get average count biases accel_bias[1] /= (int32_t) packet_count; accel_bias[2] /= (int32_t) packet_count;

The way I fixed this was simply commenting out line 236 of MPU9250.cpp
//writeByte(MPU9250_ADDRESS, FIFO_EN, 0x00); // Disable gyro and accelerometer sensors for FIFO
Now, the read operation will return a non-zero value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions