3 This package contains the Bosch Sensortec's BME280 pressure sensor driver (sensor API)
5 The sensor driver package includes bme280.c, bme280.h and bme280_defs.h files.
9 --------------|---------|------------
10 bme280.c | 3.3.1 | 07 Nov 2017
11 bme280.h | 3.3.1 | 07 Nov 2017
12 bme280_defs.h | 3.3.1 | 07 Nov 2017
14 ## Integration details
15 * Integrate bme280.h, bme280_defs.h and bme280.c file in to the project.
16 * Include the bme280.h file in your code like below.
22 * bme280_defs.h : This header file has the constants, macros and datatype declarations.
23 * bme280.h : This header file contains the declarations of the sensor driver APIs.
24 * bme280.c : This source file contains the definitions of the sensor driver APIs.
26 ## Supported sensor interfaces
30 SPI 3-wire is currently not supported in the API.
32 ### Initializing the sensor
33 To initialize the sensor, user need to create a device structure. User can do this by
34 creating an instance of the structure bme280_dev. After creating the device strcuture, user
35 need to fill in the various parameters as shown below.
37 #### Example for SPI 4-Wire
39 struct bme280_dev dev;
40 int8_t rslt = BME280_OK;
42 /* Sensor_0 interface over SPI with native chip select line */
44 dev.intf = BME280_SPI_INTF;
45 dev.read = user_spi_read;
46 dev.write = user_spi_write;
47 dev.delay_ms = user_delay_ms;
49 rslt = bme280_init(&dev);
53 struct bme280_dev dev;
54 int8_t rslt = BME280_OK;
56 dev.dev_id = BME280_I2C_ADDR_PRIM;
57 dev.intf = BME280_I2C_INTF;
58 dev.read = user_i2c_read;
59 dev.write = user_i2c_write;
60 dev.delay_ms = user_delay_ms;
62 rslt = bme280_init(&dev);
64 Regarding compensation functions for temperature,pressure and humidity we have two implementations.
65 1) Double precision floating point version
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.
70 In integer compensation functions, we also have below two implementations for pressure.
71 1) For 32 bit machine.
72 2) For 64 bit machine.
74 By default, 64 bit variant is used in the API. If the user wants 32 bit variant, the user can disable the
75 macro BME280_64BIT_ENABLE in bme280_defs.h file.
77 ### Stream sensor data
78 #### Stream sensor data in forced mode
81 int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev)
85 struct bme280_data comp_data;
87 /* Recommended mode of operation: Indoor navigation */
88 dev->settings.osr_h = BME280_OVERSAMPLING_1X;
89 dev->settings.osr_p = BME280_OVERSAMPLING_16X;
90 dev->settings.osr_t = BME280_OVERSAMPLING_2X;
91 dev->settings.filter = BME280_FILTER_COEFF_16;
93 settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL;
95 rslt = bme280_set_sensor_settings(settings_sel, dev);
97 printf("Temperature, Pressure, Humidity\r\n");
98 /* Continuously stream sensor data */
100 rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, dev);
101 /* Wait for the measurement to complete and print data @25Hz */
103 rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);
104 print_sensor_data(&comp_data);
109 void print_sensor_data(struct bme280_data *comp_data)
111 #ifdef BME280_FLOAT_ENABLE
112 printf("%0.2f, %0.2f, %0.2f\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
114 printf("%ld, %ld, %ld\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
118 ##### Stream sensor data in normal mode
120 int8_t stream_sensor_data_normal_mode(struct bme280_dev *dev)
123 uint8_t settings_sel;
124 struct bme280_data comp_data;
126 /* Recommended mode of operation: Indoor navigation */
127 dev->settings.osr_h = BME280_OVERSAMPLING_1X;
128 dev->settings.osr_p = BME280_OVERSAMPLING_16X;
129 dev->settings.osr_t = BME280_OVERSAMPLING_2X;
130 dev->settings.filter = BME280_FILTER_COEFF_16;
131 dev->settings.standby_time = BME280_STANDBY_TIME_62_5_MS;
133 settings_sel = BME280_OSR_PRESS_SEL;
134 settings_sel |= BME280_OSR_TEMP_SEL;
135 settings_sel |= BME280_OSR_HUM_SEL;
136 settings_sel |= BME280_STANDBY_SEL;
137 settings_sel |= BME280_FILTER_SEL;
138 rslt = bme280_set_sensor_settings(settings_sel, dev);
139 rslt = bme280_set_sensor_mode(BME280_NORMAL_MODE, dev);
141 printf("Temperature, Pressure, Humidity\r\n");
143 /* Delay while the sensor completes a measurement */
145 rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);
146 print_sensor_data(&comp_data);
152 void print_sensor_data(struct bme280_data *comp_data)
154 #ifdef BME280_FLOAT_ENABLE
155 printf("%0.2f, %0.2f, %0.2f\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
157 printf("%ld, %ld, %ld\r\n",comp_data->temperature, comp_data->pressure, comp_data->humidity);
162 ### Templates for function pointers
165 void user_delay_ms(uint32_t period)
168 * Return control or wait,
169 * for a period amount of milliseconds
173 int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
175 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
178 * The parameter dev_id can be used as a variable to select which Chip Select pin has
179 * to be set low to activate the relevant device on the SPI bus
183 * Data on the bus should be like
184 * |----------------+---------------------+-------------|
185 * | MOSI | MISO | Chip Select |
186 * |----------------+---------------------|-------------|
187 * | (don't care) | (don't care) | HIGH |
188 * | (reg_addr) | (don't care) | LOW |
189 * | (don't care) | (reg_data[0]) | LOW |
190 * | (....) | (....) | LOW |
191 * | (don't care) | (reg_data[len - 1]) | LOW |
192 * | (don't care) | (don't care) | HIGH |
193 * |----------------+---------------------|-------------|
199 int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
201 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
204 * The parameter dev_id can be used as a variable to select which Chip Select pin has
205 * to be set low to activate the relevant device on the SPI bus
209 * Data on the bus should be like
210 * |---------------------+--------------+-------------|
211 * | MOSI | MISO | Chip Select |
212 * |---------------------+--------------|-------------|
213 * | (don't care) | (don't care) | HIGH |
214 * | (reg_addr) | (don't care) | LOW |
215 * | (reg_data[0]) | (don't care) | LOW |
216 * | (....) | (....) | LOW |
217 * | (reg_data[len - 1]) | (don't care) | LOW |
218 * | (don't care) | (don't care) | HIGH |
219 * |---------------------+--------------|-------------|
225 int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
227 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
230 * The parameter dev_id can be used as a variable to store the I2C address of the device
234 * Data on the bus should be like
235 * |------------+---------------------|
236 * | I2C action | Data |
237 * |------------+---------------------|
239 * | Write | (reg_addr) |
242 * | Read | (reg_data[0]) |
244 * | Read | (reg_data[len - 1]) |
246 * |------------+---------------------|
252 int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
254 int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
257 * The parameter dev_id can be used as a variable to store the I2C address of the device
261 * Data on the bus should be like
262 * |------------+---------------------|
263 * | I2C action | Data |
264 * |------------+---------------------|
266 * | Write | (reg_addr) |
267 * | Write | (reg_data[0]) |
269 * | Write | (reg_data[len - 1]) |
271 * |------------+---------------------|
279 ## Copyright (C) 2016 - 2017 Bosch Sensortec GmbH