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 File | Version | Date
\r
9 --------------|---------|------------
\r
10 bme280.c | 3.3.7 | 26 Aug 2019
\r
11 bme280.h | 3.3.7 | 26 Aug 2019
\r
12 bme280_defs.h | 3.3.7 | 26 Aug 2019
\r
14 ## Integration details
\r
15 * Integrate bme280.h, bme280_defs.h and bme280.c file in to the project.
\r
16 * Include the bme280.h file in your code like below.
\r
22 * bme280_defs.h : This header file has the constants, macros and datatype declarations.
\r
23 * bme280.h : This header file contains the declarations of the sensor driver APIs.
\r
24 * bme280.c : This source file contains the definitions of the sensor driver APIs.
\r
26 ## Supported sensor interfaces
\r
30 SPI 3-wire is currently not supported in the API.
\r
32 ### Initializing the sensor
\r
33 To initialize the sensor, user need to create a device structure. User can do this by
\r
34 creating an instance of the structure bme280_dev. After creating the device strcuture, user
\r
35 need to fill in the various parameters as shown below.
\r
37 #### Example for SPI 4-Wire
\r
39 struct bme280_dev dev;
\r
40 int8_t rslt = BME280_OK;
\r
42 /* Sensor_0 interface over SPI with native chip select line */
\r
44 dev.intf = BME280_SPI_INTF;
\r
45 dev.read = user_spi_read;
\r
46 dev.write = user_spi_write;
\r
47 dev.delay_ms = user_delay_ms;
\r
49 rslt = bme280_init(&dev);
\r
51 #### Example for I2C
\r
53 struct bme280_dev dev;
\r
54 int8_t rslt = BME280_OK;
\r
56 dev.dev_id = BME280_I2C_ADDR_PRIM;
\r
57 dev.intf = BME280_I2C_INTF;
\r
58 dev.read = user_i2c_read;
\r
59 dev.write = user_i2c_write;
\r
60 dev.delay_ms = user_delay_ms;
\r
62 rslt = bme280_init(&dev);
\r
64 Regarding compensation functions for temperature,pressure and humidity we have two implementations.
\r
65 1) Double precision floating point version
\r
68 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
70 In integer compensation functions, we also have below two implementations for pressure.
\r
71 1) For 32 bit machine.
\r
72 2) For 64 bit machine.
\r
74 By default, 64 bit variant is used in the API. If the user wants 32 bit variant, the user can disable the
\r
75 macro BME280_64BIT_ENABLE in bme280_defs.h file.
\r
77 ### Sensor data units
\r
78 > The sensor data units depends on the following macros being enabled or not,
\r
79 > (in bme280_defs.h file or as compiler macros)
\r
80 > * BME280_FLOAT_ENABLE
\r
81 > * BME280_64BIT_ENABLE
\r
83 In case of the macro "BME280_FLOAT_ENABLE" enabled,
\r
84 The outputs are in double and the units are
\r
86 - °C for temperature
\r
87 - % relative humidity
\r
88 - Pascal for pressure
\r
90 In case if "BME280_FLOAT_ENABLE" is not enabled, then it is
\r
92 - int32_t for temperature with the units 100 * °C
\r
93 - uint32_t for humidity with the units 1024 * % relative humidity
\r
94 - uint32_t for pressure
\r
95 If macro "BME280_64BIT_ENABLE" is enabled, which it is by default, the unit is 100 * Pascal
\r
96 If this macro is disabled, Then the unit is in Pascal
\r
98 ### Stream sensor data
\r
99 #### Stream sensor data in forced mode
\r
102 int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev)
\r
105 uint8_t settings_sel;
\r
106 struct bme280_data comp_data;
\r
108 /* Recommended mode of operation: Indoor navigation */
\r
109 dev->settings.osr_h = BME280_OVERSAMPLING_1X;
\r
110 dev->settings.osr_p = BME280_OVERSAMPLING_16X;
\r
111 dev->settings.osr_t = BME280_OVERSAMPLING_2X;
\r
112 dev->settings.filter = BME280_FILTER_COEFF_16;
\r
114 settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL;
\r
116 rslt = bme280_set_sensor_settings(settings_sel, dev);
\r
118 printf("Temperature, Pressure, Humidity\r\n");
\r
119 /* Continuously stream sensor data */
\r
121 rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, dev);
\r
122 /* Wait for the measurement to complete and print data @25Hz */
\r
124 rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);
\r
125 print_sensor_data(&comp_data);
\r
130 void print_sensor_data(struct bme280_data *comp_data)
\r
132 #ifdef BME280_FLOAT_ENABLE
\r
133 printf("%0.2f, %0.2f, %0.2f\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
\r
135 printf("%ld, %ld, %ld\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
\r
139 ##### Stream sensor data in normal mode
\r
141 int8_t stream_sensor_data_normal_mode(struct bme280_dev *dev)
\r
144 uint8_t settings_sel;
\r
145 struct bme280_data comp_data;
\r
147 /* Recommended mode of operation: Indoor navigation */
\r
148 dev->settings.osr_h = BME280_OVERSAMPLING_1X;
\r
149 dev->settings.osr_p = BME280_OVERSAMPLING_16X;
\r
150 dev->settings.osr_t = BME280_OVERSAMPLING_2X;
\r
151 dev->settings.filter = BME280_FILTER_COEFF_16;
\r
152 dev->settings.standby_time = BME280_STANDBY_TIME_62_5_MS;
\r
154 settings_sel = BME280_OSR_PRESS_SEL;
\r
155 settings_sel |= BME280_OSR_TEMP_SEL;
\r
156 settings_sel |= BME280_OSR_HUM_SEL;
\r
157 settings_sel |= BME280_STANDBY_SEL;
\r
158 settings_sel |= BME280_FILTER_SEL;
\r
159 rslt = bme280_set_sensor_settings(settings_sel, dev);
\r
160 rslt = bme280_set_sensor_mode(BME280_NORMAL_MODE, dev);
\r
162 printf("Temperature, Pressure, Humidity\r\n");
\r
164 /* Delay while the sensor completes a measurement */
\r
166 rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);
\r
167 print_sensor_data(&comp_data);
\r
173 void print_sensor_data(struct bme280_data *comp_data)
\r
175 #ifdef BME280_FLOAT_ENABLE
\r
176 printf("%0.2f, %0.2f, %0.2f\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
\r
178 printf("%ld, %ld, %ld\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
\r
183 ### Templates for function pointers
\r
186 void user_delay_ms(uint32_t period)
\r
189 * Return control or wait,
\r
190 * for a period amount of milliseconds
\r
194 int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
\r
196 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
\r
199 * The parameter dev_id can be used as a variable to select which Chip Select pin has
\r
200 * to be set low to activate the relevant device on the SPI bus
\r
204 * Data on the bus should be like
\r
205 * |----------------+---------------------+-------------|
\r
206 * | MOSI | MISO | Chip Select |
\r
207 * |----------------+---------------------|-------------|
\r
208 * | (don't care) | (don't care) | HIGH |
\r
209 * | (reg_addr) | (don't care) | LOW |
\r
210 * | (don't care) | (reg_data[0]) | LOW |
\r
211 * | (....) | (....) | LOW |
\r
212 * | (don't care) | (reg_data[len - 1]) | LOW |
\r
213 * | (don't care) | (don't care) | HIGH |
\r
214 * |----------------+---------------------|-------------|
\r
220 int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
\r
222 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
\r
225 * The parameter dev_id can be used as a variable to select which Chip Select pin has
\r
226 * to be set low to activate the relevant device on the SPI bus
\r
230 * Data on the bus should be like
\r
231 * |---------------------+--------------+-------------|
\r
232 * | MOSI | MISO | Chip Select |
\r
233 * |---------------------+--------------|-------------|
\r
234 * | (don't care) | (don't care) | HIGH |
\r
235 * | (reg_addr) | (don't care) | LOW |
\r
236 * | (reg_data[0]) | (don't care) | LOW |
\r
237 * | (....) | (....) | LOW |
\r
238 * | (reg_data[len - 1]) | (don't care) | LOW |
\r
239 * | (don't care) | (don't care) | HIGH |
\r
240 * |---------------------+--------------|-------------|
\r
246 int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
\r
248 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
\r
251 * The parameter dev_id can be used as a variable to store the I2C address of the device
\r
255 * Data on the bus should be like
\r
256 * |------------+---------------------|
\r
257 * | I2C action | Data |
\r
258 * |------------+---------------------|
\r
260 * | Write | (reg_addr) |
\r
263 * | Read | (reg_data[0]) |
\r
264 * | Read | (....) |
\r
265 * | Read | (reg_data[len - 1]) |
\r
267 * |------------+---------------------|
\r
273 int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
\r
275 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
\r
278 * The parameter dev_id can be used as a variable to store the I2C address of the device
\r
282 * Data on the bus should be like
\r
283 * |------------+---------------------|
\r
284 * | I2C action | Data |
\r
285 * |------------+---------------------|
\r
287 * | Write | (reg_addr) |
\r
288 * | Write | (reg_data[0]) |
\r
289 * | Write | (....) |
\r
290 * | Write | (reg_data[len - 1]) |
\r
292 * |------------+---------------------|
\r
300 ## Copyright (C) 2016 - 2017 Bosch Sensortec GmbH