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
37 uint8_t dev_addr = 0;
\r
39 dev.intf_ptr = &dev_addr;
\r
40 dev.intf = BME280_SPI_INTF;
\r
41 dev.read = user_spi_read;
\r
42 dev.write = user_spi_write;
\r
43 dev.delay_ms = user_delay_ms;
\r
45 rslt = bme280_init(&dev);
\r
47 #### Example for I2C
\r
49 struct bme280_dev dev;
\r
50 int8_t rslt = BME280_OK;
\r
51 uint8_t dev_addr = BME280_I2C_ADDR_PRIM;
\r
53 dev.intf_ptr = &dev_addr;
\r
54 dev.intf = BME280_I2C_INTF;
\r
55 dev.read = user_i2c_read;
\r
56 dev.write = user_i2c_write;
\r
57 dev.delay_ms = user_delay_ms;
\r
59 rslt = bme280_init(&dev);
\r
61 Regarding compensation functions for temperature,pressure and humidity we have two implementations.
\r
62 1) Double precision floating point version
\r
65 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
67 In integer compensation functions, we also have below two implementations for pressure.
\r
68 1) For 32 bit machine.
\r
69 2) For 64 bit machine.
\r
71 By default, 64 bit variant is used in the API. If the user wants 32 bit variant, the user can disable the
\r
72 macro BME280_64BIT_ENABLE in bme280_defs.h file.
\r
74 ### Sensor data units
\r
75 > The sensor data units depends on the following macros being enabled or not,
\r
76 > (in bme280_defs.h file or as compiler macros)
\r
77 > * BME280_FLOAT_ENABLE
\r
78 > * BME280_64BIT_ENABLE
\r
80 In case of the macro "BME280_FLOAT_ENABLE" enabled,
\r
81 The outputs are in double and the units are
\r
83 - °C for temperature
\r
84 - % relative humidity
\r
85 - Pascal for pressure
\r
87 In case if "BME280_FLOAT_ENABLE" is not enabled, then it is
\r
89 - int32_t for temperature with the units 100 * °C
\r
90 - uint32_t for humidity with the units 1024 * % relative humidity
\r
91 - uint32_t for pressure
\r
92 If macro "BME280_64BIT_ENABLE" is enabled, which it is by default, the unit is 100 * Pascal
\r
93 If this macro is disabled, Then the unit is in Pascal
\r
95 ### Stream sensor data
\r
96 #### Stream sensor data in forced mode
\r
99 int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev)
\r
102 uint8_t settings_sel;
\r
103 uint32_t req_delay;
\r
104 struct bme280_data comp_data;
\r
106 /* Recommended mode of operation: Indoor navigation */
\r
107 dev->settings.osr_h = BME280_OVERSAMPLING_1X;
\r
108 dev->settings.osr_p = BME280_OVERSAMPLING_16X;
\r
109 dev->settings.osr_t = BME280_OVERSAMPLING_2X;
\r
110 dev->settings.filter = BME280_FILTER_COEFF_16;
\r
112 settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL;
\r
114 rslt = bme280_set_sensor_settings(settings_sel, dev);
\r
116 /*Calculate the minimum delay required between consecutive measurement based upon the sensor enabled
\r
117 * and the oversampling configuration. */
\r
118 req_delay = bme280_cal_meas_delay(&dev->settings);
\r
120 printf("Temperature, Pressure, Humidity\r\n");
\r
121 /* Continuously stream sensor data */
\r
123 rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, dev);
\r
124 /* Wait for the measurement to complete and print data @25Hz */
\r
125 dev->delay_ms(req_delay, dev->intf_ptr);
\r
126 rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);
\r
127 print_sensor_data(&comp_data);
\r
132 void print_sensor_data(struct bme280_data *comp_data)
\r
134 #ifdef BME280_FLOAT_ENABLE
\r
135 printf("%0.2f, %0.2f, %0.2f\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
\r
137 printf("%ld, %ld, %ld\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
\r
141 ##### Stream sensor data in normal mode
\r
143 int8_t stream_sensor_data_normal_mode(struct bme280_dev *dev)
\r
146 uint8_t settings_sel;
\r
147 struct bme280_data comp_data;
\r
149 /* Recommended mode of operation: Indoor navigation */
\r
150 dev->settings.osr_h = BME280_OVERSAMPLING_1X;
\r
151 dev->settings.osr_p = BME280_OVERSAMPLING_16X;
\r
152 dev->settings.osr_t = BME280_OVERSAMPLING_2X;
\r
153 dev->settings.filter = BME280_FILTER_COEFF_16;
\r
154 dev->settings.standby_time = BME280_STANDBY_TIME_62_5_MS;
\r
156 settings_sel = BME280_OSR_PRESS_SEL;
\r
157 settings_sel |= BME280_OSR_TEMP_SEL;
\r
158 settings_sel |= BME280_OSR_HUM_SEL;
\r
159 settings_sel |= BME280_STANDBY_SEL;
\r
160 settings_sel |= BME280_FILTER_SEL;
\r
161 rslt = bme280_set_sensor_settings(settings_sel, dev);
\r
162 rslt = bme280_set_sensor_mode(BME280_NORMAL_MODE, dev);
\r
164 printf("Temperature, Pressure, Humidity\r\n");
\r
166 /* Delay while the sensor completes a measurement */
\r
167 dev->delay_ms(70, dev->intf_ptr);
\r
168 rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);
\r
169 print_sensor_data(&comp_data);
\r
175 void print_sensor_data(struct bme280_data *comp_data)
\r
177 #ifdef BME280_FLOAT_ENABLE
\r
178 printf("%0.2f, %0.2f, %0.2f\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
\r
180 printf("%ld, %ld, %ld\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
\r
185 ### Templates for function pointers
\r
188 void user_delay_ms(uint32_t period, void *intf_ptr)
\r
191 * Return control or wait,
\r
192 * for a period amount of milliseconds
\r
196 int8_t user_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
\r
198 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
\r
201 * The parameter intf_ptr can be used as a variable to select which Chip Select pin has
\r
202 * to be set low to activate the relevant device on the SPI bus
\r
206 * Data on the bus should be like
\r
207 * |----------------+---------------------+-------------|
\r
208 * | MOSI | MISO | Chip Select |
\r
209 * |----------------+---------------------|-------------|
\r
210 * | (don't care) | (don't care) | HIGH |
\r
211 * | (reg_addr) | (don't care) | LOW |
\r
212 * | (don't care) | (reg_data[0]) | LOW |
\r
213 * | (....) | (....) | LOW |
\r
214 * | (don't care) | (reg_data[len - 1]) | LOW |
\r
215 * | (don't care) | (don't care) | HIGH |
\r
216 * |----------------+---------------------|-------------|
\r
222 int8_t user_spi_write(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
\r
224 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
\r
227 * The parameter intf_ptr can be used as a variable to select which Chip Select pin has
\r
228 * to be set low to activate the relevant device on the SPI bus
\r
232 * Data on the bus should be like
\r
233 * |---------------------+--------------+-------------|
\r
234 * | MOSI | MISO | Chip Select |
\r
235 * |---------------------+--------------|-------------|
\r
236 * | (don't care) | (don't care) | HIGH |
\r
237 * | (reg_addr) | (don't care) | LOW |
\r
238 * | (reg_data[0]) | (don't care) | LOW |
\r
239 * | (....) | (....) | LOW |
\r
240 * | (reg_data[len - 1]) | (don't care) | LOW |
\r
241 * | (don't care) | (don't care) | HIGH |
\r
242 * |---------------------+--------------|-------------|
\r
248 int8_t user_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
\r
250 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
\r
253 * The parameter intf_ptr can be used as a variable to store the I2C address of the device
\r
257 * Data on the bus should be like
\r
258 * |------------+---------------------|
\r
259 * | I2C action | Data |
\r
260 * |------------+---------------------|
\r
262 * | Write | (reg_addr) |
\r
265 * | Read | (reg_data[0]) |
\r
266 * | Read | (....) |
\r
267 * | Read | (reg_data[len - 1]) |
\r
269 * |------------+---------------------|
\r
275 int8_t user_i2c_write(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
\r
277 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
\r
280 * The parameter intf_ptr can be used as a variable to store the I2C address of the device
\r
284 * Data on the bus should be like
\r
285 * |------------+---------------------|
\r
286 * | I2C action | Data |
\r
287 * |------------+---------------------|
\r
289 * | Write | (reg_addr) |
\r
290 * | Write | (reg_data[0]) |
\r
291 * | Write | (....) |
\r
292 * | Write | (reg_data[len - 1]) |
\r
294 * |------------+---------------------|
\r