From 49708e4e1d2a305fa9a3a78de4d98e29505c8562 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Tue, 4 Oct 2022 15:19:09 +1300 Subject: [PATCH] ms5611: ignore reading 0 This prevents publishing a negative pressure which leads to a NAN altitude estimate further down the line. --- src/drivers/barometer/ms5611/ms5611.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/drivers/barometer/ms5611/ms5611.cpp b/src/drivers/barometer/ms5611/ms5611.cpp index 06a4a04db10e..871316a0fdda 100644 --- a/src/drivers/barometer/ms5611/ms5611.cpp +++ b/src/drivers/barometer/ms5611/ms5611.cpp @@ -253,6 +253,18 @@ MS5611::collect() return ret; } + // According to the sensor docs: + // If the conversion is not executed before the ADC read command, or the + // ADC read command is repeated, it will give 0 as the output result. + // + // We have seen 0 during the init phase on I2C, therefore, we add this + // protection in. + if (raw == 0) { + perf_count(_comms_errors); + perf_end(_sample_perf); + return ret; + } + /* handle a measurement */ if (_measure_phase == 0) {