From 0490046af45e8e4f8ae94961000211236ba25501 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Tue, 6 Oct 2015 17:22:38 +0200 Subject: [PATCH] MS5611: Increase the requirements about the PROM contents and CRC. --- src/drivers/ms5611/ms5611_i2c.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/drivers/ms5611/ms5611_i2c.cpp b/src/drivers/ms5611/ms5611_i2c.cpp index 74f67c0f26..86aa28a389 100644 --- a/src/drivers/ms5611/ms5611_i2c.cpp +++ b/src/drivers/ms5611/ms5611_i2c.cpp @@ -266,6 +266,9 @@ MS5611_I2C::_read_prom() */ usleep(3000); + uint8_t last_val = 0; + bool bits_stuck = true; + /* read and convert PROM words */ for (int i = 0; i < 8; i++) { uint8_t cmd = ADDR_PROM_SETUP + (i * 2); @@ -274,6 +277,16 @@ MS5611_I2C::_read_prom() break; } + /* check if all bytes are zero */ + if (i == 0) { + /* initalize to first byte read */ + last_val = prom_buf[0]; + } + + if (prom_buf[0] != last_val || prom_buf[1] != last_val) { + bits_stuck = false; + } + /* assemble 16 bit value and convert from big endian (sensor) to little endian (MCU) */ cvt.b[0] = prom_buf[1]; cvt.b[1] = prom_buf[0]; @@ -281,5 +294,5 @@ MS5611_I2C::_read_prom() } /* calculate CRC and return success/failure accordingly */ - return ms5611::crc4(&_prom.c[0]) ? PX4_OK : -EIO; + return (ms5611::crc4(&_prom.c[0]) && !bits_stuck) ? PX4_OK : -EIO; }