BME680 is an integrated environmental sensor developed specifically for mobile applications and wearables where size and low power consumption are key requirements.

Dependents:   Example_DS3231_test

Files at this revision

API Documentation at this revision

Comitter:
yangcq88517
Date:
Wed Aug 03 15:07:42 2016 +0000
Parent:
0:c70b7ececf93
Commit message:
add three different mod

Changed in this revision

BME680.cpp Show annotated file Show diff for this revision Revisions of this file
BME680.h Show annotated file Show diff for this revision Revisions of this file
--- a/BME680.cpp	Fri Jul 22 17:38:11 2016 +0000
+++ b/BME680.cpp	Wed Aug 03 15:07:42 2016 +0000
@@ -4,35 +4,139 @@
 //const double BME680::const_array1[16] = {1,1,1,1,1,0.99,1,0.992,1,1,0.998,0.995,1,0.99,1,1};
 //const double BME680::const_array2[16] = {8000000,4000000,2000000,1000000,499500.4995,248262.1648,125000,63004.03226,31281.28128,15625,7812.5,3906.25,1953.125,976.5625,488.28125,244.140625};
 
-
 const uint64_t BME680::lookup_k1_range[16] = {
-        2147483647UL, 2147483647UL, 2147483647UL, 2147483647UL, 2147483647UL,
-        2126008810UL, 2147483647UL, 2130303777UL, 2147483647UL, 2147483647UL,
-        2143188679UL, 2136746228UL, 2147483647UL, 2126008810UL, 2147483647UL,
-        2147483647UL
-                                             };
+    2147483647UL, 2147483647UL, 2147483647UL, 2147483647UL, 2147483647UL,
+    2126008810UL, 2147483647UL, 2130303777UL, 2147483647UL, 2147483647UL,
+    2143188679UL, 2136746228UL, 2147483647UL, 2126008810UL, 2147483647UL,
+    2147483647UL
+};
 
 const uint64_t BME680::lookup_k2_range[16] = {
-        4096000000UL, 2048000000UL, 1024000000UL, 512000000UL,
-        255744255UL, 127110228UL, 64000000UL, 32258064UL, 16016016UL,
-        8000000UL, 4000000UL, 2000000UL, 1000000UL, 500000UL, 250000UL,
-        125000UL
-                                             };
+    4096000000UL, 2048000000UL, 1024000000UL, 512000000UL,
+    255744255UL, 127110228UL, 64000000UL, 32258064UL, 16016016UL,
+    8000000UL, 4000000UL, 2000000UL, 1000000UL, 500000UL, 250000UL,
+    125000UL
+};
 
 const double BME680::_lookup_k1_range[BME680_GAS_RANGE_RL_LENGTH] = {
     0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -0.8,
     0.0, 0.0, -0.2, -0.5, 0.0, -1.0, 0.0, 0.0
 };
+
 const double BME680::_lookup_k2_range[BME680_GAS_RANGE_RL_LENGTH] = {
     0.0, 0.0, 0.0, 0.0, 0.1, 0.7, 0.0, -0.8,
     -0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
 };
 
