From 3b5d73b1fe0bc7219249089af9bcdfa6f87befd3 Mon Sep 17 00:00:00 2001 From: Julien BERAUD Date: Fri, 18 Sep 2015 12:19:11 +0200 Subject: [PATCH] AP_Baro_MS5611: Fix state machine in case of error If there is a read error, reading from the adc will return 0 but moreover, we need to re-initiate a read or else we are stuck forever. From MS5611-01BA03 datasheet, p. 10, CONVERSION SEQUENCE: "After the conversion, using ADC read command the result is clocked out with the MSB first. 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." --- libraries/AP_Baro/AP_Baro_MS5611.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libraries/AP_Baro/AP_Baro_MS5611.cpp b/libraries/AP_Baro/AP_Baro_MS5611.cpp index f5f50e8ae4..327a680482 100644 --- a/libraries/AP_Baro/AP_Baro_MS5611.cpp +++ b/libraries/AP_Baro/AP_Baro_MS5611.cpp @@ -286,6 +286,10 @@ void AP_Baro_MS56XX::_timer(void) if (_serial->write(CMD_CONVERT_D1_OSR4096)) { // Command to read pressure _state++; } + } else { + /* if read fails, re-initiate a temperature read command or we are + * stuck */ + _serial->write(CMD_CONVERT_D2_OSR4096); } } else { uint32_t d1 = _serial->read_24bits(0);; @@ -313,6 +317,10 @@ void AP_Baro_MS56XX::_timer(void) _state++; } } + } else { + /* if read fails, re-initiate a pressure read command or we are + * stuck */ + _serial->write(CMD_CONVERT_D1_OSR4096); } }