From c3ac1497c0d9596d76c289bf45b0324bfeeb3f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 26 Apr 2019 17:26:54 +0200 Subject: [PATCH] mpu9250: fix mag publishing garbage on IMU failure (SPI only) The Pixhawk cube as an internal mag on SPI. If there was a bad register read (e.g. on an IMU failure), _register_wait was non-zero and there was no transfer but _mag still published mpu_report.mag. --- src/drivers/imu/mpu9250/mpu9250.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/drivers/imu/mpu9250/mpu9250.cpp b/src/drivers/imu/mpu9250/mpu9250.cpp index 14cfc35b27..2d29eb6bb9 100644 --- a/src/drivers/imu/mpu9250/mpu9250.cpp +++ b/src/drivers/imu/mpu9250/mpu9250.cpp @@ -1058,7 +1058,9 @@ MPU9250::measure() if (_mag->is_passthrough()) { # endif - _mag->_measure(mpu_report.mag); + if (_register_wait == 0) { + _mag->_measure(mpu_report.mag); + } # ifdef USE_I2C