From d5d784bb1a6d87b75b5064d7238a63220eed26a3 Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Mon, 18 Mar 2024 18:22:59 +0000 Subject: [PATCH 1/3] Fix reading of dig_H5 and dig_H6 Fixes #480 --- spi/bme280_spi/bme280_spi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spi/bme280_spi/bme280_spi.c b/spi/bme280_spi/bme280_spi.c index c6c50b11f..457324405 100644 --- a/spi/bme280_spi/bme280_spi.c +++ b/spi/bme280_spi/bme280_spi.c @@ -163,15 +163,15 @@ void read_compensation_parameters() { dig_P8 = buffer[20] | (buffer[21] << 8); dig_P9 = buffer[22] | (buffer[23] << 8); - dig_H1 = buffer[25]; + dig_H1 = buffer[25]; // 0xA1 read_registers(0xE1, buffer, 8); - dig_H2 = buffer[0] | (buffer[1] << 8); - dig_H3 = (int8_t) buffer[2]; - dig_H4 = buffer[3] << 4 | (buffer[4] & 0xf); - dig_H5 = (buffer[5] >> 4) | (buffer[6] << 4); - dig_H6 = (int8_t) buffer[7]; + dig_H2 = buffer[0] | (buffer[1] << 8); // 0xE1 | 0xE2 + dig_H3 = (int8_t) buffer[2]; // 0xE3 + dig_H4 = buffer[3] << 4 | (buffer[4] & 0xf); // 0xE4 | 0xE5[3:0] + dig_H5 = (buffer[4] >> 4) | (buffer[5] << 4); // 0xE5[7:4] | 0xE6 + dig_H6 = (int8_t) buffer[6]; // 0xE7 } static void bme280_read_raw(int32_t *humidity, int32_t *pressure, int32_t *temperature) { From 755f5ff369b3a250c7ecb39e8a2f65728ee7bba8 Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Mon, 18 Mar 2024 18:49:31 +0000 Subject: [PATCH 2/3] Fix reading of dig_H1 Fixes #111 --- spi/bme280_spi/bme280_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spi/bme280_spi/bme280_spi.c b/spi/bme280_spi/bme280_spi.c index 457324405..eb2643bdf 100644 --- a/spi/bme280_spi/bme280_spi.c +++ b/spi/bme280_spi/bme280_spi.c @@ -147,7 +147,7 @@ static void read_registers(uint8_t reg, uint8_t *buf, uint16_t len) { void read_compensation_parameters() { uint8_t buffer[26]; - read_registers(0x88, buffer, 24); + read_registers(0x88, buffer, 26); dig_T1 = buffer[0] | (buffer[1] << 8); dig_T2 = buffer[2] | (buffer[3] << 8); From e3d5df34a5b1b8893e42f29cc7b06aa4301861b7 Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Mon, 18 Mar 2024 18:50:32 +0000 Subject: [PATCH 3/3] Fix order of reading of temp and pressure Fixes #442 --- spi/bme280_spi/bme280_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spi/bme280_spi/bme280_spi.c b/spi/bme280_spi/bme280_spi.c index eb2643bdf..74a4e228a 100644 --- a/spi/bme280_spi/bme280_spi.c +++ b/spi/bme280_spi/bme280_spi.c @@ -225,8 +225,8 @@ int main() { // These are the raw numbers from the chip, so we need to run through the // compensations to get human understandable numbers - pressure = compensate_pressure(pressure); temperature = compensate_temp(temperature); + pressure = compensate_pressure(pressure); humidity = compensate_humidity(humidity); printf("Humidity = %.2f%%\n", humidity / 1024.0);