+void BME680::setParallelMode()
+{
+    //Select oversampling for T, P, H
+    setOversamplingTemperature(2);
+    setOversamplingPressure(5);
+    setOversamplingHumidity(1);
+    
+    //Select IIR filter for pressure & temperature
+    setIIRfilterCoefficient(0);
+    
+    //Enable gas coversion
+    runGasConversion();
+    
+    //Select heater set-points to be used
+    setHeaterProfile(1);
+    
+    //Set wait time between TPHG submeasurements
+    //Set gas_wait_shared<7:0> (time base unit is 0.477ms)
+    setGasWaitShared(32, 1);
+    
+    //Define heater-on times
+    //Convert durations to register codes
+    //Set gas_wait_x<7:0> (time base unit is ms)
+    setGasWaitTime(0,25,4);
+    
+#ifdef FIXED_POINT_COMPENSATION
+    setTargetHeaterResistance(0, convertTemperatureResistanceInt(350,30));
+#else
+    setTargetHeaterResistance(0, convertTemperatureResistanceDouble(350,30));
+#endif
+
+    setMode(2);
+}
+
+void BME680::setForcedMode()
+{
+    //Select oversampling for T, P, H
+    setOversamplingTemperature(2);
+    setOversamplingPressure(5);
+    setOversamplingHumidity(1);
+
+    //Select IIR filter for pressure & temperature
+    setIIRfilterCoefficient(0);
+
+    //Enable gas coversion
+    runGasConversion();
+
+    //Select heater set-points to be used
+    setHeaterProfile(1);
+
+    //Define heater-on times
+    //Convert durations to register codes
+    //Set gas_wait_x<7:0> (time base unit is ms)
+    setGasWaitTime(0,25,4);
+
+#ifdef FIXED_POINT_COMPENSATION
+    setTargetHeaterResistance(0, convertTemperatureResistanceInt(350,30));
+#else
+    setTargetHeaterResistance(0, convertTemperatureResistanceDouble(350,30));
+#endif
+
+    //Set mode to sequential mode
+    //Set mode<1:0> to 0b01
+    setMode(1);
+}
+
+void BME680::setSequentialMode()
+{
+    //Select stand-by time between measurements
+    setWakePeriod(1);
+
+    //Select oversampling for T, P, H
+    setOversamplingTemperature(2);
+    setOversamplingPressure(5);
+    setOversamplingHumidity(1);
+
+    //Select IIR filter for pressure & temperature
+    setIIRfilterCoefficient(0);
+
+    //Enable gas coversion
+    runGasConversion();
+
+    //Select heater set-points to be used
+    setHeaterProfile(1);
+
+    //Define heater-on times
+    //Convert durations to register codes
+    //Set gas_wait_x<7:0> (time base unit is ms)
+    setGasWaitTime(0,25,4);
+
+    //Set heater temperatures
+    //Convert temperature to register code
+    //Set res_heat_x<7:0>
+
+#ifdef FIXED_POINT_COMPENSATION
+    setTargetHeaterResistance(0, convertTemperatureResistanceInt(350,30));
+#else
+    setTargetHeaterResistance(0, convertTemperatureResistanceDouble(350,30));
+#endif
+
+    //Set mode to sequential mode
+    //Set mode<1:0> to 0b11
+    setMode(3);
+}
 
 #ifdef FIXED_POINT_COMPENSATION
 int32_t BME680::getCompensatedTemperature(int field)
 {
-    uint32_t v_uncomp_temperature_u32 = getTemp1Data(field);
+    uint32_t v_uncomp_temperature_u32 = getUncompensatedTemp1Data(field);
 
     int32_t var1 = ((int32_t)v_uncomp_temperature_u32 >> 3) - ((int32_t)(par_T1 << 1));
     int32_t var2 = (var1 * (int32_t) par_T2) >> 11;
@@ -49,7 +153,7 @@
 
 int32_t BME680::getCompensateHumidity(int field)
 {
-    uint32_t v_uncomp_humidity_u32 = getHumidityData(field);
+    uint32_t v_uncomp_humidity_u32 = getUncompensatedHumidityData(field);
 
     int32_t temp_scaled = (t_fine * 5 + 128) >> 8;
     int32_t var1 = (int32_t)v_uncomp_humidity_u32 -
@@ -90,7 +194,7 @@
 
 int32_t BME680::getCompensatePressure(int field)
 {
-    uint32_t v_uncomp_pressure_u32 = getPressureData(field);
+    uint32_t v_uncomp_pressure_u32 = getUncompensatedPressureData(field);
 
     int32_t var1 = (((int32_t)t_fine) >> 1) - 64000;
     int32_t var2 = ((((var1 >> 2) * (var1 >> 2)) >> 11) * (int32_t)par_P6) >> 2;
@@ -156,7 +260,7 @@
 int32_t BME680::getCalculateGasInt(int field)
 {
     uint8_t gas_range_u8 = getGasResistanceRange(field);
-    uint16_t gas_adc_u16 = getGasResistanceData(field);
+    uint16_t gas_adc_u16 = getUncompensatedGasResistanceData(field);
 
     int64_t var1 = (int64_t)((1340 + (5 * (int64_t)range_switching_error)) *
                              ((int64_t)lookup_k1_range[gas_range_u8])) >> 16;
@@ -383,25 +487,25 @@
     return true;
 }
 
-uint32_t BME680::getPressureData(int field)
+uint32_t BME680::getUncompensatedPressureData(int field)
 {
     readRegister(0x1F + field * 0x11, 3);
     return (data[0] << 12) | (data[1] << 4) | (data[2] >> 4);
 }
 
-uint32_t BME680::getTemp1Data(int field)
+uint32_t BME680::getUncompensatedTemp1Data(int field)
 {
     readRegister(0x22 + field * 0x11, 3);
     return (data[0] << 12) | (data[1] << 4) | (data[2] >> 4);
 }
 
-uint32_t BME680::getHumidityData(int field)
+uint32_t BME680::getUncompensatedHumidityData(int field)
 {
     readRegister(0x25 + field * 0x11, 2);
     return (data[0] << 8) | data[1];
 }
 
-uint16_t BME680::getGasResistanceData(int field)
+uint16_t BME680::getUncompensatedGasResistanceData(int field)
 {
     readRegister(0x2A + field * 0x11, 2);
     return (data[0] << 2) | (data[1] >> 6);
--- a/BME680.h	Fri Jul 22 17:38:11 2016 +0000
+++ b/BME680.h	Wed Aug 03 15:07:42 2016 +0000
@@ -11,7 +11,7 @@
 #define FIXED_POINT_COMPENSATION
 
 // no idea what it is for
-#define HEATER_C1_ENABLE
+//#define HEATER_C1_ENABLE
 
 // Sensor Specific constants */
 #define BME680_SLEEP_MODE               (0x00)
@@ -32,7 +32,12 @@
 #define BME680_MIN_HUMIDITY_VALUE       (double)(0.0)
 #endif
 
-/// BME680 integrated environmental sensor. This API supports FIXED and FLOATING compenstion. By default it supports FIXED, to use FLOATING user need to disable "FIXED_POINT_COMPENSATION" in the BME680.h file.
+/**
+* !! MUST CALL init() FIRST !!
+* read the chip id and calibration data of the BME680 sensor
+* BME680 integrated environmental sensor. This API supports FIXED and FLOATING compenstion.
+* By default it supports FIXED, to use FLOATING user need to disable "FIXED_POINT_COMPENSATION" in the BME680.h file.
+*/
 class BME680
 {
 private:
@@ -124,13 +129,27 @@
 
 public:
 
-    /// NOT IMPLEMENTED
+    /**
+    * TPHG measurements are performed.
+    * continuously until mode change.
+    * Between each cycle, the sensor enters stand-by for a period of time according to the odr<3:0> control register.
+    * Gas sensor heater only operates during gas sub-measurement.
+    * 100 ms gas wait time, T:X2, P:X16, H:X1
+    */
     void setSequentialMode();
-    
-    /// NOT IMPLEMENTED
+
+    /**
+    * Single TPHG cycle is performed.
+    * Sensor automatically returns to sleep mode afterwards.
+    * Gas sensor heater only operates during gas sub-measureme.
+    */
     void setForcedMode();
-    
-    /// NOT IMPLEMENTED
+
+    /**
+    * TPHG measurements are performed continuously until mode change.
+    * No stand-by occurs between consecutive TPHG cycles.
+    * Gas sensor heater operates in parallel with TPH measurements.
+    */
     void setParallelMode();
 
     /*
@@ -368,7 +387,7 @@
     * Note: Only field0 will be updated in forced mode
     * @param field 0-2
     */
-    uint32_t getPressureData(int field);
+    uint32_t getUncompensatedPressureData(int field = 0);
 
     /**
     * [temp1_msb] [temp1_lsb] [temp1_xlsb]
@@ -381,7 +400,7 @@
     * Note: Only field0 will be updated in forced mode
     * @param field 0-2
     */
-    uint32_t getTemp1Data(int field);
+    uint32_t getUncompensatedTemp1Data(int field = 0);
 
     /**
     * [hum_msb] [hum_lsb]
@@ -394,7 +413,7 @@
     * Note: Only field0 will be updated in forced mode
     * @param field 0-2
     */
-    uint32_t getHumidityData(int field);
+    uint32_t getUncompensatedHumidityData(int field = 0);
 
     /**
     * [gas_rl]
@@ -407,7 +426,7 @@
     * Note: Only field0 will be updated in forced mode
     * @param field 0-2
     */
-    uint16_t getGasResistanceData(int field);
+    uint16_t getUncompensatedGasResistanceData(int field = 0);
 
     /**
     * [gas_range_rl]
@@ -421,7 +440,7 @@
     * Note: Only field0 will be updated in forced mode
     * @param field 0-2
     */
-    uint8_t getGasResistanceRange(int field);
+    uint8_t getGasResistanceRange(int field = 0);
 
 
     // STATUS #########################################################################
@@ -434,7 +453,7 @@
     * measurements. Availability of new (yet unread) results is indicated by new_data_0|1|2 flags.
     * @param field 0-2
     */
-    bool isNewData(int field);
+    bool isNewData(int field = 0);
 
     /**
     * [gas_measuring]
@@ -444,7 +463,7 @@
     * should not be changed when the device is measuring.
     * @param field 0-2
     */
-    bool isGasMeasuring(int field);
+    bool isGasMeasuring(int field = 0);
 
     /**
     * [measuring]
@@ -452,7 +471,7 @@
     * gas) is running and back to ‘0’ when the results have been transferred to the data registers.
     * @param field 0-2
     */
-    bool isMeasuring(int field);
+    bool isMeasuring(int field = 0);
 
     /**
     * [gas_meas_index_x]
@@ -462,7 +481,7 @@
     * to 9) is stored in gas_meas_index register.
     * @param field 0-2
     */
-    int getGasMeasurementIndex(int field);
+    int getGasMeasurementIndex(int field = 0);
 
     /**
     * [sub_meas_index_x]
@@ -473,7 +492,7 @@
     * Note: This index is incremented only if gas conversion is active.
     * @param field 0-2
     */
-    int getSubMeasurementIndex(int field);
+    int getSubMeasurementIndex(int field = 0);
 
     /**
     * [gas_valid_rl]
@@ -482,14 +501,14 @@
     * real gas conversion (i.e., not a dummy one) is indicated by the gas_valid_rl status register.
     * @param field 0-2
     */
-    bool isGasValid(int field);
+    bool isGasValid(int field = 0);
 
     /**
     * [heat_stab_rl]
     * Heater temperature stability for target heater resistance is indicated heat_stab_x status bits.
     * @param field 0-2
     */
-    bool isHeaterStable(int field);
+    bool isHeaterStable(int field = 0);
 
     // GAS CONTROL #########################################################################