From 17743dc4137425ab0f511d12352683255033a79a Mon Sep 17 00:00:00 2001 From: Jonny Roeker Date: Sat, 25 May 2024 17:42:40 +0200 Subject: [PATCH] =?UTF-8?q?AP=5FCompass:=20Scale=20adjusted=20QMC5883L=20?= =?UTF-8?q?=09ge=C3=A4ndert:=20=20=20=20=20=20=20libraries/AP=5FCompass/AP?= =?UTF-8?q?=5FCompass=5FQMC5883L.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libraries/AP_Compass/AP_Compass_QMC5883L.cpp | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) 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)){