Library for the BME220

Fork of BME680 by CHENGQI YANG

Committer:
UHSLMarcus
Date:
Wed Jan 25 12:06:36 2017 +0000
Revision:
6:37b94c473e8a
Parent:
3:5b39369b3b91
debug prints

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yangcq88517 0:c70b7ececf93 1 #ifndef UK_AC_HERTS_SMARTLAB_BME680
yangcq88517 0:c70b7ececf93 2 #define UK_AC_HERTS_SMARTLAB_BME680
yangcq88517 0:c70b7ececf93 3
yangcq88517 0:c70b7ececf93 4 #include "mbed.h"
yangcq88517 0:c70b7ececf93 5 #include "stdint.h"
UHSLMarcus 6:37b94c473e8a 6 #include "serial.h"
yangcq88517 0:c70b7ececf93 7
yangcq88517 0:c70b7ececf93 8 /*
yangcq88517 0:c70b7ececf93 9 * Use below macro for fixed Point Calculation
yangcq88517 0:c70b7ececf93 10 * else Floating Point calculation will be used
yangcq88517 0:c70b7ececf93 11 */
yangcq88517 0:c70b7ececf93 12 #define FIXED_POINT_COMPENSATION
yangcq88517 0:c70b7ececf93 13
yangcq88517 0:c70b7ececf93 14 // no idea what it is for
yangcq88517 1:85088a918342 15 //#define HEATER_C1_ENABLE
yangcq88517 0:c70b7ececf93 16
yangcq88517 0:c70b7ececf93 17 // Sensor Specific constants */
yangcq88517 0:c70b7ececf93 18 #define BME680_SLEEP_MODE (0x00)
yangcq88517 0:c70b7ececf93 19 #define BME680_FORCED_MODE (0x01)
yangcq88517 0:c70b7ececf93 20 #define BME680_PARALLEL_MODE (0x02)
yangcq88517 0:c70b7ececf93 21 #define BME680_SEQUENTIAL_MODE (0x03)
yangcq88517 0:c70b7ececf93 22 #define BME680_GAS_PROFILE_TEMPERATURE_MIN (200)
yangcq88517 0:c70b7ececf93 23 #define BME680_GAS_PROFILE_TEMPERATURE_MAX (400)
yangcq88517 0:c70b7ececf93 24 #define BME680_GAS_RANGE_RL_LENGTH (16)
yangcq88517 0:c70b7ececf93 25 #define BME680_SIGN_BIT_MASK (0x08)
yangcq88517 0:c70b7ececf93 26
yangcq88517 0:c70b7ececf93 27 #ifdef FIXED_POINT_COMPENSATION
yangcq88517 0:c70b7ececf93 28 //< Multiply by 1000, In order to convert float value into fixed point
yangcq88517 0:c70b7ececf93 29 #define BME680_MAX_HUMIDITY_VALUE (102400)
yangcq88517 0:c70b7ececf93 30 #define BME680_MIN_HUMIDITY_VALUE (0)
yangcq88517 0:c70b7ececf93 31 #else
yangcq88517 0:c70b7ececf93 32 #define BME680_MAX_HUMIDITY_VALUE (double)(100.0)
yangcq88517 0:c70b7ececf93 33 #define BME680_MIN_HUMIDITY_VALUE (double)(0.0)
yangcq88517 0:c70b7ececf93 34 #endif
yangcq88517 0:c70b7ececf93 35
yangcq88517 1:85088a918342 36 /**
yangcq88517 1:85088a918342 37 * !! MUST CALL init() FIRST !!
yangcq88517 1:85088a918342 38 * read the chip id and calibration data of the BME680 sensor
yangcq88517 1:85088a918342 39 * BME680 integrated environmental sensor. This API supports FIXED and FLOATING compenstion.
yangcq88517 1:85088a918342 40 * By default it supports FIXED, to use FLOATING user need to disable "FIXED_POINT_COMPENSATION" in the BME680.h file.
yangcq88517 1:85088a918342 41 */
yangcq88517 0:c70b7ececf93 42 class BME680
yangcq88517 0:c70b7ececf93 43 {
yangcq88517 0:c70b7ececf93 44 private:
yangcq88517 0:c70b7ececf93 45 static const int FREQUENCY_STANDARD = 100000;
yangcq88517 0:c70b7ececf93 46 static const int FREQUENCY_FULL = 400000;
yangcq88517 0:c70b7ececf93 47 static const int FREQUENCY_FAST = 1000000;
yangcq88517 0:c70b7ececf93 48 static const int FREQUENCY_HIGH = 3200000;
yangcq88517 0:c70b7ececf93 49
UHSLMarcus 2:d717e4ab624f 50 I2C * _i2c_bus;
yangcq88517 0:c70b7ececf93 51 int _addr;
yangcq88517 0:c70b7ececf93 52 uint8_t data[30];
yangcq88517 0:c70b7ececf93 53
yangcq88517 0:c70b7ececf93 54 //static const double const_array1[];
yangcq88517 0:c70b7ececf93 55 //static const double const_array2[];
yangcq88517 0:c70b7ececf93 56 static const uint64_t lookup_k1_range[];
yangcq88517 0:c70b7ececf93 57 static const uint64_t lookup_k2_range[];
yangcq88517 0:c70b7ececf93 58 static const double _lookup_k1_range[];
yangcq88517 0:c70b7ececf93 59 static const double _lookup_k2_range[];
yangcq88517 0:c70b7ececf93 60
yangcq88517 0:c70b7ececf93 61 /* For Calibration Data*/
yangcq88517 0:c70b7ececf93 62 static const int DIG_T2_LSB_REG = 1;
yangcq88517 0:c70b7ececf93 63 static const int DIG_T2_MSB_REG = 2;
yangcq88517 0:c70b7ececf93 64 static const int DIG_T3_REG = 3;
yangcq88517 0:c70b7ececf93 65 static const int DIG_P1_LSB_REG = 5;
yangcq88517 0:c70b7ececf93 66 static const int DIG_P1_MSB_REG = 6;
yangcq88517 0:c70b7ececf93 67 static const int DIG_P2_LSB_REG = 7;
yangcq88517 0:c70b7ececf93 68 static const int DIG_P2_MSB_REG = 8;
yangcq88517 0:c70b7ececf93 69 static const int DIG_P3_REG = 9;
yangcq88517 0:c70b7ececf93 70 static const int DIG_P4_LSB_REG = 11;
yangcq88517 0:c70b7ececf93 71 static const int DIG_P4_MSB_REG = 12;
yangcq88517 0:c70b7ececf93 72 static const int DIG_P5_LSB_REG = 13;
yangcq88517 0:c70b7ececf93 73 static const int DIG_P5_MSB_REG = 14;
yangcq88517 0:c70b7ececf93 74 static const int DIG_P7_REG = 15;
yangcq88517 0:c70b7ececf93 75 static const int DIG_P6_REG = 16;
yangcq88517 0:c70b7ececf93 76 static const int DIG_P8_LSB_REG = 19;
yangcq88517 0:c70b7ececf93 77 static const int DIG_P8_MSB_REG = 20;
yangcq88517 0:c70b7ececf93 78 static const int DIG_P9_LSB_REG = 21;
yangcq88517 0:c70b7ececf93 79 static const int DIG_P9_MSB_REG = 22;
yangcq88517 0:c70b7ececf93 80 static const int DIG_P10_REG = 23;
yangcq88517 0:c70b7ececf93 81 static const int DIG_H2_MSB_REG = 25;
yangcq88517 0:c70b7ececf93 82 static const int DIG_H2_LSB_REG = 26;
yangcq88517 0:c70b7ececf93 83 static const int DIG_H1_LSB_REG = 26;
yangcq88517 0:c70b7ececf93 84 static const int DIG_H1_MSB_REG = 27;
yangcq88517 0:c70b7ececf93 85 static const int DIG_H3_REG = 28;
yangcq88517 0:c70b7ececf93 86 static const int DIG_H4_REG = 29;
yangcq88517 0:c70b7ececf93 87 static const int DIG_H5_REG = 30;
yangcq88517 0:c70b7ececf93 88 static const int DIG_H6_REG = 31;
yangcq88517 0:c70b7ececf93 89 static const int DIG_H7_REG = 32;
yangcq88517 0:c70b7ececf93 90 static const int DIG_T1_LSB_REG = 33;
yangcq88517 0:c70b7ececf93 91 static const int DIG_T1_MSB_REG = 34;
yangcq88517 0:c70b7ececf93 92 static const int DIG_GH2_LSB_REG = 35;
yangcq88517 0:c70b7ececf93 93 static const int DIG_GH2_MSB_REG = 36;
yangcq88517 0:c70b7ececf93 94 static const int DIG_GH1_REG = 37;
yangcq88517 0:c70b7ececf93 95 static const int DIG_GH3_REG = 38;
yangcq88517 0:c70b7ececf93 96
yangcq88517 0:c70b7ececf93 97 static const int BME680_BIT_MASK_H1_DATA = 0x0F;
yangcq88517 0:c70b7ececf93 98
yangcq88517 0:c70b7ececf93 99 int8_t par_T3;/**<calibration T3 data*/
yangcq88517 0:c70b7ececf93 100 int8_t par_P3;/**<calibration P3 data*/
yangcq88517 0:c70b7ececf93 101 int8_t par_P6;/**<calibration P6 data*/
yangcq88517 0:c70b7ececf93 102 int8_t par_P7;/**<calibration P7 data*/
yangcq88517 0:c70b7ececf93 103 uint8_t par_P10;/**<calibration P10 data*/
yangcq88517 0:c70b7ececf93 104 int8_t par_H3;/**<calibration H3 data*/
yangcq88517 0:c70b7ececf93 105 int8_t par_H4;/**<calibration H4 data*/
yangcq88517 0:c70b7ececf93 106 int8_t par_H5;/**<calibration H5 data*/
yangcq88517 0:c70b7ececf93 107 uint8_t par_H6;/**<calibration H6 data*/
yangcq88517 0:c70b7ececf93 108 int8_t par_H7;/**<calibration H7 data*/
yangcq88517 0:c70b7ececf93 109 int8_t par_GH1;/**<calibration GH1 data*/
yangcq88517 0:c70b7ececf93 110 uint8_t res_heat_range;/**<resistance calculation*/
yangcq88517 0:c70b7ececf93 111 int8_t res_heat_val; /**<correction factor*/
yangcq88517 0:c70b7ececf93 112 int8_t range_switching_error;/**<range switching error*/
yangcq88517 0:c70b7ececf93 113 int16_t par_GH2;/**<calibration GH2 data*/
yangcq88517 0:c70b7ececf93 114 uint16_t par_T1;/**<calibration T1 data*/
yangcq88517 0:c70b7ececf93 115 int16_t par_T2;/**<calibration T2 data*/
yangcq88517 0:c70b7ececf93 116 uint16_t par_P1;/**<calibration P1 data*/
yangcq88517 0:c70b7ececf93 117 int16_t par_P2;/**<calibration P2 data*/
yangcq88517 0:c70b7ececf93 118 int16_t par_P4;/**<calibration P4 data*/
yangcq88517 0:c70b7ececf93 119 int16_t par_P5;/**<calibration P5 data*/
yangcq88517 0:c70b7ececf93 120 int16_t par_P8;/**<calibration P8 data*/
yangcq88517 0:c70b7ececf93 121 int16_t par_P9;/**<calibration P9 data*/
yangcq88517 0:c70b7ececf93 122 uint16_t par_H1;/**<calibration H1 data*/
yangcq88517 0:c70b7ececf93 123 uint16_t par_H2;/**<calibration H2 data*/
yangcq88517 0:c70b7ececf93 124 int32_t t_fine;/**<calibration T_FINE data*/
yangcq88517 0:c70b7ececf93 125 int8_t par_GH3;/**<calibration GH3 data*/
yangcq88517 0:c70b7ececf93 126
yangcq88517 0:c70b7ececf93 127 void readRegister(int reg, int size = 1);
yangcq88517 0:c70b7ececf93 128
yangcq88517 0:c70b7ececf93 129 void writeRegister(int reg, int value);
yangcq88517 0:c70b7ececf93 130
yangcq88517 0:c70b7ececf93 131 public:
yangcq88517 0:c70b7ececf93 132
yangcq88517 1:85088a918342 133 /**
yangcq88517 1:85088a918342 134 * TPHG measurements are performed.
yangcq88517 1:85088a918342 135 * continuously until mode change.
yangcq88517 1:85088a918342 136 * Between each cycle, the sensor enters stand-by for a period of time according to the odr<3:0> control register.
yangcq88517 1:85088a918342 137 * Gas sensor heater only operates during gas sub-measurement.
yangcq88517 1:85088a918342 138 * 100 ms gas wait time, T:X2, P:X16, H:X1
yangcq88517 1:85088a918342 139 */
yangcq88517 0:c70b7ececf93 140 void setSequentialMode();
yangcq88517 1:85088a918342 141
yangcq88517 1:85088a918342 142 /**
yangcq88517 1:85088a918342 143 * Single TPHG cycle is performed.
yangcq88517 1:85088a918342 144 * Sensor automatically returns to sleep mode afterwards.
yangcq88517 1:85088a918342 145 * Gas sensor heater only operates during gas sub-measureme.
yangcq88517 1:85088a918342 146 */
yangcq88517 0:c70b7ececf93 147 void setForcedMode();
yangcq88517 1:85088a918342 148
yangcq88517 1:85088a918342 149 /**
yangcq88517 1:85088a918342 150 * TPHG measurements are performed continuously until mode change.
yangcq88517 1:85088a918342 151 * No stand-by occurs between consecutive TPHG cycles.
yangcq88517 1:85088a918342 152 * Gas sensor heater operates in parallel with TPH measurements.
yangcq88517 1:85088a918342 153 */
yangcq88517 0:c70b7ececf93 154 void setParallelMode();
yangcq88517 0:c70b7ececf93 155
UHSLMarcus 3:5b39369b3b91 156 /**
UHSLMarcus 3:5b39369b3b91 157 * Constructor
UHSLMarcus 2:d717e4ab624f 158 * @param i2c I2C interface used for communication
yangcq88517 0:c70b7ececf93 159 * @param SDO Slave address LSB (High->true, Low->false)
yangcq88517 0:c70b7ececf93 160 */
UHSLMarcus 2:d717e4ab624f 161 BME680(I2C * i2c, bool SDO);
yangcq88517 0:c70b7ececf93 162
yangcq88517 0:c70b7ececf93 163 /**
yangcq88517 0:c70b7ececf93 164 * !! MUST CALL THIS FIRST !!
yangcq88517 0:c70b7ececf93 165 * read the chip id and calibration data of the BME680 sensor
yangcq88517 0:c70b7ececf93 166 */
yangcq88517 0:c70b7ececf93 167 bool init();
yangcq88517 0:c70b7ececf93 168 // DATA #########################################################################
yangcq88517 0:c70b7ececf93 169
yangcq88517 0:c70b7ececf93 170 #ifdef FIXED_POINT_COMPENSATION
yangcq88517 0:c70b7ececf93 171 /**
yangcq88517 0:c70b7ececf93 172 * This function is used to convert the uncompensated
yangcq88517 0:c70b7ececf93 173 * temperature data to compensated temperature data using
yangcq88517 0:c70b7ececf93 174 * compensation formula(integer version)
yangcq88517 0:c70b7ececf93 175 * @note Returns the value in 0.01 degree Centigrade
yangcq88517 0:c70b7ececf93 176 * Output value of "5123" equals 51.23 DegC.
yangcq88517 0:c70b7ececf93 177 *
yangcq88517 0:c70b7ececf93 178 * @param field 0-2
yangcq88517 0:c70b7ececf93 179 *
yangcq88517 0:c70b7ececf93 180 * @return Returns the compensated temperature data
yangcq88517 0:c70b7ececf93 181 *
yangcq88517 0:c70b7ececf93 182 */
yangcq88517 0:c70b7ececf93 183 int32_t getCompensatedTemperature(int field = 0);
yangcq88517 0:c70b7ececf93 184
yangcq88517 0:c70b7ececf93 185 /**
yangcq88517 0:c70b7ececf93 186 * Reads actual temperature from uncompensated temperature
yangcq88517 0:c70b7ececf93 187 * @note Returns the value with 500LSB/DegC centred around 24 DegC
yangcq88517 0:c70b7ececf93 188 * output value of "5123" equals(5123/500)+24 = 34.246DegC
yangcq88517 0:c70b7ececf93 189 *
yangcq88517 0:c70b7ececf93 190 *
yangcq88517 0:c70b7ececf93 191 * @param v_uncomp_temperature_u32: value of uncompensated temperature
yangcq88517 0:c70b7ececf93 192 * @param bme680: structure pointer.
yangcq88517 0:c70b7ececf93 193 *
yangcq88517 0:c70b7ececf93 194 *
yangcq88517 0:c70b7ececf93 195 * @return Return the actual temperature as s16 output
yangcq88517 0:c70b7ececf93 196 *
yangcq88517 0:c70b7ececf93 197 */
yangcq88517 0:c70b7ececf93 198 int16_t getTemperatureInt(int field = 0);
yangcq88517 0:c70b7ececf93 199
yangcq88517 0:c70b7ececf93 200 /**
yangcq88517 0:c70b7ececf93 201 * @brief This function is used to convert the uncompensated
yangcq88517 0:c70b7ececf93 202 * humidity data to compensated humidity data using
yangcq88517 0:c70b7ececf93 203 * compensation formula(integer version)
yangcq88517 0:c70b7ececf93 204 *
yangcq88517 0:c70b7ececf93 205 * @note Returns the value in %rH as unsigned 32bit integer
yangcq88517 0:c70b7ececf93 206 * in Q22.10 format(22 integer 10 fractional bits).
yangcq88517 0:c70b7ececf93 207 * @note An output value of 42313
yangcq88517 0:c70b7ececf93 208 * represents 42313 / 1024 = 41.321 %rH
yangcq88517 0:c70b7ececf93 209 *
yangcq88517 0:c70b7ececf93 210 *
yangcq88517 0:c70b7ececf93 211 *
yangcq88517 0:c70b7ececf93 212 * @param v_uncomp_humidity_u32: value of uncompensated humidity
yangcq88517 0:c70b7ececf93 213 * @param bme680: structure pointer.
yangcq88517 0:c70b7ececf93 214 *
yangcq88517 0:c70b7ececf93 215 * @return Return the compensated humidity data
yangcq88517 0:c70b7ececf93 216 *
yangcq88517 0:c70b7ececf93 217 */
yangcq88517 0:c70b7ececf93 218 int32_t getCompensateHumidity(int field = 0);
yangcq88517 0:c70b7ececf93 219
yangcq88517 0:c70b7ececf93 220 /**
yangcq88517 0:c70b7ececf93 221 * @brief Reads actual humidity from uncompensated humidity
yangcq88517 0:c70b7ececf93 222 * @note Returns the value in %rH as unsigned 16bit integer
yangcq88517 0:c70b7ececf93 223 * @note An output value of 42313
yangcq88517 0:c70b7ececf93 224 * represents 42313/512 = 82.643 %rH
yangcq88517 0:c70b7ececf93 225 *
yangcq88517 0:c70b7ececf93 226 *
yangcq88517 0:c70b7ececf93 227 *
yangcq88517 0:c70b7ececf93 228 * @param v_uncomp_humidity_u32: value of uncompensated humidity
yangcq88517 0:c70b7ececf93 229 * @param bme680: structure pointer.
yangcq88517 0:c70b7ececf93 230 *
yangcq88517 0:c70b7ececf93 231 * @return Return the actual relative humidity output as u16
yangcq88517 0:c70b7ececf93 232 *
yangcq88517 0:c70b7ececf93 233 */
yangcq88517 0:c70b7ececf93 234 uint16_t getHumidityInt(int field = 0);
yangcq88517 0:c70b7ececf93 235
yangcq88517 0:c70b7ececf93 236 /**
yangcq88517 0:c70b7ececf93 237 * @brief This function is used to convert the uncompensated
yangcq88517 0:c70b7ececf93 238 * pressure data to compensated pressure data data using
yangcq88517 0:c70b7ececf93 239 * compensation formula(integer version)
yangcq88517 0:c70b7ececf93 240 *
yangcq88517 0:c70b7ececf93 241 * @note Returns the value in Pascal(Pa)
yangcq88517 0:c70b7ececf93 242 * Output value of "96386" equals 96386 Pa =
yangcq88517 0:c70b7ececf93 243 * 963.86 hPa = 963.86 millibar
yangcq88517 0:c70b7ececf93 244 *
yangcq88517 0:c70b7ececf93 245 *
yangcq88517 0:c70b7ececf93 246 *
yangcq88517 0:c70b7ececf93 247 * @param v_uncomp_pressure_u32 : value of uncompensated pressure
yangcq88517 0:c70b7ececf93 248 * @param bme680: structure pointer.
yangcq88517 0:c70b7ececf93 249 *
yangcq88517 0:c70b7ececf93 250 * @return Return the compensated pressure data
yangcq88517 0:c70b7ececf93 251 *
yangcq88517 0:c70b7ececf93 252 */
yangcq88517 0:c70b7ececf93 253 int32_t getCompensatePressure(int field = 0);
yangcq88517 0:c70b7ececf93 254
yangcq88517 0:c70b7ececf93 255 /**
yangcq88517 0:c70b7ececf93 256 * @brief Reads actual pressure from uncompensated pressure
yangcq88517 0:c70b7ececf93 257 * @note Returns the value in Pa.
yangcq88517 0:c70b7ececf93 258 * @note Output value of "12337434"
yangcq88517 0:c70b7ececf93 259 * @note represents 12337434 / 128 = 96386.2 Pa = 963.862 hPa
yangcq88517 0:c70b7ececf93 260 *
yangcq88517 0:c70b7ececf93 261 *
yangcq88517 0:c70b7ececf93 262 *
yangcq88517 0:c70b7ececf93 263 * @param v_uncomp_pressure_u32 : value of uncompensated pressure
yangcq88517 0:c70b7ececf93 264 * @param bme680: structure pointer.
yangcq88517 0:c70b7ececf93 265 *
yangcq88517 0:c70b7ececf93 266 * @return the actual pressure in u32
yangcq88517 0:c70b7ececf93 267 *
yangcq88517 0:c70b7ececf93 268 */
yangcq88517 0:c70b7ececf93 269 uint32_t getPressureInt(int field = 0);
yangcq88517 0:c70b7ececf93 270
yangcq88517 0:c70b7ececf93 271 /**
yangcq88517 0:c70b7ececf93 272 * @brief This function is used to convert temperature to resistance
yangcq88517 0:c70b7ececf93 273 * using the integer compensation formula
yangcq88517 0:c70b7ececf93 274 *
yangcq88517 0:c70b7ececf93 275 * @param heater_temp_u16: The value of heater temperature
yangcq88517 0:c70b7ececf93 276 * @param ambient_temp_s16: The value of ambient temperature
yangcq88517 0:c70b7ececf93 277 * @param bme680: structure pointer.
yangcq88517 0:c70b7ececf93 278 *
yangcq88517 0:c70b7ececf93 279 * @return calculated resistance from temperature
yangcq88517 0:c70b7ececf93 280 *
yangcq88517 0:c70b7ececf93 281 *
yangcq88517 0:c70b7ececf93 282 *
yangcq88517 0:c70b7ececf93 283 */
yangcq88517 0:c70b7ececf93 284 uint8_t convertTemperatureResistanceInt(uint16_t heater, int16_t ambient);
yangcq88517 0:c70b7ececf93 285
yangcq88517 0:c70b7ececf93 286
yangcq88517 0:c70b7ececf93 287 /**
yangcq88517 0:c70b7ececf93 288 * @brief This function is used to convert uncompensated gas data to
yangcq88517 0:c70b7ececf93 289 * compensated gas data using compensation formula(integer version)
yangcq88517 0:c70b7ececf93 290 *
yangcq88517 0:c70b7ececf93 291 * @param gas_adc_u16: The value of gas resistance calculated
yangcq88517 0:c70b7ececf93 292 * using temperature
yangcq88517 0:c70b7ececf93 293 * @param gas_range_u8: The value of gas range form register value
yangcq88517 0:c70b7ececf93 294 * @param bme680: structure pointer.
yangcq88517 0:c70b7ececf93 295 *
yangcq88517 0:c70b7ececf93 296 * @return calculated compensated gas from compensation formula
yangcq88517 0:c70b7ececf93 297 * @retval compensated gas data
yangcq88517 0:c70b7ececf93 298 *
yangcq88517 0:c70b7ececf93 299 *
yangcq88517 0:c70b7ececf93 300 */
yangcq88517 0:c70b7ececf93 301 int32_t getCalculateGasInt(int field = 0);
yangcq88517 0:c70b7ececf93 302
yangcq88517 0:c70b7ececf93 303 #else
yangcq88517 0:c70b7ececf93 304 /**
yangcq88517 0:c70b7ececf93 305 * This function used to convert temperature data
yangcq88517 0:c70b7ececf93 306 * to uncompensated temperature data using compensation formula
yangcq88517 0:c70b7ececf93 307 * @note returns the value in Degree centigrade
yangcq88517 0:c70b7ececf93 308 * @note Output value of "51.23" equals 51.23 DegC.
yangcq88517 0:c70b7ececf93 309 * @param field 0-2
yangcq88517 0:c70b7ececf93 310 * @return Return the actual temperature in floating point
yangcq88517 0:c70b7ececf93 311 */
yangcq88517 0:c70b7ececf93 312 double getTemperatureDouble(int field = 0);
yangcq88517 0:c70b7ececf93 313
yangcq88517 0:c70b7ececf93 314 /**
yangcq88517 0:c70b7ececf93 315 * @brief This function is used to convert the uncompensated
yangcq88517 0:c70b7ececf93 316 * humidity data to compensated humidity data data using
yangcq88517 0:c70b7ececf93 317 * compensation formula
yangcq88517 0:c70b7ececf93 318 * @note returns the value in relative humidity (%rH)
yangcq88517 0:c70b7ececf93 319 * @note Output value of "42.12" equals 42.12 %rH
yangcq88517 0:c70b7ececf93 320 *
yangcq88517 0:c70b7ececf93 321 * @param uncom_humidity_u16 : value of uncompensated humidity
yangcq88517 0:c70b7ececf93 322 * @param comp_temperature : value of compensated temperature
yangcq88517 0:c70b7ececf93 323 * @param bme680: structure pointer.
yangcq88517 0:c70b7ececf93 324 *
yangcq88517 0:c70b7ececf93 325 *
yangcq88517 0:c70b7ececf93 326 * @return Return the compensated humidity data in floating point
yangcq88517 0:c70b7ececf93 327 *
yangcq88517 0:c70b7ececf93 328 */
yangcq88517 0:c70b7ececf93 329 double getHumidityDouble(int field = 0);
yangcq88517 0:c70b7ececf93 330
yangcq88517 0:c70b7ececf93 331 /**
yangcq88517 0:c70b7ececf93 332 * @brief This function is used to convert the uncompensated
yangcq88517 0:c70b7ececf93 333 * pressure data to compensated data using compensation formula
yangcq88517 0:c70b7ececf93 334 * @note Returns pressure in Pa as double.
yangcq88517 0:c70b7ececf93 335 * @note Output value of "96386.2"
yangcq88517 0:c70b7ececf93 336 * equals 96386.2 Pa = 963.862 hPa.
yangcq88517 0:c70b7ececf93 337 *
yangcq88517 0:c70b7ececf93 338 *
yangcq88517 0:c70b7ececf93 339 * @param uncom_pressure_u32 : value of uncompensated pressure
yangcq88517 0:c70b7ececf93 340 * @param bme680: structure pointer.
yangcq88517 0:c70b7ececf93 341 *
yangcq88517 0:c70b7ececf93 342 * @return Return the compensated pressure data in floating point
yangcq88517 0:c70b7ececf93 343 *
yangcq88517 0:c70b7ececf93 344 */
yangcq88517 0:c70b7ececf93 345 double getPressureDouble(int field = 0);
yangcq88517 0:c70b7ececf93 346
yangcq88517 0:c70b7ececf93 347 /**
yangcq88517 0:c70b7ececf93 348 * @brief This function is used to convert temperature to resistance
yangcq88517 0:c70b7ececf93 349 * using the compensation formula
yangcq88517 0:c70b7ececf93 350 *
yangcq88517 0:c70b7ececf93 351 * @param heater_temp_u16: The value of heater temperature
yangcq88517 0:c70b7ececf93 352 * @param ambient_temp_s16: The value of ambient temperature
yangcq88517 0:c70b7ececf93 353 * @param bme680: structure pointer.
yangcq88517 0:c70b7ececf93 354 *
yangcq88517 0:c70b7ececf93 355 * @return calculated resistance from temperature
yangcq88517 0:c70b7ececf93 356 *
yangcq88517 0:c70b7ececf93 357 *
yangcq88517 0:c70b7ececf93 358 *
yangcq88517 0:c70b7ececf93 359 */
yangcq88517 0:c70b7ececf93 360 double convertTemperatureResistanceDouble(uint16_t heater, int16_t ambient);
yangcq88517 0:c70b7ececf93 361
yangcq88517 0:c70b7ececf93 362 /**
yangcq88517 0:c70b7ececf93 363 * @brief This function is used to convert uncompensated gas data to
yangcq88517 0:c70b7ececf93 364 * compensated gas data using compensation formula
yangcq88517 0:c70b7ececf93 365 *
yangcq88517 0:c70b7ececf93 366 * @param gas_adc_u16: The value of gas resistance calculated
yangcq88517 0:c70b7ececf93 367 * using temperature
yangcq88517 0:c70b7ececf93 368 * @param gas_range_u8: The value of gas range form register value
yangcq88517 0:c70b7ececf93 369 * @param bme680: structure pointer.
yangcq88517 0:c70b7ececf93 370 *
yangcq88517 0:c70b7ececf93 371 * @return calculated compensated gas from compensation formula
yangcq88517 0:c70b7ececf93 372 * @retval compensated gas
yangcq88517 0:c70b7ececf93 373 *
yangcq88517 0:c70b7ececf93 374 *
yangcq88517 0:c70b7ececf93 375 */
yangcq88517 0:c70b7ececf93 376 double getCalculateGasDouble(int field = 0);
yangcq88517 0:c70b7ececf93 377 #endif
yangcq88517 0:c70b7ececf93 378
yangcq88517 0:c70b7ececf93 379
yangcq88517 0:c70b7ececf93 380 /**
yangcq88517 0:c70b7ececf93 381 * [press_msb] [press_lsb] [press_xlsb]
yangcq88517 0:c70b7ececf93 382 * Pressure, temperature, humidity and gas data of BME680 are stored in 3 data field registers
yangcq88517 0:c70b7ececf93 383 * named field0, field1, and field2. The data fields are updated sequentially and always results of
yangcq88517 0:c70b7ececf93 384 * the three latest measurements are available for the user; if the last but one conversion was written
yangcq88517 0:c70b7ececf93 385 * to field number k, the current conversion results are written to field with number (k+1) mod 3. All
yangcq88517 0:c70b7ececf93 386 * data outputs from data fields are buffered using shadowing registers to ensure keeping stable
yangcq88517 0:c70b7ececf93 387 * data if update of the data registers comes simultaneously with serial interface reading out.
yangcq88517 0:c70b7ececf93 388 * Note: Only field0 will be updated in forced mode
yangcq88517 0:c70b7ececf93 389 * @param field 0-2
yangcq88517 0:c70b7ececf93 390 */
yangcq88517 1:85088a918342 391 uint32_t getUncompensatedPressureData(int field = 0);
yangcq88517 0:c70b7ececf93 392
yangcq88517 0:c70b7ececf93 393 /**
yangcq88517 0:c70b7ececf93 394 * [temp1_msb] [temp1_lsb] [temp1_xlsb]
yangcq88517 0:c70b7ececf93 395 * Pressure, temperature, humidity and gas data of BME680 are stored in 3 data field registers
yangcq88517 0:c70b7ececf93 396 * named field0, field1, and field2. The data fields are updated sequentially and always results of
yangcq88517 0:c70b7ececf93 397 * the three latest measurements are available for the user; if the last but one conversion was written
yangcq88517 0:c70b7ececf93 398 * to field number k, the current conversion results are written to field with number (k+1) mod 3. All
yangcq88517 0:c70b7ececf93 399 * data outputs from data fields are buffered using shadowing registers to ensure keeping stable
yangcq88517 0:c70b7ececf93 400 * data if update of the data registers comes simultaneously with serial interface reading out.
yangcq88517 0:c70b7ececf93 401 * Note: Only field0 will be updated in forced mode
yangcq88517 0:c70b7ececf93 402 * @param field 0-2
yangcq88517 0:c70b7ececf93 403 */
yangcq88517 1:85088a918342 404 uint32_t getUncompensatedTemp1Data(int field = 0);
yangcq88517 0:c70b7ececf93 405
yangcq88517 0:c70b7ececf93 406 /**
yangcq88517 0:c70b7ececf93 407 * [hum_msb] [hum_lsb]
yangcq88517 0:c70b7ececf93 408 * Pressure, temperature, humidity and gas data of BME680 are stored in 3 data field registers
yangcq88517 0:c70b7ececf93 409 * named field0, field1, and field2. The data fields are updated sequentially and always results of
yangcq88517 0:c70b7ececf93 410 * the three latest measurements are available for the user; if the last but one conversion was written
yangcq88517 0:c70b7ececf93 411 * to field number k, the current conversion results are written to field with number (k+1) mod 3. All
yangcq88517 0:c70b7ececf93 412 * data outputs from data fields are buffered using shadowing registers to ensure keeping stable
yangcq88517 0:c70b7ececf93 413 * data if update of the data registers comes simultaneously with serial interface reading out.
yangcq88517 0:c70b7ececf93 414 * Note: Only field0 will be updated in forced mode
yangcq88517 0:c70b7ececf93 415 * @param field 0-2
yangcq88517 0:c70b7ececf93 416 */
yangcq88517 1:85088a918342 417 uint32_t getUncompensatedHumidityData(int field = 0);
yangcq88517 0:c70b7ececf93 418
yangcq88517 0:c70b7ececf93 419 /**
yangcq88517 0:c70b7ececf93 420 * [gas_rl]
yangcq88517 0:c70b7ececf93 421 * Pressure, temperature, humidity and gas data of BME680 are stored in 3 data field registers
yangcq88517 0:c70b7ececf93 422 * named field0, field1, and field2. The data fields are updated sequentially and always results of
yangcq88517 0:c70b7ececf93 423 * the three latest measurements are available for the user; if the last but one conversion was written
yangcq88517 0:c70b7ececf93 424 * to field number k, the current conversion results are written to field with number (k+1) mod 3. All
yangcq88517 0:c70b7ececf93 425 * data outputs from data fields are buffered using shadowing registers to ensure keeping stable
yangcq88517 0:c70b7ececf93 426 * data if update of the data registers comes simultaneously with serial interface reading out.
yangcq88517 0:c70b7ececf93 427 * Note: Only field0 will be updated in forced mode
yangcq88517 0:c70b7ececf93 428 * @param field 0-2
yangcq88517 0:c70b7ececf93 429 */
yangcq88517 1:85088a918342 430 uint16_t getUncompensatedGasResistanceData(int field = 0);
yangcq88517 0:c70b7ececf93 431
yangcq88517 0:c70b7ececf93 432 /**
yangcq88517 0:c70b7ececf93 433 * [gas_range_rl]
yangcq88517 0:c70b7ececf93 434 * Pressure, temperature, humidity and gas data of BME680 are stored in 3 data field registers
yangcq88517 0:c70b7ececf93 435 * named field0, field1, and field2. The data fields are updated sequentially and always results of
yangcq88517 0:c70b7ececf93 436 * the three latest measurements are available for the user; if the last but one conversion was written
yangcq88517 0:c70b7ececf93 437 * to field number k, the current conversion results are written to field with number (k+1) mod 3. All
yangcq88517 0:c70b7ececf93 438 * data outputs from data fields are buffered using shadowing registers to ensure keeping stable
yangcq88517 0:c70b7ececf93 439 * data if update of the data registers comes simultaneously with serial interface reading out.
yangcq88517 0:c70b7ececf93 440 * Contains ADC range of measured gas resistance
yangcq88517 0:c70b7ececf93 441 * Note: Only field0 will be updated in forced mode
yangcq88517 0:c70b7ececf93 442 * @param field 0-2
yangcq88517 0:c70b7ececf93 443 */
yangcq88517 1:85088a918342 444 uint8_t getGasResistanceRange(int field = 0);
yangcq88517 0:c70b7ececf93 445
yangcq88517 0:c70b7ececf93 446
yangcq88517 0:c70b7ececf93 447 // STATUS #########################################################################
yangcq88517 0:c70b7ececf93 448
yangcq88517 0:c70b7ececf93 449 /**
yangcq88517 0:c70b7ececf93 450 * [new_data_x]
yangcq88517 0:c70b7ececf93 451 * The measured data are stored into the output data registers at the end of each TPHG conversion
yangcq88517 0:c70b7ececf93 452 * phase along with status flags and index of measurement. The part of the register map for output
yangcq88517 0:c70b7ececf93 453 * data storage is composed of 3 data fields (TPHG data field0|1|2)) keeping results from the last 3
yangcq88517 0:c70b7ececf93 454 * measurements. Availability of new (yet unread) results is indicated by new_data_0|1|2 flags.
yangcq88517 0:c70b7ececf93 455 * @param field 0-2
yangcq88517 0:c70b7ececf93 456 */
yangcq88517 1:85088a918342 457 bool isNewData(int field = 0);
yangcq88517 0:c70b7ececf93 458
yangcq88517 0:c70b7ececf93 459 /**
yangcq88517 0:c70b7ececf93 460 * [gas_measuring]
yangcq88517 0:c70b7ececf93 461 * Measuring bit is set to “1‟ only during gas measurements, goes to “0‟ as soon as measurement
yangcq88517 0:c70b7ececf93 462 * is completed and data transferred to data registers. The registers storing the configuration values
yangcq88517 0:c70b7ececf93 463 * for the measurement (gas_wait_shared, gas_wait_x, res_heat_x, idac_heat_x, image registers)
yangcq88517 0:c70b7ececf93 464 * should not be changed when the device is measuring.
yangcq88517 0:c70b7ececf93 465 * @param field 0-2
yangcq88517 0:c70b7ececf93 466 */
yangcq88517 1:85088a918342 467 bool isGasMeasuring(int field = 0);
yangcq88517 0:c70b7ececf93 468
yangcq88517 0:c70b7ececf93 469 /**
yangcq88517 0:c70b7ececf93 470 * [measuring]
yangcq88517 0:c70b7ececf93 471 * Measuring status will be set to ‘1’ whenever a conversion (Pressure, Temperature, humidity &
yangcq88517 0:c70b7ececf93 472 * gas) is running and back to ‘0’ when the results have been transferred to the data registers.
yangcq88517 0:c70b7ececf93 473 * @param field 0-2
yangcq88517 0:c70b7ececf93 474 */
yangcq88517 1:85088a918342 475 bool isMeasuring(int field = 0);
yangcq88517 0:c70b7ececf93 476
yangcq88517 0:c70b7ececf93 477 /**
yangcq88517 0:c70b7ececf93 478 * [gas_meas_index_x]
yangcq88517 0:c70b7ececf93 479 * User can program a sequence of up to 10 conversions by setting nb_conv<3:0>. Each conversion
yangcq88517 0:c70b7ececf93 480 * has its own heater resistance target but 3 field registers to store conversion results. The actual
yangcq88517 0:c70b7ececf93 481 * gas conversion number in the measurement sequence (up to 10 conversions numbered from 0
yangcq88517 0:c70b7ececf93 482 * to 9) is stored in gas_meas_index register.
yangcq88517 0:c70b7ececf93 483 * @param field 0-2
yangcq88517 0:c70b7ececf93 484 */
yangcq88517 1:85088a918342 485 int getGasMeasurementIndex(int field = 0);
yangcq88517 0:c70b7ececf93 486
yangcq88517 0:c70b7ececf93 487 /**
yangcq88517 0:c70b7ececf93 488 * [sub_meas_index_x]
yangcq88517 0:c70b7ececf93 489 * sub_meas_index_x registers form “virtual time sensor” and contain a snapshot of the internal 8
yangcq88517 0:c70b7ececf93 490 * bit conversion counter. Conversion counter is incremented with each TPHG conversion; the
yangcq88517 0:c70b7ececf93 491 * counter thus contains the number of conversions modulo 256 executed since the last change of
yangcq88517 0:c70b7ececf93 492 * device mode.
yangcq88517 0:c70b7ececf93 493 * Note: This index is incremented only if gas conversion is active.
yangcq88517 0:c70b7ececf93 494 * @param field 0-2
yangcq88517 0:c70b7ececf93 495 */
yangcq88517 1:85088a918342 496 int getSubMeasurementIndex(int field = 0);
yangcq88517 0:c70b7ececf93 497
yangcq88517 0:c70b7ececf93 498 /**
yangcq88517 0:c70b7ececf93 499 * [gas_valid_rl]
yangcq88517 0:c70b7ececf93 500 * In parallel mode, each TPHG sequence contains a gas measurement slot, either a real one which
yangcq88517 0:c70b7ececf93 501 * result is used or a dummy one to keep a constant sampling rate and predictable device timing. A
yangcq88517 0:c70b7ececf93 502 * real gas conversion (i.e., not a dummy one) is indicated by the gas_valid_rl status register.
yangcq88517 0:c70b7ececf93 503 * @param field 0-2
yangcq88517 0:c70b7ececf93 504 */
yangcq88517 1:85088a918342 505 bool isGasValid(int field = 0);
yangcq88517 0:c70b7ececf93 506
yangcq88517 0:c70b7ececf93 507 /**
yangcq88517 0:c70b7ececf93 508 * [heat_stab_rl]
yangcq88517 0:c70b7ececf93 509 * Heater temperature stability for target heater resistance is indicated heat_stab_x status bits.
yangcq88517 0:c70b7ececf93 510 * @param field 0-2
yangcq88517 0:c70b7ececf93 511 */
yangcq88517 1:85088a918342 512 bool isHeaterStable(int field = 0);
yangcq88517 0:c70b7ececf93 513
yangcq88517 0:c70b7ececf93 514 // GAS CONTROL #########################################################################
yangcq88517 0:c70b7ececf93 515
yangcq88517 0:c70b7ececf93 516 /**
yangcq88517 0:c70b7ececf93 517 * [idac_heat_x]
yangcq88517 0:c70b7ececf93 518 * BME680 contains a heater control block that will inject enough current into the heater resistance
yangcq88517 0:c70b7ececf93 519 * to achieve the requested heater temperature. There is a control loop which periodically measures
yangcq88517 0:c70b7ececf93 520 * heater resistance value and adapts the value of current injected from a DAC.
yangcq88517 0:c70b7ececf93 521 * BME680 heater operation could be speeded up by setting an initial heater current for a target
yangcq88517 0:c70b7ececf93 522 * heater temperature by using register idac_heat_x<7:0>. This step is optional since the control
yangcq88517 0:c70b7ececf93 523 * loop will find the current after a few iterations anyway.
yangcq88517 0:c70b7ececf93 524 * Current injected to the heater in mA = (idac_heat_7_1 + 1) / 8
yangcq88517 0:c70b7ececf93 525 * Where: idac_heat_7_1 = decimal value stored in idac_heat<7:1> (unsigned, value from 0 to 127)
yangcq88517 0:c70b7ececf93 526 * @param setPoint 0-9
yangcq88517 0:c70b7ececf93 527 */
yangcq88517 0:c70b7ececf93 528 uint8_t getHeaterCurrent(int setPoint);
yangcq88517 0:c70b7ececf93 529
yangcq88517 0:c70b7ececf93 530 /**
yangcq88517 0:c70b7ececf93 531 * [idac_heat_x]
yangcq88517 0:c70b7ececf93 532 * BME680 contains a heater control block that will inject enough current into the heater resistance
yangcq88517 0:c70b7ececf93 533 * to achieve the requested heater temperature. There is a control loop which periodically measures
yangcq88517 0:c70b7ececf93 534 * heater resistance value and adapts the value of current injected from a DAC.
yangcq88517 0:c70b7ececf93 535 * BME680 heater operation could be speeded up by setting an initial heater current for a target
yangcq88517 0:c70b7ececf93 536 * heater temperature by using register idac_heat_x<7:0>. This step is optional since the control
yangcq88517 0:c70b7ececf93 537 * loop will find the current after a few iterations anyway.
yangcq88517 0:c70b7ececf93 538 * Current injected to the heater in mA = (idac_heat_7_1 + 1) / 8
yangcq88517 0:c70b7ececf93 539 * Where: idac_heat_7_1 = decimal value stored in idac_heat<7:1> (unsigned, value from 0 to 127)
yangcq88517 0:c70b7ececf93 540 * @param setPoint 0-9
yangcq88517 0:c70b7ececf93 541 */
yangcq88517 0:c70b7ececf93 542 void setHeaterCurrent(int setPoint, uint8_t value);
yangcq88517 0:c70b7ececf93 543
yangcq88517 0:c70b7ececf93 544 /**
yangcq88517 0:c70b7ececf93 545 * [res_heat_x]
yangcq88517 0:c70b7ececf93 546 * Target heater resistance is programmed by user through res_heat_x<7:0> registers.
yangcq88517 0:c70b7ececf93 547 * res_heat_x = 3.4* ((R_Target*(4/4+res_heat_range))-25) / ((res_heat_val * 0.002) + 1))
yangcq88517 0:c70b7ececf93 548 * Where
yangcq88517 0:c70b7ececf93 549 * R_Target is the target heater resistance in Ohm
yangcq88517 0:c70b7ececf93 550 * res_heat_x is the decimal value that needs to be stored in register with same name
yangcq88517 0:c70b7ececf93 551 * res_heat_range is heater range stored in register address 0x02 <5:4>
yangcq88517 0:c70b7ececf93 552 * res_heat_val is heater resistance correction factor stored in register address 0x00 (signed, value from -128 to 127)
yangcq88517 0:c70b7ececf93 553 * @param setPoint 0-9
yangcq88517 0:c70b7ececf93 554 */
yangcq88517 0:c70b7ececf93 555 int8_t getTargetHeaterResistance(int setPoint);
yangcq88517 0:c70b7ececf93 556
yangcq88517 0:c70b7ececf93 557 /**
yangcq88517 0:c70b7ececf93 558 * [res_heat_x]
yangcq88517 0:c70b7ececf93 559 * Target heater resistance is programmed by user through res_heat_x<7:0> registers.
yangcq88517 0:c70b7ececf93 560 * res_heat_x = 3.4* ((R_Target*(4/4+res_heat_range))-25) / ((res_heat_val * 0.002) + 1))
yangcq88517 0:c70b7ececf93 561 * Where
yangcq88517 0:c70b7ececf93 562 * R_Target is the target heater resistance in Ohm
yangcq88517 0:c70b7ececf93 563 * res_heat_x is the decimal value that needs to be stored in register with same name
yangcq88517 0:c70b7ececf93 564 * res_heat_range is heater range stored in register address 0x02 <5:4>
yangcq88517 0:c70b7ececf93 565 * res_heat_val is heater resistance correction factor stored in register address 0x00 (signed, value from -128 to 127)
yangcq88517 0:c70b7ececf93 566 * @param setPoint 0-9
yangcq88517 0:c70b7ececf93 567 */
yangcq88517 0:c70b7ececf93 568 void setTargetHeaterResistance(int setPoint, int8_t value);
yangcq88517 0:c70b7ececf93 569
yangcq88517 0:c70b7ececf93 570 /**
yangcq88517 0:c70b7ececf93 571 * [gas_wait_x]
yangcq88517 0:c70b7ececf93 572 * gas_wait_x controls heater timing of the gas sensor. Functionality of this register will vary based on power modes.
yangcq88517 0:c70b7ececf93 573 * Forced Mode & Sequential mode
yangcq88517 0:c70b7ececf93 574 * Time between beginning of heat phase and start of sensor resistance conversion depend on gas_wait_x settings as mentioned below.
yangcq88517 0:c70b7ececf93 575 * Parallel Mode
yangcq88517 0:c70b7ececf93 576 * The number of TPHG sub-measurement sequences within the one Gas conversion for one target
yangcq88517 0:c70b7ececf93 577 * temperature resistance is defined by gas_wait_x settings.
yangcq88517 0:c70b7ececf93 578 * Note: Please take care about gas_wait_x on shifting modes between parallel & sequential/forced mode as register functionality will change.
yangcq88517 0:c70b7ececf93 579 * @return result * 0.477 ms
yangcq88517 0:c70b7ececf93 580 * @param setPoint 0-9
yangcq88517 0:c70b7ececf93 581 */
yangcq88517 0:c70b7ececf93 582 int getGasWaitTime(int setPoint);
yangcq88517 0:c70b7ececf93 583
yangcq88517 0:c70b7ececf93 584 /**
yangcq88517 0:c70b7ececf93 585 * [gas_wait_x]
yangcq88517 0:c70b7ececf93 586 * gas_wait_x controls heater timing of the gas sensor. Functionality of this register will vary based on power modes.
yangcq88517 0:c70b7ececf93 587 * Forced Mode & Sequential mode
yangcq88517 0:c70b7ececf93 588 * Time between beginning of heat phase and start of sensor resistance conversion depend on gas_wait_x settings as mentioned below.
yangcq88517 0:c70b7ececf93 589 * Parallel Mode
yangcq88517 0:c70b7ececf93 590 * The number of TPHG sub-measurement sequences within the one Gas conversion for one target
yangcq88517 0:c70b7ececf93 591 * temperature resistance is defined by gas_wait_x settings.
yangcq88517 0:c70b7ececf93 592 * Note: Please take care about gas_wait_x on shifting modes between parallel & sequential/forced mode as register functionality will change.
yangcq88517 0:c70b7ececf93 593 * @return result * 0.477 ms
yangcq88517 0:c70b7ececf93 594 * @param setPoint 0-9
yangcq88517 0:c70b7ececf93 595 * @param time 64 timer values with 1ms step sizes, all zeros means no wait.
yangcq88517 0:c70b7ececf93 596 * @param multiplication [0, 1, 2, 3] -> [1, 4, 16, 64]
yangcq88517 0:c70b7ececf93 597 */
yangcq88517 0:c70b7ececf93 598 void setGasWaitTime(int setPoint, int time, int multiplication);
yangcq88517 0:c70b7ececf93 599
yangcq88517 0:c70b7ececf93 600 /**
yangcq88517 0:c70b7ececf93 601 * [gas_wait_shared]
yangcq88517 0:c70b7ececf93 602 * The programmable wait time between two TPHG sub-measurement sequences of parallel mode depends on gas_wait_shared settings as follows
yangcq88517 0:c70b7ececf93 603 */
yangcq88517 0:c70b7ececf93 604 int getGasWaitShared();
yangcq88517 0:c70b7ececf93 605
yangcq88517 0:c70b7ececf93 606 /**
yangcq88517 0:c70b7ececf93 607 * [gas_wait_shared]
yangcq88517 0:c70b7ececf93 608 * The programmable wait time between two TPHG sub-measurement sequences of parallel mode depends on gas_wait_shared settings as follows
yangcq88517 0:c70b7ececf93 609 * @param setPoint 0-9
yangcq88517 0:c70b7ececf93 610 * @param time 64 timer values with 0.477 ms step sizes, all zeros means no wait.
yangcq88517 0:c70b7ececf93 611 * @param multiplication [0x00, 0x01, 0x10, 0x11] -> [1, 4, 16, 64]
yangcq88517 0:c70b7ececf93 612 */
yangcq88517 0:c70b7ececf93 613 void setGasWaitShared(int time, int multiplication);
yangcq88517 0:c70b7ececf93 614
yangcq88517 0:c70b7ececf93 615 /**
yangcq88517 0:c70b7ececf93 616 * [heat_off]
yangcq88517 0:c70b7ececf93 617 * Turn off current injected to heater
yangcq88517 0:c70b7ececf93 618 */
yangcq88517 0:c70b7ececf93 619 void setHeaterOff();
yangcq88517 0:c70b7ececf93 620
yangcq88517 0:c70b7ececf93 621 /**
yangcq88517 0:c70b7ececf93 622 * [nb_conv]
yangcq88517 0:c70b7ececf93 623 * is used to select heater set-points of BME680
yangcq88517 0:c70b7ececf93 624 * Sequential & Parallel Mode
yangcq88517 0:c70b7ececf93 625 * User can program a sequence of up to 10 conversions by setting nb_conv<3:0>. Each conversion has its own heater resistance target but 3 field registers to store conversion results. The actual
yangcq88517 0:c70b7ececf93 626 * gas conversion number in the measurement sequence (up to 10 conversions numbered from 0 to 9) is stored in gas measurement index register
yangcq88517 0:c70b7ececf93 627 * In parallel mode, no TPH conversions are ran at all. In sequential mode, TPH conversions are run according to osrs_t|p|h settings, gas is skipped
yangcq88517 0:c70b7ececf93 628 * @return Sequential & Parallel : number of profiles (0-10), 0 means no gas conversion
yangcq88517 0:c70b7ececf93 629 * @return Forced : indicates index of heater profile
yangcq88517 0:c70b7ececf93 630 */
yangcq88517 0:c70b7ececf93 631 int getHeaterProfile();
yangcq88517 0:c70b7ececf93 632
yangcq88517 0:c70b7ececf93 633 /**
yangcq88517 0:c70b7ececf93 634 * [nb_conv]
yangcq88517 0:c70b7ececf93 635 * is used to select heater set-points of BME680
yangcq88517 0:c70b7ececf93 636 * Sequential & Parallel Mode
yangcq88517 0:c70b7ececf93 637 * User can program a sequence of up to 10 conversions by setting nb_conv<3:0>. Each conversion has its own heater resistance target but 3 field registers to store conversion results. The actual
yangcq88517 0:c70b7ececf93 638 * gas conversion number in the measurement sequence (up to 10 conversions numbered from 0 to 9) is stored in gas measurement index register
yangcq88517 0:c70b7ececf93 639 * In parallel mode, no TPH conversions are ran at all. In sequential mode, TPH conversions are run according to osrs_t|p|h settings, gas is skipped
yangcq88517 0:c70b7ececf93 640 * @param Sequential & Parallel : number of profiles (0-10), 0 means no gas conversion
yangcq88517 0:c70b7ececf93 641 * @param Forced : indicates index of heater profile
yangcq88517 0:c70b7ececf93 642 */
yangcq88517 0:c70b7ececf93 643 void setHeaterProfile(int value);
yangcq88517 0:c70b7ececf93 644
yangcq88517 0:c70b7ececf93 645 /**
yangcq88517 0:c70b7ececf93 646 * [run_gas_l]
yangcq88517 0:c70b7ececf93 647 * The gas conversions are started only in appropriate mode if run_gas_l=1
yangcq88517 0:c70b7ececf93 648 */
yangcq88517 0:c70b7ececf93 649 void runGasConversion();
yangcq88517 0:c70b7ececf93 650
yangcq88517 0:c70b7ececf93 651 /**
yangcq88517 0:c70b7ececf93 652 * [odr]
yangcq88517 0:c70b7ececf93 653 * Wake period in sequential mode – odr
yangcq88517 0:c70b7ececf93 654 * In the sequential mode operation the device periodically enters stand-by state and returns to an operational state after a given wake-up period. Wake period can be programmed by odr<3:0> register as shown below
yangcq88517 0:c70b7ececf93 655 * @return in ms, 0 means device does not go to standby
yangcq88517 0:c70b7ececf93 656 */
yangcq88517 0:c70b7ececf93 657 float getWakePeriod();
yangcq88517 0:c70b7ececf93 658
yangcq88517 0:c70b7ececf93 659 /**
yangcq88517 0:c70b7ececf93 660 * [odr]
yangcq88517 0:c70b7ececf93 661 * Wake period in sequential mode – odr
yangcq88517 0:c70b7ececf93 662 * In the sequential mode operation the device periodically enters stand-by state and returns to an operational state after a given wake-up period. Wake period can be programmed by odr<3:0> register as shown below
yangcq88517 0:c70b7ececf93 663 * @param value : [0 - 8+] [0.59,62.5,125,250,500,1000,10,20,no standby]
yangcq88517 0:c70b7ececf93 664 */
yangcq88517 0:c70b7ececf93 665 void setWakePeriod(int value);
yangcq88517 0:c70b7ececf93 666
yangcq88517 0:c70b7ececf93 667 // PRESSURE TEMPERATURE HUMIDITY CONTROL #########################################################################
yangcq88517 0:c70b7ececf93 668
yangcq88517 0:c70b7ececf93 669 /**
yangcq88517 0:c70b7ececf93 670 * [osrs_h]
yangcq88517 0:c70b7ececf93 671 * @return value : [0,1,2,4,8,16] -> [skip,X1,X2,X4,X8,X16], 0 means skipped (output set to 0x8000)
yangcq88517 0:c70b7ececf93 672 */
yangcq88517 0:c70b7ececf93 673 int getOversamplingHumidity();
yangcq88517 0:c70b7ececf93 674
yangcq88517 0:c70b7ececf93 675 /**
yangcq88517 0:c70b7ececf93 676 * [osrs_h]
yangcq88517 0:c70b7ececf93 677 * @param value : [0,1,2,3,4,5] -> [skip,X1,X2,X4,X8,X16], 0 means skipped (output set to 0x8000)
yangcq88517 0:c70b7ececf93 678 */
yangcq88517 0:c70b7ececf93 679 void setOversamplingHumidity(int value);
yangcq88517 0:c70b7ececf93 680
yangcq88517 0:c70b7ececf93 681 /**
yangcq88517 0:c70b7ececf93 682 * [osrs_p]
yangcq88517 0:c70b7ececf93 683 * @return value : [0,1,2,4,8,16] -> [skip,X1,X2,X4,X8,X16], 0 means skipped (output set to 0x8000)
yangcq88517 0:c70b7ececf93 684 */
yangcq88517 0:c70b7ececf93 685 int getOversamplingPressure();
yangcq88517 0:c70b7ececf93 686
yangcq88517 0:c70b7ececf93 687 /**
yangcq88517 0:c70b7ececf93 688 * [osrs_p]
yangcq88517 0:c70b7ececf93 689 * @param value : [0,1,2,3,4,5] -> [skip,X1,X2,X4,X8,X16], 0 means skipped (output set to 0x8000)
yangcq88517 0:c70b7ececf93 690 */
yangcq88517 0:c70b7ececf93 691 void setOversamplingPressure(int value);
yangcq88517 0:c70b7ececf93 692
yangcq88517 0:c70b7ececf93 693 /**
yangcq88517 0:c70b7ececf93 694 * [osrs_t]
yangcq88517 0:c70b7ececf93 695 * @return value : [0,1,2,4,8,16] -> [skip,X1,X2,X4,X8,X16], 0 means skipped (output set to 0x8000)
yangcq88517 0:c70b7ececf93 696 */
yangcq88517 0:c70b7ececf93 697 int getOversamplingTemperature();
yangcq88517 0:c70b7ececf93 698
yangcq88517 0:c70b7ececf93 699 /**
yangcq88517 0:c70b7ececf93 700 * [osrs_t]
yangcq88517 0:c70b7ececf93 701 * @param value : [0,1,2,3,4,5] -> [skip,X1,X2,X4,X8,X16], 0 means skipped (output set to 0x8000)
yangcq88517 0:c70b7ececf93 702 */
yangcq88517 0:c70b7ececf93 703 void setOversamplingTemperature(int value);
yangcq88517 0:c70b7ececf93 704
yangcq88517 0:c70b7ececf93 705 /**
yangcq88517 0:c70b7ececf93 706 * [filter]
yangcq88517 0:c70b7ececf93 707 * IIR filter control
yangcq88517 0:c70b7ececf93 708 * IIR filter applies to temperature and pressure data but not to humidity and gas data. The data
yangcq88517 0:c70b7ececf93 709 * coming from the ADC are filtered and then loaded into the data registers. The T, P result registers
yangcq88517 0:c70b7ececf93 710 * are updated together at the same time at the end of measurement. IIR filter output resolution is
yangcq88517 0:c70b7ececf93 711 * 20 bits. The T, P result registers are reset to value 0x80000 when the T, P measurements have
yangcq88517 0:c70b7ececf93 712 * been skipped (osrs_x=”000‟). The appropriate filter memory is kept unchanged (the value fromt he last measurement is kept). When the appropriate OSRS register is set back to nonzero, then
yangcq88517 0:c70b7ececf93 713 * the first value stored to the T, P result register is filtered.
yangcq88517 0:c70b7ececf93 714 * @return value : [0,1,3,7,15,31,63,127]
yangcq88517 0:c70b7ececf93 715 */
yangcq88517 0:c70b7ececf93 716 int getIIRfilterCoefficient();
yangcq88517 0:c70b7ececf93 717
yangcq88517 0:c70b7ececf93 718 /**
yangcq88517 0:c70b7ececf93 719 * [filter]
yangcq88517 0:c70b7ececf93 720 * IIR filter control
yangcq88517 0:c70b7ececf93 721 * IIR filter applies to temperature and pressure data but not to humidity and gas data. The data
yangcq88517 0:c70b7ececf93 722 * coming from the ADC are filtered and then loaded into the data registers. The T, P result registers
yangcq88517 0:c70b7ececf93 723 * are updated together at the same time at the end of measurement. IIR filter output resolution is
yangcq88517 0:c70b7ececf93 724 * 20 bits. The T, P result registers are reset to value 0x80000 when the T, P measurements have
yangcq88517 0:c70b7ececf93 725 * been skipped (osrs_x=”000‟). The appropriate filter memory is kept unchanged (the value fromt he last measurement is kept). When the appropriate OSRS register is set back to nonzero, then
yangcq88517 0:c70b7ececf93 726 * the first value stored to the T, P result register is filtered.
yangcq88517 0:c70b7ececf93 727 * @param value : [0,1,2,3,4,5,6,7] -> [0,1,3,7,15,31,63,127]
yangcq88517 0:c70b7ececf93 728 */
yangcq88517 0:c70b7ececf93 729 void setIIRfilterCoefficient(int value);
yangcq88517 0:c70b7ececf93 730
yangcq88517 0:c70b7ececf93 731 // GENERAL CONTROL #########################################################################
yangcq88517 0:c70b7ececf93 732
yangcq88517 0:c70b7ececf93 733 /**
yangcq88517 0:c70b7ececf93 734 * [mode]
yangcq88517 0:c70b7ececf93 735 * Four measurement modes are available for BME680; that is sleep, sequential, parallel and forced
yangcq88517 0:c70b7ececf93 736 * mode.Four measurement modes are available for BME680; that is sleep, sequential, parallel and forced mode.
yangcq88517 0:c70b7ececf93 737 * @param mode : [0,1,2,3] -> [Sleep, Forced, Parallel, Sequential]
yangcq88517 0:c70b7ececf93 738 */
yangcq88517 0:c70b7ececf93 739 void setMode(int mode);
yangcq88517 0:c70b7ececf93 740
yangcq88517 0:c70b7ececf93 741 /**
yangcq88517 0:c70b7ececf93 742 * [mode]
yangcq88517 0:c70b7ececf93 743 * Four measurement modes are available for BME680; that is sleep, sequential, parallel and forced
yangcq88517 0:c70b7ececf93 744 * mode.Four measurement modes are available for BME680; that is sleep, sequential, parallel and forced mode.
yangcq88517 0:c70b7ececf93 745 * @return value : [0,1,2,3] -> [Sleep, Forced, Parallel, Sequential]
yangcq88517 0:c70b7ececf93 746 */
yangcq88517 0:c70b7ececf93 747 int getMode();
yangcq88517 0:c70b7ececf93 748
yangcq88517 0:c70b7ececf93 749 /**
yangcq88517 0:c70b7ececf93 750 * [chip_id]
yangcq88517 0:c70b7ececf93 751 * Chip id of the device, this should give 0x61
yangcq88517 0:c70b7ececf93 752 */
yangcq88517 0:c70b7ececf93 753 int getChipID();
yangcq88517 0:c70b7ececf93 754 };
yangcq88517 0:c70b7ececf93 755
yangcq88517 0:c70b7ececf93 756 #endif