Skip to content

Wrong Magnetometer Readings at Lines 1729-1731 of MPU9150.cpp #179

@siavakhsht

Description

@siavakhsht

Hello,

I am new to the github, so please excuse me if this is not the right place to post this.
I noticed in lines 1729-1731, the way mx, my and mz readings are reconstructed from MSB and LSB is not correct. Unlike the Accel and Gyro which have big-endian format (MSB at lower address and LSB at higher address), magnetometer data which come from a different chip (i.e. AK8975) have little-endian format (LSB at lower address and MSB at higher address) (refer to page 53 of MPU-9150 Register Map and Descriptions Revision 3.0). Therefore these 3 lines (1729-1731) should be modified as follows:
1729 *mx = (((int16_t)buffer[1]) << 8) | buffer[0];
1730 *my = (((int16_t)buffer[3]) << 8) | buffer[2];
1731 *mz = (((int16_t)buffer[5]) << 8) | buffer[4];

Thank you,
Siavash Y
P.S. Thank you very much for the great libraries you have made and shared.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions