diff --git a/bme680.c b/bme680.c index d102676..0e833d3 100644 --- a/bme680.c +++ b/bme680.c @@ -83,6 +83,8 @@ int bme680_init(bme680_t *bme680, uint8_t mode) { bme680->mode = mode; bme680->spi_page = 0; + bme680->gas_valid = 0; + bme680->heat_stab = 0; if (bme680->dev.init() != 0) { return 1; @@ -177,10 +179,6 @@ int bme680_configure(bme680_t *bme680) { err |= write_dev(bme680, REG_CTRL_GAS_1, ctrl_gas1); err |= write_dev(bme680, REG_CTRL_GAS_0, ctrl_gas0); - // TODO: check gas_valid_r and heat_stab_r in 0x2B - - - SKIP_GAS: return err; } @@ -249,12 +247,21 @@ int bme680_read(bme680_t *bme680) { } /* read gas adc ?*/ + // TODO: read 2 bytes once if (BME680_GAS_ENABLED(bme680->mode)) { err |= read_dev(bme680, 0x2A, buffer, 2); bme680->adc.gas = (buffer[0] << 2) | (buffer[1] >> 6); err |= read_dev(bme680, 0x2B, buffer, 1); bme680->adc.gas_range = buffer[0] & 0xF; + + /* check gas validity status (if one actually took place ??? ) */ + err |= read_dev(bme680, 0x2B, buffer, 1); + bme680->gas_valid = (buffer[0] >> 5) & 1 ; + + /* check heater stability. if it managed to get to temp within given time + preload current */ + err |= read_dev(bme680, 0x2B, buffer, 1); + bme680->heat_stab = (buffer[0] >> 4) & 1; } /* read/convert in order ..*/ diff --git a/bme680.h b/bme680.h index 0ff82db..9fb5389 100644 --- a/bme680.h +++ b/bme680.h @@ -135,6 +135,8 @@ struct bme680 { struct bme680_adc adc; uint8_t mode; uint8_t spi_page; + uint8_t gas_valid; + uint8_t heat_stab; }; typedef struct bme680 bme680_t; diff --git a/main.c b/main.c index fcb3143..21bd8c0 100644 --- a/main.c +++ b/main.c @@ -76,9 +76,9 @@ int main(void) { /* define the time between the start of heating and start of resistance sensing in this s.p.*/ /* Bosch datasheet suggests ~30 - 40ms is usually all that is required to get up to temp. */ - /* 50 * X4 = 200 ms wait before sampling resistance starts. */ + /* 25 * X4 = 100 ms wait before sampling resistance starts. */ /* the first value is 6-bit (0...64) with 1 ms step size. */ - bme680.cfg.gas_wait[i] = BME680_GAS_WAIT(50, BME680_GAS_WAIT_X4); + bme680.cfg.gas_wait[i] = BME680_GAS_WAIT(25, BME680_GAS_WAIT_X4); } /* The BME680 does not cycle between setpoints. They have to be manually set. */ @@ -140,6 +140,12 @@ int main(void) { } } + /* print out heat stability and gas valid flags. should both be 1 !! */ + if (BME680_GAS_ENABLED(bme680.mode)) { + printf("=== gas_valid_r: %d\n", bme680.gas_valid); + printf("=== heat_stab_r: %d\n", bme680.heat_stab); + } + bme680_deinit(&bme680); return 0;