Skip to contentSkip to conversation

BME-280 humidity over-/underflow

PATCH Hendrik Hoeth 2 participants 3 messages Jun 10, 2020 IIO

lore
Share & tools
lore
#0 lore raw

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

Signature · 3 lines
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

drivers/iio/pressure/bmp280-core.c +2 -0
index 29c209cc1108..d1f36b044f05 100644
@@ -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;
 };
#1 lore raw

Hello Hendrik,

Quoted 14 lines · Hendrik Hoeth

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.

Quoted 8 lines

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

Seems this particular issue has been already fixed here:
dee2dabc0e4115b80945fe2c91603e634f4b4686 iio: bmp280: fix compensation of humidity

Quoted 21 lines

--
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

drivers/iio/pressure/bmp280-core.c +2 -0
index 29c209cc1108..d1f36b044f05 100644
@@ -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;
 };
#2 lore raw

Hello Tomasz,

Quoted 2 lines · Tomasz Duszynski

Seems this particular issue has been already fixed here:
dee2dabc0e4115b80945fe2c91603e634f4b4686 iio: bmp280: fix compensation of humidity

Thanks, I hadn't seen that (I only checked stable).

Best regards, and sorry for the noise,

Hendrik