3 This package contains the Bosch Sensortec's BME280 pressure sensor driver (sensor API)
\r
5 The sensor driver package includes bme280.c, bme280.h and bme280_defs.h files.
\r
8 ## Integration details
\r
9 * Integrate bme280.h, bme280_defs.h and bme280.c file in to the project.
\r
10 * Include the bme280.h file in your code like below.
\r
16 * bme280_defs.h : This header file has the constants, macros and datatype declarations.
\r
17 * bme280.h : This header file contains the declarations of the sensor driver APIs.
\r
18 * bme280.c : This source file contains the definitions of the sensor driver APIs.
\r
20 ## Supported sensor interfaces
\r
24 SPI 3-wire is currently not supported in the API.
\r
26 ### Initializing the sensor
\r
27 To initialize the sensor, user need to create a device structure. User can do this by
\r
28 creating an instance of the structure bme280_dev. After creating the device strcuture, user
\r
29 need to fill in the various parameters as shown below.
\r
31 #### Example for SPI 4-Wire
\r
33 struct bme280_dev dev;
\r
34 int8_t rslt = BME280_OK;
\r
36 /* Sensor_0 interface over SPI with native chip select line */
\r
38 dev.intf = BME280_SPI_INTF;
\r
39 dev.read = user_spi_read;
\r
40 dev.write = user_spi_write;
\r
41 dev.delay_ms = user_delay_ms;
\r
43 rslt = bme280_init(&dev);
\r
45 #### Example for I2C
\r
47 struct bme280_dev dev;
\r
48 int8_t rslt = BME280_OK;
\r
50 dev.dev_id = BME280_I2C_ADDR_PRIM;
\r
51 dev.intf = BME280_I2C_INTF;
\r
52 dev.read = user_i2c_read;
\r
53 dev.write = user_i2c_write;
\r
54 dev.delay_ms = user_delay_ms;
\r
56 rslt = bme280_init(&dev);
\r
58 Regarding compensation functions for temperature,pressure and humidity we have two implementations.
\r
59 1) Double precision floating point version
\r
62 By default, integer version is used in the API. If the user needs the floating point version, the user has to uncomment BME280_FLOAT_ENABLE macro in bme280_defs.h file or add that to the compiler flags.
\r
64 In integer compensation functions, we also have below two implementations for pressure.
\r
65 1) For 32 bit machine.
\r
66 2) For 64 bit machine.
\r
68 By default, 64 bit variant is used in the API. If the user wants 32 bit variant, the user can disable the
\r
69 macro BME280_64BIT_ENABLE in bme280_defs.h file.
\r
71 ### Sensor data units
\r
72 > The sensor data units depends on the following macros being enabled or not,
\r
73 > (in bme280_defs.h file or as compiler macros)
\r
74 > * BME280_FLOAT_ENABLE
\r
75 > * BME280_64BIT_ENABLE
\r
77 In case of the macro "BME280_FLOAT_ENABLE" enabled,
\r
78 The outputs are in double and the units are
\r
80 - °C for temperature
\r
81 - % relative humidity
\r
82 - Pascal for pressure
\r
84 In case if "BME280_FLOAT_ENABLE" is not enabled, then it is
\r
86 - int32_t for temperature with the units 100 * °C
\r
87 - uint32_t for humidity with the units 1024 * % relative humidity
\r
88 - uint32_t for pressure
\r
89 If macro "BME280_64BIT_ENABLE" is enabled, which it is by default, the unit is 100 * Pascal
\r
90 If this macro is disabled, Then the unit is in Pascal
\r
92 ### Stream sensor data
\r
93 #### Stream sensor data in forced mode
\r
96 int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev)
\r
99 uint8_t settings_sel;
\r
100 uint32_t req_delay;
\r
101 struct bme280_data comp_data;
\r
103 /* Recommended mode of operation: Indoor navigation */
\r
104 dev->settings.osr_h = BME280_OVERSAMPLING_1X;
\r
105 dev->settings.osr_p = BME280_OVERSAMPLING_16X;
\r
106 dev->settings.osr_t = BME280_OVERSAMPLING_2X;
\r
107 dev->settings.filter = BME280_FILTER_COEFF_16;
\r
109 settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL;
\r
111 rslt = bme280_set_sensor_settings(settings_sel, dev);
\r
113 /*Calculate the minimum delay required between consecutive measurement based upon the sensor enabled
\r
114 * and the oversampling configuration. */
\r
115 req_delay = bme280_cal_meas_delay(&dev->settings);
\r
117 printf("Temperature, Pressure, Humidity\r\n");
\r
118 /* Continuously stream sensor data */
\r
120 rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, dev);
\r
121 /* Wait for the measurement to complete and print data @25Hz */
\r
122 dev->delay_ms(req_delay);
\r
123 rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);
\r
124 print_sensor_data(&comp_data);
\r
129 void print_sensor_data(struct bme280_data *comp_data)
\r
131 #ifdef BME280_FLOAT_ENABLE
\r
132 printf("%0.2f, %0.2f, %0.2f\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
\r
134 printf("%ld, %ld, %ld\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
\r
138 ##### Stream sensor data in normal mode
\r
140 int8_t stream_sensor_data_normal_mode(struct bme280_dev *dev)
\r
143 uint8_t settings_sel;
\r
144 struct bme280_data comp_data;
\r
146 /* Recommended mode of operation: Indoor navigation */
\r
147 dev->settings.osr_h = BME280_OVERSAMPLING_1X;
\r
148 dev->settings.osr_p = BME280_OVERSAMPLING_16X;
\r
149 dev->settings.osr_t = BME280_OVERSAMPLING_2X;
\r
150 dev->settings.filter = BME280_FILTER_COEFF_16;
\r
151 dev->settings.standby_time = BME280_STANDBY_TIME_62_5_MS;
\r
153 settings_sel = BME280_OSR_PRESS_SEL;
\r
154 settings_sel |= BME280_OSR_TEMP_SEL;
\r
155 settings_sel |= BME280_OSR_HUM_SEL;
\r
156 settings_sel |= BME280_STANDBY_SEL;
\r
157 settings_sel |= BME280_FILTER_SEL;
\r
158 rslt = bme280_set_sensor_settings(settings_sel, dev);
\r
159 rslt = bme280_set_sensor_mode(BME280_NORMAL_MODE, dev);
\r
161 printf("Temperature, Pressure, Humidity\r\n");
\r
163 /* Delay while the sensor completes a measurement */
\r
165 rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);
\r
166 print_sensor_data(&comp_data);
\r
172 void print_sensor_data(struct bme280_data *comp_data)
\r
174 #ifdef BME280_FLOAT_ENABLE
\r
175 printf("%0.2f, %0.2f, %0.2f\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
\r
177 printf("%ld, %ld, %ld\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
\r
182 ### Templates for function pointers
\r
185 void user_delay_ms(uint32_t period)
\r
188 * Return control or wait,
\r
189 * for a period amount of milliseconds
\r
193 int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
\r
195 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
\r
198 * The parameter dev_id can be used as a variable to select which Chip Select pin has
\r
199 * to be set low to activate the relevant device on the SPI bus
\r
203 * Data on the bus should be like
\r
204 * |----------------+---------------------+-------------|
\r
205 * | MOSI | MISO | Chip Select |
\r
206 * |----------------+---------------------|-------------|
\r
207 * | (don't care) | (don't care) | HIGH |
\r
208 * | (reg_addr) | (don't care) | LOW |
\r
209 * | (don't care) | (reg_data[0]) | LOW |
\r
210 * | (....) | (....) | LOW |
\r
211 * | (don't care) | (reg_data[len - 1]) | LOW |
\r
212 * | (don't care) | (don't care) | HIGH |
\r
213 * |----------------+---------------------|-------------|
\r
219 int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
\r
221 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
\r
224 * The parameter dev_id can be used as a variable to select which Chip Select pin has
\r
225 * to be set low to activate the relevant device on the SPI bus
\r
229 * Data on the bus should be like
\r
230 * |---------------------+--------------+-------------|
\r
231 * | MOSI | MISO | Chip Select |
\r
232 * |---------------------+--------------|-------------|
\r
233 * | (don't care) | (don't care) | HIGH |
\r
234 * | (reg_addr) | (don't care) | LOW |
\r
235 * | (reg_data[0]) | (don't care) | LOW |
\r
236 * | (....) | (....) | LOW |
\r
237 * | (reg_data[len - 1]) | (don't care) | LOW |
\r
238 * | (don't care) | (don't care) | HIGH |
\r
239 * |---------------------+--------------|-------------|
\r
245 int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
\r
247 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
\r
250 * The parameter dev_id can be used as a variable to store the I2C address of the device
\r
254 * Data on the bus should be like
\r
255 * |------------+---------------------|
\r
256 * | I2C action | Data |
\r
257 * |------------+---------------------|
\r
259 * | Write | (reg_addr) |
\r
262 * | Read | (reg_data[0]) |
\r
263 * | Read | (....) |
\r
264 * | Read | (reg_data[len - 1]) |
\r
266 * |------------+---------------------|
\r
272 int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
\r
274 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
\r
277 * The parameter dev_id can be used as a variable to store the I2C address of the device
\r
281 * Data on the bus should be like
\r
282 * |------------+---------------------|
\r
283 * | I2C action | Data |
\r
284 * |------------+---------------------|
\r
286 * | Write | (reg_addr) |
\r
287 * | Write | (reg_data[0]) |
\r
288 * | Write | (....) |
\r
289 * | Write | (reg_data[len - 1]) |
\r
291 * |------------+---------------------|
\r