From a4cad3173fc49cc0286f6eedf6efbca15db6688e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 25 Oct 2019 13:38:50 +0200 Subject: BME280 driver: normalize API, add i2cdetect test --- src/app/i2cdetect/main.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/app/i2cdetect/main.cc') diff --git a/src/app/i2cdetect/main.cc b/src/app/i2cdetect/main.cc index e235369..faa2725 100644 --- a/src/app/i2cdetect/main.cc +++ b/src/app/i2cdetect/main.cc @@ -12,6 +12,10 @@ #ifdef DRIVER_AM2320 #include "driver/am2320.h" #endif +#ifdef DRIVER_BME280 +#include "driver/bme280.h" +#include "driver/bme680_util.h" +#endif #ifdef DRIVER_BME680 #include "driver/bme680.h" #include "driver/bme680_util.h" @@ -52,6 +56,30 @@ void loop(void) kout << "AM2320 error " << dec << am2320.getStatus() << endl; } #endif +#ifdef DRIVER_BME280 + bme280.intf = BME280_I2C_INTF; + bme280.read = bme680_i2c_read; + bme280.write = bme680_i2c_write; + bme280.delay_ms = bme680_delay_ms; + + int8_t rslt = BME280_OK; + struct bme280_data comp_data; + rslt = bme280.init(); + kout << "BME280 init " << rslt << endl; + bme280.settings.osr_p = BME280_OVERSAMPLING_16X; + bme280.settings.osr_t = BME280_OVERSAMPLING_16X; + bme280.settings.osr_h = BME280_OVERSAMPLING_16X; + bme280.settings.filter = BME280_FILTER_COEFF_OFF; + bme280.settings.standby_time = BME280_STANDBY_TIME_500_MS; + bme280.setSensorSettings(BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL | BME280_STANDBY_SEL); + bme280.setSensorMode(BME280_NORMAL_MODE); + arch.delay_ms(100); + rslt = bme280.getSensorData(BME280_ALL, &comp_data); + kout << "BME280 read " << rslt << endl; + kout << "BME280 temperature " << (float)comp_data.temperature / 100 << " degC" << endl; + kout << "BME280 humidity " << (float)comp_data.humidity / 1024 << " %" << endl; + kout << "BME280 pressure " << (float)comp_data.pressure / 100 << " Pa" << endl; +#endif #ifdef DRIVER_BME680 bme680.intf = BME680_I2C_INTF; bme680.read = bme680_i2c_read; -- cgit v1.2.3