diff --git a/libraries/AP_Compass/AP_Compass_QMC5883L.cpp b/libraries/AP_Compass/AP_Compass_QMC5883L.cpp index ad1bea4989..ea36cbd7a9 100644 --- a/libraries/AP_Compass/AP_Compass_QMC5883L.cpp +++ b/libraries/AP_Compass/AP_Compass_QMC5883L.cpp @@ -27,12 +27,13 @@ #include #include #include +#include #define QMC5883L_REG_CONF1 0x09 #define QMC5883L_REG_CONF2 0x0A // data output rates for 5883L -#define QMC5883L_ODR_10HZ (0x00 << 2) +#define QMC5883L_ODR_10HZ (0x00 << 2) #define QMC5883L_ODR_50HZ (0x01 << 2) #define QMC5883L_ODR_100HZ (0x02 << 2) #define QMC5883L_ODR_200HZ (0x03 << 2) @@ -46,8 +47,8 @@ #define QMC5883L_OSR_512 (0x00 << 6) #define QMC5883L_OSR_256 (0x01 << 6) -#define QMC5883L_OSR_128 (0x10 << 6) -#define QMC5883L_OSR_64 (0x11 << 6) +#define QMC5883L_OSR_128 (0x10 << 6) +#define QMC5883L_OSR_64 (0x11 << 6) #define QMC5883L_RST 0x80 @@ -99,14 +100,14 @@ bool AP_Compass_QMC5883L::init() goto fail; } + /* Registers 0x20 and 0x21 are not documented in the data sheet and do not show any function during operation */ + if (!_dev->write_register(0x0B, 0x01)|| - !_dev->write_register(0x20, 0x40)|| - !_dev->write_register(0x21, 0x01)|| - !_dev->write_register(QMC5883L_REG_CONF1, - QMC5883L_MODE_CONTINUOUS| - QMC5883L_ODR_100HZ| - QMC5883L_OSR_512| - QMC5883L_RNG_8G)) { + !_dev->write_register(QMC5883L_REG_CONF1, + QMC5883L_MODE_CONTINUOUS| + QMC5883L_ODR_100HZ| + QMC5883L_OSR_512| + QMC5883L_RNG_8G)) { goto fail; } @@ -165,7 +166,8 @@ void AP_Compass_QMC5883L::timer() le16_t rz; } buffer; - const float range_scale = 1000.0f / 3000.0f; + /* Most modules deliver a value four times higher */ + const float range_scale = 1000.0f / (3000.0f * 4.0f); uint8_t status; if(!_dev->read_registers(QMC5883L_REG_STATUS,&status,1)){