/* * bme680.h * * Created on: Feb 11, 2020 * Author: KamilB */ #include "main.h" #include #include #ifndef INC_BME680_H_ #define INC_BME680_H_ //double const_array1[]={1, 1, 1, 1, 1, 0.99, 1, 0.992, 1, 1, 0.998, 0.995, 1, 0.99, 1,1}; //double const_array2[] = {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}; //registers uint8_t res_heat_range, nb_conv, status; int8_t res_heat_val, range_sw_err; double const_array1[16]; double const_array2[16]; uint16_t par_t1, par_p1, par_h1, par_h2, heater_temp, heater_dur; uint8_t par_p10, par_h6, heater_ctrl, run_gas, os_temp, os_hum, os_press, filter, power_mode, data_buff[15]; int16_t par_t2, par_p2, par_p4, par_p5, par_p8, par_p9,par_gh2; int8_t par_t3, par_p3,par_p6, par_p7, par_h3, par_h4, par_h5, par_h7, par_gh1, par_gh3; bool _gas_enabled, _temp_enabled, _hum_enabled, _press_enabled, _filter_enabled, amb_temp; extern SPI_HandleTypeDef hspi2; #define NSS_PIN GPIO_PIN_8 #define NSS_PORT GPIOC #define RESET_REG 0x60 #define ID_REG 0x50 #define BME680_CONF_ODR_FILT_ADDR 0x75 #define BME680_CONF_T_P_MODE_ADDR 0x74 #define BME680_CONF_OS_H_ADDR 0x72 #define BME680_CONF_ODR_RUN_GAS_NBC_ADDR 0x71 #define BME680_CONF_HEAT_CTRL_ADDR 0x70 #define BME680_GAS_WAIT0_ADDR 0x64 //to 0x6D #define BME680_RES_HEAT0_ADDR 0x5A // to 0x63 #define IDAC_HEAT0_REG 0x50 // to ox59 #define GAS_R_LSB_REG 0x2B #define GAS_R_MSB_REG 0x2A #define BME680_COEFF_ADDR1 0x89 #define BME680_COEFF_ADDR2 0xE1 #define BME680_ADDR_RES_HEAT_RANGE_ADDR 0x02 #define BME680_ADDR_RES_HEAT_VAL_ADDR 0x00 #define BME680_ADDR_RANGE_SW_ERR_ADDR 0x04 #define BME680_FIELD0_ADDR 0x1D //modes #define SOFT_RESET_MODE 0xB6 //important #define BME680_DISABLE_HEATER 0x08 #define BME680_DISABLE_GAS_MEAS 0x00 #define BME680_ENABLE_HEATER 0x00 #define BME680_ENABLE_GAS_MEAS 0x01 #define BME680_RESET_PERIOD 10 #define BME680_POLL_PERIOD_MS 10 #define BME680_ID 0x61 #define BME680_T2_LSB_REG (1) #define BME680_T2_MSB_REG (2) #define BME680_T3_REG (3) #define BME680_P1_LSB_REG (5) #define BME680_P1_MSB_REG (6) #define BME680_P2_LSB_REG (7) #define BME680_P2_MSB_REG (8) #define BME680_P3_REG (9) #define BME680_P4_LSB_REG (11) #define BME680_P4_MSB_REG (12) #define BME680_P5_LSB_REG (13) #define BME680_P5_MSB_REG (14) #define BME680_P7_REG (15) #define BME680_P6_REG (16) #define BME680_P8_LSB_REG (19) #define BME680_P8_MSB_REG (20) #define BME680_P9_LSB_REG (21) #define BME680_P9_MSB_REG (22) #define BME680_P10_REG (23) #define BME680_H2_MSB_REG (25) #define BME680_H2_LSB_REG (26) #define BME680_H1_LSB_REG (26) #define BME680_H1_MSB_REG (27) #define BME680_H3_REG (28) #define BME680_H4_REG (29) #define BME680_H5_REG (30) #define BME680_H6_REG (31) #define BME680_H7_REG (32) #define BME680_T1_LSB_REG (33) #define BME680_T1_MSB_REG (34) #define BME680_GH2_LSB_REG (35) #define BME680_GH2_MSB_REG (36) #define BME680_GH1_REG (37) #define BME680_GH3_REG (38) #define BME680_MODE_MSK 0x03 #define BME680_RSERROR_MSK 0xF0 #define BME680_RHRANGE_MSK 0x30 #define BME680_BIT_H1_DATA_MSK 0x0F #define BME680_FILTER_MSK 0x1C #define BME680_HCTRL_MSK 0x08 #define BME680_OST_MSK 0xE0 #define BME680_OSP_MSK 0x1C #define BME680_OSH_MSK 0x07 #define BME680_RUN_GAS_MSK 0x10 #define BME680_NBCONV_MSK 0x0F #define BME680_NEW_DATA_MSK 0x80 #define BME680_GASM_VALID_MSK 0x20 #define BME680_HEAT_STAB_MSK 0x10 #define BME680_GAS_RANGE_MSK 0x0F #define BME680_HUM_REG_SHIFT_VAL 4 #define BME680_COEFF_ADDR1_LEN 25 #define BME680_COEFF_ADDR2_LEN 16 #define BME680_COEFF_SIZE 41 #define BME680_FILTER_POS 2 #define BME680_OST_POS 5 #define BME680_OSP_POS 2 #define BME680_RUN_GAS_POS 4 #define BME680_CONCAT_BYTES(msb, lsb) (((uint16_t)msb<<8)|(uint16_t)lsb) #define BME680_SET_BITS(reg_data, bitname, data) \ ((reg_data & ~(bitname##_MSK))| \ ((data<< bitname##_POS)&bitname##_MSK)) #define BME680_SET_BITS_POS_0(reg_data, bitname, data)\ ((reg_data &~(bitname##_MSK))|\ (data&bitname##_MSK)) #define BME680_OS_NONE 0x00 #define BME680_OS_1X 0x01 #define BME680_OS_2X 0x02 #define BME680_OS_4X 0x03 #define BME680_OS_8X 0x04 #define BME680_OS_16X 0x05 #define BME680_FILTER_SIZE_0 0x00 #define BME680_FILTER_SIZE_1 0x01 #define BME680_FILTER_SIZE_3 0x02 #define BME680_FILTER_SIZE_7 0x03 #define BME680_FILTER_SIZE_15 0x04 #define BME680_FILTER_SIZE_31 0x05 #define BME680_FILTER_SIZE_63 0x06 #define BME680_FILTER_SIZE_127 0x07 #define BME680_OST_SEL 1 #define BME680_OSP_SEL 2 #define BME680_OSH_SEL 4 #define BME680_GAS_MEAS_SEL 8 #define BME680_FILTER_SEL 16 #define BME680_HCNTRL_SEL 32 #define BME680_RUN_GAS_SEL 64 #define BME680_NBCONV_SEL 128 #define BME680_GAS_SENSOR_SEL (BME680_GAS_MEAS_SEL | BME680_RUN_GAS_SEL | BME680_NBCONV_SEL) #define BME680_RUN_GAS_ENABLE 1 #define BME680_RUN_GAS_DISABLE 0 #define BME680_NBCONV_MIN 0 #define BME680_NBCONV_MAX 10 #define BME680_SLEEP_MODE 0 #define BME680_FORCED_MODE 1 #define BME680_TMP_BUFFER_LENGTH 40 #define BME680_REG_BUFFER_LENGTH 6 #define BME680_FIELD_DATA_LENGTH 3 #define BME680_GAS_REG_BUF_LENGTH 20 #define BME680_FIELD_LENGTH 15 void BME680_write8(uint8_t reg, uint8_t val); int8_t BME680_calib_data(); int8_t BME680_read8(uint8_t reg); int8_t BME680_begin(); int8_t BME680_set_sensor_settings(uint16_t desired_settings); int8_t BME680_set_gas_config(); int8_t BME680_set_sensor_mode(); int8_t BME680_soft_reset(); int8_t BME680_boundary_check(uint8_t *value, uint8_t min, uint8_t max); int8_t BME680_read_field_data(); uint8_t BME680_calc_heater_res(uint16_t temp); uint8_t BME680_calc_heater_dur(uint16_t dur); uint8_t BME680_sample(); uint8_t BME680_readgas(); uint32_t BME680_read_gas_data(); void BME680_get_profile_dur(uint16_t *duration); void BME680_set_gas_heater(uint16_t temp, uint16_t dur); bool BME680_set_temperature_oversampling(uint8_t oversample); bool BME680_set_humidity_oversampling(uint8_t oversample); bool BME680_set_pressure_oversampling(uint8_t oversample); bool BME680_set_IIR_filter_size(uint8_t filtersize); bool BME680_end_reading(); unsigned long BME680_begin_reading(); #endif /* INC_BME680_H_ */