BME-280 humidity over-/underflow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I've discovered an over-/underflow problem for relative humidity
measurements in drivers/iio/pressure/bmp280-core.c. At very low
humidities the value measured by the sensor can fluctuate into the
negative humidity range. The kernel driver then reports this as
extremely large value (e.g. 4193085, corresponding to 4193% RH). The
same probably happens at high humidity values, but with our climate
chamber I was only able to look at the low end.

To avoid this, the reference code in the BME-280 datasheet catches
values < 0% RH and > 100% RH. These two lines are currently missing in
the kernel driver.

Attached you find a patch that fixed the problem for us. You can find
the sensor datasheet at
https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280-DS002.pdf
The code I'm talking about is in section 4.2.3 on page 25/26.

Thanks a lot,

   Hendrik

-- 
Garrecht Avionik GmbH | Wieslocher Str. 38 | 69190 Walldorf
https://www.air-avionics.com/
Tel.: +49 6224 98 96 999
Fix underflow / overflow for humidity measurements

diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index 29c209cc1108..d1f36b044f05 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -270,6 +270,8 @@ static u32 bmp280_compensate_humidity(struct bmp280_data *data,
 		* (((var * (s32)calib->H3) >> 11) + (s32)32768)) >> 10)
 		+ (s32)2097152) * calib->H2 + 8192) >> 14);
 	var -= ((((var >> 15) * (var >> 15)) >> 7) * (s32)calib->H1) >> 4;
+	var = ((var < 0) ? 0 : var);
+	var = ((var > 419430400) ? 419430400 : var);
 
 	return var >> 12;
 };

[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux