3 ****************************************************************************
4 * Copyright (C) 2015 - 2016 Bosch Sensortec GmbH
10 * Revision : 2.0.5(Pressure and Temperature compensation code revision is 1.1
11 * and Humidity compensation code revision is 1.0)
13 * Usage: Sensor Driver for BME280 sensor
15 ****************************************************************************
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions are met:
22 * Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
25 * Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
29 * Neither the name of the copyright holder nor the names of the
30 * contributors may be used to endorse or promote products derived from
31 * this software without specific prior written permission.
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
34 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
35 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
38 * OR CONTRIBUTORS BE LIABLE FOR ANY
39 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
40 * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
41 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
46 * ANY WAY OUT OF THE USE OF THIS
47 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
49 * The information provided is believed to be accurate and reliable.
50 * The copyright holder assumes no responsibility
51 * for the consequences of use
52 * of such information nor for any infringement of patents or
53 * other rights of third parties which may result from its use.
54 * No license is granted by implication or otherwise under any patent or
55 * patent rights of the copyright holder.
56 **************************************************************************/
58 \brief BME280 Sensor Driver Support Header File */
64 * @brief The following definition uses for define the data types
66 * @note While porting the API please consider the following
67 * @note Please check the version of C standard
68 * @note Are you using Linux platform
72 * @brief For the Linux platform support
73 * Please use the types.h for your data types definitions
77 #include <linux/types.h>
78 #include <linux/math64.h>
79 #define BME280_64BITSUPPORT_PRESENT
80 /* singed integer type*/
81 typedef int8_t s8;/**< used for signed 8bit */
82 typedef int16_t s16;/**< used for signed 16bit */
83 typedef int32_t s32;/**< used for signed 32bit */
84 typedef int64_t s64;/**< used for signed 64bit */
86 typedef u_int8_t u8;/**< used for unsigned 8bit */
87 typedef u_int16_t u16;/**< used for unsigned 16bit */
88 typedef u_int32_t u32;/**< used for unsigned 32bit */
89 typedef u_int64_t u64;/**< used for unsigned 64bit */
93 #else /* ! __KERNEL__ */
94 /**********************************************************
95 * These definition uses for define the C
96 * standard version data types
97 ***********************************************************/
98 # if defined(__STDC_VERSION__)
100 /************************************************
101 * compiler is C11 C standard
102 ************************************************/
103 #if (__STDC_VERSION__ == 201112L)
105 /************************************************/
107 /************************************************/
109 /*unsigned integer types*/
110 typedef uint8_t u8;/**< used for unsigned 8bit */
111 typedef uint16_t u16;/**< used for unsigned 16bit */
112 typedef uint32_t u32;/**< used for unsigned 32bit */
113 typedef uint64_t u64;/**< used for unsigned 64bit */
115 /*signed integer types*/
116 typedef int8_t s8;/**< used for signed 8bit */
117 typedef int16_t s16;/**< used for signed 16bit */
118 typedef int32_t s32;/**< used for signed 32bit */
119 typedef int64_t s64;/**< used for signed 64bit */
120 #define BME280_64BITSUPPORT_PRESENT
121 /************************************************
122 * compiler is C99 C standard
123 ************************************************/
125 #elif (__STDC_VERSION__ == 199901L)
127 /* stdint.h is a C99 supported c library.
128 which is used to fixed the integer size*/
129 /************************************************/
131 /************************************************/
133 /*unsigned integer types*/
134 typedef uint8_t u8;/**< used for unsigned 8bit */
135 typedef uint16_t u16;/**< used for unsigned 16bit */
136 typedef uint32_t u32;/**< used for unsigned 32bit */
137 typedef uint64_t u64;/**< used for unsigned 64bit */
139 /*signed integer types*/
140 typedef int8_t s8;/**< used for signed 8bit */
141 typedef int16_t s16;/**< used for signed 16bit */
142 typedef int32_t s32;/**< used for signed 32bit */
143 typedef int64_t s64;/**< used for signed 64bit */
144 #define BME280_64BITSUPPORT_PRESENT
145 /************************************************
146 * compiler is C89 or other C standard
147 ************************************************/
149 #else /* !defined(__STDC_VERSION__) */
151 * @brief By default it is defined as 32 bit machine configuration
152 * define your data types based on your
153 * machine/compiler/controller configuration
155 #define MACHINE_32_BIT
158 * If your machine support 16 bit
159 * define the MACHINE_16_BIT
161 #ifdef MACHINE_16_BIT
163 /*signed integer types*/
164 typedef signed char s8;/**< used for signed 8bit */
165 typedef signed short int s16;/**< used for signed 16bit */
166 typedef signed long int s32;/**< used for signed 32bit */
168 #if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL
169 typedef long int s64;/**< used for signed 64bit */
170 typedef unsigned long int u64;/**< used for unsigned 64bit */
171 #define BME280_64BITSUPPORT_PRESENT
172 #elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL)
173 typedef long long int s64;/**< used for signed 64bit */
174 typedef unsigned long long int u64;/**< used for unsigned 64bit */
175 #define BME280_64BITSUPPORT_PRESENT
177 #warning Either the correct data type for signed 64 bit integer \
178 could not be found, or 64 bit integers are not supported in your environment.
179 #warning The API will only offer 32 bit pressure calculation.This will \
180 slightly impede accuracy(noise of ~1 pascal RMS will be added to output).
181 #warning If 64 bit integers are supported on your platform, \
182 please set s64 manually and "#define(BME280_64BITSUPPORT_PRESENT)" manually.
185 /*unsigned integer types*/
186 typedef unsigned char u8;/**< used for unsigned 8bit */
187 typedef unsigned short int u16;/**< used for unsigned 16bit */
188 typedef unsigned long int u32;/**< used for unsigned 32bit */
190 /* If your machine support 32 bit
191 define the MACHINE_32_BIT*/
192 #elif defined MACHINE_32_BIT
193 /*signed integer types*/
194 typedef signed char s8;/**< used for signed 8bit */
195 typedef signed short int s16;/**< used for signed 16bit */
196 typedef signed int s32;/**< used for signed 32bit */
197 typedef signed long long int s64;/**< used for signed 64bit */
199 /*unsigned integer types*/
200 typedef unsigned char u8;/**< used for unsigned 8bit */
201 typedef unsigned short int u16;/**< used for unsigned 16bit */
202 typedef unsigned int u32;/**< used for unsigned 32bit */
203 typedef unsigned long long int u64;/**< used for unsigned 64bit */
205 * If your machine support 64 bit
206 * define the MACHINE_64_BIT
208 #define BME280_64BITSUPPORT_PRESENT
210 /* If your machine support 64 bit
211 define the MACHINE_64_BIT*/
212 #elif defined MACHINE_64_BIT
213 /*signed integer types*/
214 typedef signed char s8;/**< used for signed 8bit */
215 typedef signed short int s16;/**< used for signed 16bit */
216 typedef signed int s32;/**< used for signed 32bit */
217 typedef signed long int s64;/**< used for signed 64bit */
219 /*unsigned integer types*/
220 typedef unsigned char u8;/**< used for unsigned 8bit */
221 typedef unsigned short int u16;/**< used for unsigned 16bit */
222 typedef unsigned int u32;/**< used for unsigned 32bit */
223 typedef unsigned long int u64;/**< used for unsigned 64bit */
224 #define BME280_64BITSUPPORT_PRESENT
227 #warning The data types defined above which not supported \
228 define the data types manually
232 /*** This else will execute for the compilers
233 * which are not supported the C standards
234 * Like C89/C99/C11***/
237 * @brief By default it is defined as 32 bit machine configuration
238 * define your data types based on your
239 * machine/compiler/controller configuration
241 #define MACHINE_32_BIT
243 /* If your machine support 16 bit
244 define the MACHINE_16_BIT*/
245 #ifdef MACHINE_16_BIT
247 /*signed integer types*/
248 typedef signed char s8;/**< used for signed 8bit */
249 typedef signed short int s16;/**< used for signed 16bit */
250 typedef signed long int s32;/**< used for signed 32bit */
252 #if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL
253 typedef long int s64;/**< used for signed 64bit */
254 typedef unsigned long int u64;/**< used for unsigned 64bit */
255 #define BME280_64BITSUPPORT_PRESENT
256 #elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL)
257 typedef long long int s64;/**< used for signed 64bit */
258 typedef unsigned long long int u64;/**< used for unsigned 64bit */
259 #define BME280_64BITSUPPORT_PRESENT
261 #warning Either the correct data type for signed 64 bit integer \
262 could not be found, or 64 bit integers are not supported in your environment.
263 #warning The API will only offer 32 bit pressure calculation.This will \
264 slightly impede accuracy(noise of ~1 pascal RMS will be added to output).
265 #warning If 64 bit integers are supported on your platform, \
266 please set s64 manually and "#define(BME280_64BITSUPPORT_PRESENT)" manually.
269 /*unsigned integer types*/
270 typedef unsigned char u8;/**< used for unsigned 8bit */
271 typedef unsigned short int u16;/**< used for unsigned 16bit */
272 typedef unsigned long int u32;/**< used for unsigned 32bit */
274 /*! @brief If your machine support 32 bit
275 define the MACHINE_32_BIT*/
276 #elif defined MACHINE_32_BIT
277 /*signed integer types*/
278 typedef signed char s8;/**< used for signed 8bit */
279 typedef signed short int s16;/**< used for signed 16bit */
280 typedef signed int s32;/**< used for signed 32bit */
281 typedef signed long long int s64;/**< used for signed 64bit */
283 /*unsigned integer types*/
284 typedef unsigned char u8;/**< used for unsigned 8bit */
285 typedef unsigned short int u16;/**< used for unsigned 16bit */
286 typedef unsigned int u32;/**< used for unsigned 32bit */
287 typedef unsigned long long int u64;/**< used for unsigned 64bit */
288 #define BME280_64BITSUPPORT_PRESENT
290 /* If your machine support 64 bit
291 define the MACHINE_64_BIT*/
292 #elif defined MACHINE_64_BIT
293 /*signed integer types*/
294 typedef signed char s8;/**< used for signed 8bit */
295 typedef signed short int s16;/**< used for signed 16bit */
296 typedef signed int s32;/**< used for signed 32bit */
297 typedef signed long int s64;/**< used for signed 64bit */
299 /*unsigned integer types*/
300 typedef unsigned char u8;/**< used for unsigned 8bit */
301 typedef unsigned short int u16;/**< used for unsigned 16bit */
302 typedef unsigned int u32;/**< used for unsigned 32bit */
303 typedef unsigned long int u64;/**< used for unsigned 64bit */
304 #define BME280_64BITSUPPORT_PRESENT
307 #warning The data types defined above which not supported \
308 define the data types manually
312 /********************************************/
313 /**\name ENABLE FLOATING OUTPUT */
314 /**************************************/
316 * @brief If the user wants to support floating point calculations, please set
317 the following define. If floating point
318 calculation is not wanted or allowed
319 (e.g. in Linux kernel), please do not set the define. */
320 #define BME280_ENABLE_FLOAT
322 * @brief If the user wants to support 64 bit integer calculation
323 (needed for optimal pressure accuracy) please set
324 the following define. If int64 calculation is not wanted
325 (e.g. because it would include
326 large libraries), please do not set the define. */
327 #define BME280_ENABLE_INT64
328 /***************************************************************/
329 /**\name BUS READ AND WRITE FUNCTION POINTERS */
330 /***************************************************************/
332 @brief Define the calling convention of YOUR bus communication routine.
333 @note This includes types of parameters. This example shows the
334 configuration for an SPI bus link.
336 If your communication function looks like this:
338 write_my_bus_xy(u8 device_addr, u8 register_addr,
339 u8 * data, u8 length);
341 The BME280_WR_FUNC_PTR would equal:
343 BME280_WR_FUNC_PTR s8 (* bus_write)(u8,
346 Parameters can be mixed as needed refer to the
347 refer BME280_BUS_WRITE_FUNC macro.
351 /** defines the return parameter type of the BME280_WR_FUNCTION */
352 #define BME280_BUS_WR_RETURN_TYPE s8
354 /* links the order of parameters defined in
355 BME280_BUS_WR_PARAM_TYPE to function calls used inside the API*/
356 #define BME280_BUS_WR_PARAM_TYPES u8, u8,\
359 /* links the order of parameters defined in
360 BME280_BUS_WR_PARAM_TYPE to function calls used inside the API*/
361 #define BME280_BUS_WR_PARAM_ORDER(device_addr, register_addr,\
362 register_data, wr_len)
364 /* never change this line */
365 #define BME280_BUS_WRITE_FUNC(device_addr, register_addr,\
366 register_data, wr_len) bus_write(device_addr, register_addr,\
367 register_data, wr_len)
369 @brief link macro between API function calls and bus read function
370 @note The bus write function can change since this is a
371 system dependant issue.
373 If the bus_read parameter calling order is like: reg_addr,
374 reg_data, wr_len it would be as it is here.
376 If the parameters are differently ordered or your communication
377 function like I2C need to know the device address,
378 you can change this macro accordingly.
381 BME280_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, wr_len)\
382 bus_read(dev_addr, reg_addr, reg_data, wr_len)
384 This macro lets all API functions call YOUR communication routine in a
385 way that equals your definition in the
386 refer BME280_WR_FUNC_PTR definition.
388 @note: this macro also includes the "MSB='1'
389 for reading BME280 addresses.
392 /*defines the return parameter type of the BME280_RD_FUNCTION
394 #define BME280_BUS_RD_RETURN_TYPE s8
396 /**\brief defines the calling parameter types of the BME280_RD_FUNCTION
398 #define BME280_BUS_RD_PARAM_TYPES (u8, u8,\
401 /* links the order of parameters defined in \
402 BME280_BUS_RD_PARAM_TYPE to function calls used inside the API
404 #define BME280_BUS_RD_PARAM_ORDER (device_addr, register_addr,\
407 /* never change this line */
408 #define BME280_BUS_READ_FUNC(device_addr, register_addr,\
409 register_data, rd_len)bus_read(device_addr, register_addr,\
410 register_data, rd_len)
411 /****************************************/
413 /****************************************/
414 /* defines the return parameter type of the BME280_DELAY_FUNCTION
416 #define BME280_DELAY_RETURN_TYPE void
418 /* defines the calling parameter types of the BME280_DELAY_FUNCTION
420 #define BME280_DELAY_PARAM_TYPES u16
421 /***************************************************************/
422 /**\name GET AND SET BITSLICE FUNCTIONS */
423 /***************************************************************/
424 /* never change this line */
425 #define BME280_DELAY_FUNC(delay_in_msec)\
426 delay_func(delay_in_msec)
428 #define BME280_GET_BITSLICE(regvar, bitname)\
429 ((regvar & bitname##__MSK) >> bitname##__POS)
431 #define BME280_SET_BITSLICE(regvar, bitname, val)\
432 ((regvar & ~bitname##__MSK) | ((val<<bitname##__POS)&bitname##__MSK))
434 /***************************************************************/
435 /**\name COMMON USED CONSTANTS */
436 /***************************************************************/
438 #define BME280_NULL (0)
439 #define BME280_RETURN_FUNCTION_TYPE s8
440 /* shift definitions*/
441 #define BME280_SHIFT_BIT_POSITION_BY_01_BIT (1)
442 #define BME280_SHIFT_BIT_POSITION_BY_02_BITS (2)
443 #define BME280_SHIFT_BIT_POSITION_BY_03_BITS (3)
444 #define BME280_SHIFT_BIT_POSITION_BY_04_BITS (4)
445 #define BME280_SHIFT_BIT_POSITION_BY_07_BITS (7)
446 #define BME280_SHIFT_BIT_POSITION_BY_08_BITS (8)
447 #define BME280_SHIFT_BIT_POSITION_BY_10_BITS (10)
448 #define BME280_SHIFT_BIT_POSITION_BY_11_BITS (11)
449 #define BME280_SHIFT_BIT_POSITION_BY_12_BITS (12)
450 #define BME280_SHIFT_BIT_POSITION_BY_13_BITS (13)
451 #define BME280_SHIFT_BIT_POSITION_BY_14_BITS (14)
452 #define BME280_SHIFT_BIT_POSITION_BY_15_BITS (15)
453 #define BME280_SHIFT_BIT_POSITION_BY_16_BITS (16)
454 #define BME280_SHIFT_BIT_POSITION_BY_17_BITS (17)
455 #define BME280_SHIFT_BIT_POSITION_BY_18_BITS (18)
456 #define BME280_SHIFT_BIT_POSITION_BY_19_BITS (19)
457 #define BME280_SHIFT_BIT_POSITION_BY_20_BITS (20)
458 #define BME280_SHIFT_BIT_POSITION_BY_25_BITS (25)
459 #define BME280_SHIFT_BIT_POSITION_BY_31_BITS (31)
460 #define BME280_SHIFT_BIT_POSITION_BY_33_BITS (33)
461 #define BME280_SHIFT_BIT_POSITION_BY_35_BITS (35)
462 #define BME280_SHIFT_BIT_POSITION_BY_47_BITS (47)
464 /* numeric definitions */
465 #define BME280_PRESSURE_TEMPERATURE_CALIB_DATA_LENGTH (26)
466 #define BME280_HUMIDITY_CALIB_DATA_LENGTH (7)
467 #define BME280_GEN_READ_WRITE_DATA_LENGTH (1)
468 #define BME280_HUMIDITY_DATA_LENGTH (2)
469 #define BME280_TEMPERATURE_DATA_LENGTH (3)
470 #define BME280_PRESSURE_DATA_LENGTH (3)
471 #define BME280_ALL_DATA_FRAME_LENGTH (8)
472 #define BME280_INIT_VALUE (0)
473 #define BME280_CHIP_ID_READ_COUNT (5)
474 #define BME280_INVALID_DATA (0)
476 /****************************************************/
477 /**\name ERROR CODE DEFINITIONS */
478 /***************************************************/
479 #define SUCCESS ((u8)0)
480 #define E_BME280_NULL_PTR ((s8)-127)
481 #define E_BME280_COMM_RES ((s8)-1)
482 #define E_BME280_OUT_OF_RANGE ((s8)-2)
483 #define ERROR ((s8)-1)
484 #define BME280_CHIP_ID_READ_FAIL ((s8)-1)
485 #define BME280_CHIP_ID_READ_SUCCESS ((u8)0)
487 /****************************************************/
488 /**\name CHIP ID DEFINITIONS */
489 /***************************************************/
490 #define BME280_CHIP_ID (0x60)
492 /****************************************************/
493 /**\name I2C ADDRESS DEFINITIONS */
494 /***************************************************/
495 #define BME280_I2C_ADDRESS1 (0x76)
496 #define BME280_I2C_ADDRESS2 (0x77)
497 /****************************************************/
498 /**\name POWER MODE DEFINITIONS */
499 /***************************************************/
500 /* Sensor Specific constants */
501 #define BME280_SLEEP_MODE (0x00)
502 #define BME280_FORCED_MODE (0x01)
503 #define BME280_NORMAL_MODE (0x03)
504 #define BME280_SOFT_RESET_CODE (0xB6)
505 /****************************************************/
506 /**\name STANDBY DEFINITIONS */
507 /***************************************************/
508 #define BME280_STANDBY_TIME_1_MS (0x00)
509 #define BME280_STANDBY_TIME_63_MS (0x01)
510 #define BME280_STANDBY_TIME_125_MS (0x02)
511 #define BME280_STANDBY_TIME_250_MS (0x03)
512 #define BME280_STANDBY_TIME_500_MS (0x04)
513 #define BME280_STANDBY_TIME_1000_MS (0x05)
514 #define BME280_STANDBY_TIME_10_MS (0x06)
515 #define BME280_STANDBY_TIME_20_MS (0x07)
516 /****************************************************/
517 /**\name OVER SAMPLING DEFINITIONS */
518 /***************************************************/
519 #define BME280_OVERSAMP_SKIPPED (0x00)
520 #define BME280_OVERSAMP_1X (0x01)
521 #define BME280_OVERSAMP_2X (0x02)
522 #define BME280_OVERSAMP_4X (0x03)
523 #define BME280_OVERSAMP_8X (0x04)
524 #define BME280_OVERSAMP_16X (0x05)
525 /****************************************************/
526 /**\name WORK MODE DEFINITIONS */
527 /***************************************************/
528 /*#define BME280_ULTRALOWPOWER_MODE (0x00)
529 #define BME280_LOWPOWER_MODE (0x01)
530 #define BME280_STANDARDRESOLUTION_MODE (0x02)
531 #define BME280_HIGHRESOLUTION_MODE (0x03)
532 #define BME280_ULTRAHIGHRESOLUTION_MODE (0x04)
534 #define BME280_ULTRALOWPOWER_OSRS_P BME280_OVERSAMP_1X
535 #define BME280_ULTRALOWPOWER_OSRS_T BME280_OVERSAMP_1X
537 #define BME280_LOWPOWER_OSRS_P BME280_OVERSAMP_2X
538 #define BME280_LOWPOWER_OSRS_T BME280_OVERSAMP_1X
540 #define BME280_STANDARDRESOLUTION_OSRS_P BME280_OVERSAMP_4X
541 #define BME280_STANDARDRESOLUTION_OSRS_T BME280_OVERSAMP_1X
543 #define BME280_HIGHRESOLUTION_OSRS_P BME280_OVERSAMP_8X
544 #define BME280_HIGHRESOLUTION_OSRS_T BME280_OVERSAMP_1X
546 #define BME280_ULTRAHIGHRESOLUTION_OSRS_P BME280_OVERSAMP_16X
547 #define BME280_ULTRAHIGHRESOLUTION_OSRS_T BME280_OVERSAMP_2X */
549 #define BME280_STANDARD_OVERSAMP_HUMIDITY BME280_OVERSAMP_1X
550 /****************************************************/
551 /**\name FILTER DEFINITIONS */
552 /***************************************************/
553 #define BME280_FILTER_COEFF_OFF (0x00)
554 #define BME280_FILTER_COEFF_2 (0x01)
555 #define BME280_FILTER_COEFF_4 (0x02)
556 #define BME280_FILTER_COEFF_8 (0x03)
557 #define BME280_FILTER_COEFF_16 (0x04)
558 /****************************************************/
559 /**\name DELAY DEFINITIONS */
560 /***************************************************/
561 #define T_INIT_MAX (20)
562 /* 20/16 = 1.25 ms */
563 #define T_MEASURE_PER_OSRS_MAX (37)
564 /* 37/16 = 2.3125 ms*/
566 #define T_SETUP_PRESSURE_MAX (10)
567 /* 10/16 = 0.625 ms */
569 #define T_SETUP_HUMIDITY_MAX (10)
570 /* 10/16 = 0.625 ms */
571 /****************************************************/
572 /**\name DEFINITIONS FOR ARRAY SIZE OF DATA */
573 /***************************************************/
574 #define BME280_HUMIDITY_DATA_SIZE (2)
575 #define BME280_TEMPERATURE_DATA_SIZE (3)
576 #define BME280_PRESSURE_DATA_SIZE (3)
577 #define BME280_DATA_FRAME_SIZE (8)
578 /**< data frames includes temperature,
579 pressure and humidity*/
580 #define BME280_CALIB_DATA_SIZE (26)
582 #define BME280_TEMPERATURE_MSB_DATA (0)
583 #define BME280_TEMPERATURE_LSB_DATA (1)
584 #define BME280_TEMPERATURE_XLSB_DATA (2)
585 #define BME280_PRESSURE_MSB_DATA (0)
586 #define BME280_PRESSURE_LSB_DATA (1)
587 #define BME280_PRESSURE_XLSB_DATA (2)
588 #define BME280_HUMIDITY_MSB_DATA (0)
589 #define BME280_HUMIDITY_LSB_DATA (1)
591 #define BME280_DATA_FRAME_PRESSURE_MSB_BYTE (0)
592 #define BME280_DATA_FRAME_PRESSURE_LSB_BYTE (1)
593 #define BME280_DATA_FRAME_PRESSURE_XLSB_BYTE (2)
594 #define BME280_DATA_FRAME_TEMPERATURE_MSB_BYTE (3)
595 #define BME280_DATA_FRAME_TEMPERATURE_LSB_BYTE (4)
596 #define BME280_DATA_FRAME_TEMPERATURE_XLSB_BYTE (5)
597 #define BME280_DATA_FRAME_HUMIDITY_MSB_BYTE (6)
598 #define BME280_DATA_FRAME_HUMIDITY_LSB_BYTE (7)
599 /****************************************************/
600 /**\name ARRAY PARAMETER FOR CALIBRATION */
601 /***************************************************/
602 #define BME280_TEMPERATURE_CALIB_DIG_T1_LSB (0)
603 #define BME280_TEMPERATURE_CALIB_DIG_T1_MSB (1)
604 #define BME280_TEMPERATURE_CALIB_DIG_T2_LSB (2)
605 #define BME280_TEMPERATURE_CALIB_DIG_T2_MSB (3)
606 #define BME280_TEMPERATURE_CALIB_DIG_T3_LSB (4)
607 #define BME280_TEMPERATURE_CALIB_DIG_T3_MSB (5)
608 #define BME280_PRESSURE_CALIB_DIG_P1_LSB (6)
609 #define BME280_PRESSURE_CALIB_DIG_P1_MSB (7)
610 #define BME280_PRESSURE_CALIB_DIG_P2_LSB (8)
611 #define BME280_PRESSURE_CALIB_DIG_P2_MSB (9)
612 #define BME280_PRESSURE_CALIB_DIG_P3_LSB (10)
613 #define BME280_PRESSURE_CALIB_DIG_P3_MSB (11)
614 #define BME280_PRESSURE_CALIB_DIG_P4_LSB (12)
615 #define BME280_PRESSURE_CALIB_DIG_P4_MSB (13)
616 #define BME280_PRESSURE_CALIB_DIG_P5_LSB (14)
617 #define BME280_PRESSURE_CALIB_DIG_P5_MSB (15)
618 #define BME280_PRESSURE_CALIB_DIG_P6_LSB (16)
619 #define BME280_PRESSURE_CALIB_DIG_P6_MSB (17)
620 #define BME280_PRESSURE_CALIB_DIG_P7_LSB (18)
621 #define BME280_PRESSURE_CALIB_DIG_P7_MSB (19)
622 #define BME280_PRESSURE_CALIB_DIG_P8_LSB (20)
623 #define BME280_PRESSURE_CALIB_DIG_P8_MSB (21)
624 #define BME280_PRESSURE_CALIB_DIG_P9_LSB (22)
625 #define BME280_PRESSURE_CALIB_DIG_P9_MSB (23)
626 #define BME280_HUMIDITY_CALIB_DIG_H1 (25)
627 #define BME280_HUMIDITY_CALIB_DIG_H2_LSB (0)
628 #define BME280_HUMIDITY_CALIB_DIG_H2_MSB (1)
629 #define BME280_HUMIDITY_CALIB_DIG_H3 (2)
630 #define BME280_HUMIDITY_CALIB_DIG_H4_MSB (3)
631 #define BME280_HUMIDITY_CALIB_DIG_H4_LSB (4)
632 #define BME280_HUMIDITY_CALIB_DIG_H5_MSB (5)
633 #define BME280_HUMIDITY_CALIB_DIG_H6 (6)
634 #define BME280_MASK_DIG_H4 (0x0F)
635 /****************************************************/
636 /**\name CALIBRATION REGISTER ADDRESS DEFINITIONS */
637 /***************************************************/
638 /*calibration parameters */
639 #define BME280_TEMPERATURE_CALIB_DIG_T1_LSB_REG (0x88)
640 #define BME280_TEMPERATURE_CALIB_DIG_T1_MSB_REG (0x89)
641 #define BME280_TEMPERATURE_CALIB_DIG_T2_LSB_REG (0x8A)
642 #define BME280_TEMPERATURE_CALIB_DIG_T2_MSB_REG (0x8B)
643 #define BME280_TEMPERATURE_CALIB_DIG_T3_LSB_REG (0x8C)
644 #define BME280_TEMPERATURE_CALIB_DIG_T3_MSB_REG (0x8D)
645 #define BME280_PRESSURE_CALIB_DIG_P1_LSB_REG (0x8E)
646 #define BME280_PRESSURE_CALIB_DIG_P1_MSB_REG (0x8F)
647 #define BME280_PRESSURE_CALIB_DIG_P2_LSB_REG (0x90)
648 #define BME280_PRESSURE_CALIB_DIG_P2_MSB_REG (0x91)
649 #define BME280_PRESSURE_CALIB_DIG_P3_LSB_REG (0x92)
650 #define BME280_PRESSURE_CALIB_DIG_P3_MSB_REG (0x93)
651 #define BME280_PRESSURE_CALIB_DIG_P4_LSB_REG (0x94)
652 #define BME280_PRESSURE_CALIB_DIG_P4_MSB_REG (0x95)
653 #define BME280_PRESSURE_CALIB_DIG_P5_LSB_REG (0x96)
654 #define BME280_PRESSURE_CALIB_DIG_P5_MSB_REG (0x97)
655 #define BME280_PRESSURE_CALIB_DIG_P6_LSB_REG (0x98)
656 #define BME280_PRESSURE_CALIB_DIG_P6_MSB_REG (0x99)
657 #define BME280_PRESSURE_CALIB_DIG_P7_LSB_REG (0x9A)
658 #define BME280_PRESSURE_CALIB_DIG_P7_MSB_REG (0x9B)
659 #define BME280_PRESSURE_CALIB_DIG_P8_LSB_REG (0x9C)
660 #define BME280_PRESSURE_CALIB_DIG_P8_MSB_REG (0x9D)
661 #define BME280_PRESSURE_CALIB_DIG_P9_LSB_REG (0x9E)
662 #define BME280_PRESSURE_CALIB_DIG_P9_MSB_REG (0x9F)
664 #define BME280_HUMIDITY_CALIB_DIG_H1_REG (0xA1)
666 #define BME280_HUMIDITY_CALIB_DIG_H2_LSB_REG (0xE1)
667 #define BME280_HUMIDITY_CALIB_DIG_H2_MSB_REG (0xE2)
668 #define BME280_HUMIDITY_CALIB_DIG_H3_REG (0xE3)
669 #define BME280_HUMIDITY_CALIB_DIG_H4_MSB_REG (0xE4)
670 #define BME280_HUMIDITY_CALIB_DIG_H4_LSB_REG (0xE5)
671 #define BME280_HUMIDITY_CALIB_DIG_H5_MSB_REG (0xE6)
672 #define BME280_HUMIDITY_CALIB_DIG_H6_REG (0xE7)
673 /****************************************************/
674 /**\name REGISTER ADDRESS DEFINITIONS */
675 /***************************************************/
676 #define BME280_CHIP_ID_REG (0xD0) /*Chip ID Register */
677 #define BME280_RST_REG (0xE0) /*Softreset Register */
678 #define BME280_STAT_REG (0xF3) /*Status Register */
679 #define BME280_CTRL_MEAS_REG (0xF4) /*Ctrl Measure Register */
680 #define BME280_CTRL_HUMIDITY_REG (0xF2) /*Ctrl Humidity Register*/
681 #define BME280_CONFIG_REG (0xF5) /*Configuration Register */
682 #define BME280_PRESSURE_MSB_REG (0xF7) /*Pressure MSB Register */
683 #define BME280_PRESSURE_LSB_REG (0xF8) /*Pressure LSB Register */
684 #define BME280_PRESSURE_XLSB_REG (0xF9) /*Pressure XLSB Register */
685 #define BME280_TEMPERATURE_MSB_REG (0xFA) /*Temperature MSB Reg */
686 #define BME280_TEMPERATURE_LSB_REG (0xFB) /*Temperature LSB Reg */
687 #define BME280_TEMPERATURE_XLSB_REG (0xFC) /*Temperature XLSB Reg */
688 #define BME280_HUMIDITY_MSB_REG (0xFD) /*Humidity MSB Reg */
689 #define BME280_HUMIDITY_LSB_REG (0xFE) /*Humidity LSB Reg */
690 /****************************************************/
691 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS */
692 /***************************************************/
693 /* Status Register */
694 #define BME280_STAT_REG_MEASURING__POS (3)
695 #define BME280_STAT_REG_MEASURING__MSK (0x08)
696 #define BME280_STAT_REG_MEASURING__LEN (1)
697 #define BME280_STAT_REG_MEASURING__REG (BME280_STAT_REG)
699 #define BME280_STAT_REG_IM_UPDATE__POS (0)
700 #define BME280_STAT_REG_IM_UPDATE__MSK (0x01)
701 #define BME280_STAT_REG_IM_UPDATE__LEN (1)
702 #define BME280_STAT_REG_IM_UPDATE__REG (BME280_STAT_REG)
703 /****************************************************/
704 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
705 FOR TEMPERATURE OVERSAMPLING */
706 /***************************************************/
707 /* Control Measurement Register */
708 #define BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__POS (5)
709 #define BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__MSK (0xE0)
710 #define BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__LEN (3)
711 #define BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__REG \
712 (BME280_CTRL_MEAS_REG)
713 /****************************************************/
714 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
715 FOR PRESSURE OVERSAMPLING */
716 /***************************************************/
717 #define BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__POS (2)
718 #define BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__MSK (0x1C)
719 #define BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__LEN (3)
720 #define BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__REG \
721 (BME280_CTRL_MEAS_REG)
722 /****************************************************/
723 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
725 /***************************************************/
726 #define BME280_CTRL_MEAS_REG_POWER_MODE__POS (0)
727 #define BME280_CTRL_MEAS_REG_POWER_MODE__MSK (0x03)
728 #define BME280_CTRL_MEAS_REG_POWER_MODE__LEN (2)
729 #define BME280_CTRL_MEAS_REG_POWER_MODE__REG \
730 (BME280_CTRL_MEAS_REG)
731 /****************************************************/
732 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
733 FOR HUMIDITY OVERSAMPLING */
734 /***************************************************/
735 #define BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY__POS (0)
736 #define BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY__MSK (0x07)
737 #define BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY__LEN (3)
738 #define BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY__REG \
739 (BME280_CTRL_HUMIDITY_REG)
740 /****************************************************/
741 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
743 /***************************************************/
744 /* Configuration Register */
745 #define BME280_CONFIG_REG_TSB__POS (5)
746 #define BME280_CONFIG_REG_TSB__MSK (0xE0)
747 #define BME280_CONFIG_REG_TSB__LEN (3)
748 #define BME280_CONFIG_REG_TSB__REG (BME280_CONFIG_REG)
749 /****************************************************/
750 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
752 /***************************************************/
753 #define BME280_CONFIG_REG_FILTER__POS (2)
754 #define BME280_CONFIG_REG_FILTER__MSK (0x1C)
755 #define BME280_CONFIG_REG_FILTER__LEN (3)
756 #define BME280_CONFIG_REG_FILTER__REG (BME280_CONFIG_REG)
757 /****************************************************/
758 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
760 /***************************************************/
761 #define BME280_CONFIG_REG_SPI3_ENABLE__POS (0)
762 #define BME280_CONFIG_REG_SPI3_ENABLE__MSK (0x01)
763 #define BME280_CONFIG_REG_SPI3_ENABLE__LEN (1)
764 #define BME280_CONFIG_REG_SPI3_ENABLE__REG (BME280_CONFIG_REG)
765 /****************************************************/
766 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
767 FOR PRESSURE AND TEMPERATURE DATA */
768 /***************************************************/
770 #define BME280_PRESSURE_XLSB_REG_DATA__POS (4)
771 #define BME280_PRESSURE_XLSB_REG_DATA__MSK (0xF0)
772 #define BME280_PRESSURE_XLSB_REG_DATA__LEN (4)
773 #define BME280_PRESSURE_XLSB_REG_DATA__REG (BME280_PRESSURE_XLSB_REG)
775 #define BME280_TEMPERATURE_XLSB_REG_DATA__POS (4)
776 #define BME280_TEMPERATURE_XLSB_REG_DATA__MSK (0xF0)
777 #define BME280_TEMPERATURE_XLSB_REG_DATA__LEN (4)
778 #define BME280_TEMPERATURE_XLSB_REG_DATA__REG (BME280_TEMPERATURE_XLSB_REG)
779 /****************************************************/
780 /**\name BUS READ AND WRITE FUNCTION POINTERS */
781 /***************************************************/
782 #define BME280_WR_FUNC_PTR\
783 s8 (*bus_write)(u8, u8,\
786 #define BME280_RD_FUNC_PTR\
787 s8 (*bus_read)(u8, u8,\
790 #define BME280_MDELAY_DATA_TYPE u32
792 #define BME280_3MS_DELAY (3)
793 #define BME280_REGISTER_READ_DELAY (1)
794 /**************************************************************/
795 /**\name STRUCTURE DEFINITIONS */
796 /**************************************************************/
798 * @brief This structure holds all device specific calibration parameters
800 struct bme280_calibration_param_t {
801 u16 dig_T1;/**<calibration T1 data*/
802 s16 dig_T2;/**<calibration T2 data*/
803 s16 dig_T3;/**<calibration T3 data*/
804 u16 dig_P1;/**<calibration P1 data*/
805 s16 dig_P2;/**<calibration P2 data*/
806 s16 dig_P3;/**<calibration P3 data*/
807 s16 dig_P4;/**<calibration P4 data*/
808 s16 dig_P5;/**<calibration P5 data*/
809 s16 dig_P6;/**<calibration P6 data*/
810 s16 dig_P7;/**<calibration P7 data*/
811 s16 dig_P8;/**<calibration P8 data*/
812 s16 dig_P9;/**<calibration P9 data*/
814 u8 dig_H1;/**<calibration H1 data*/
815 s16 dig_H2;/**<calibration H2 data*/
816 u8 dig_H3;/**<calibration H3 data*/
817 s16 dig_H4;/**<calibration H4 data*/
818 s16 dig_H5;/**<calibration H5 data*/
819 s8 dig_H6;/**<calibration H6 data*/
821 s32 t_fine;/**<calibration T_FINE data*/
824 * @brief This structure holds BME280 initialization parameters
827 struct bme280_calibration_param_t cal_param;
828 /**< calibration parameters*/
830 u8 chip_id;/**< chip id of the sensor*/
831 u8 dev_addr;/**< device address of the sensor*/
833 u8 oversamp_temperature;/**< temperature over sampling*/
834 u8 oversamp_pressure;/**< pressure over sampling*/
835 u8 oversamp_humidity;/**< humidity over sampling*/
836 u8 ctrl_hum_reg;/**< status of control humidity register*/
837 u8 ctrl_meas_reg;/**< status of control measurement register*/
838 u8 config_reg;/**< status of configuration register*/
840 BME280_WR_FUNC_PTR;/**< bus write function pointer*/
841 BME280_RD_FUNC_PTR;/**< bus read function pointer*/
842 void (*delay_msec)(BME280_MDELAY_DATA_TYPE);/**< delay function pointer*/
844 /**************************************************************/
845 /**\name FUNCTION DECLARATIONS */
846 /**************************************************************/
847 /**************************************************************/
848 /**\name FUNCTION FOR INTIALIZATION */
849 /**************************************************************/
851 * @brief This function is used for initialize
852 * the bus read and bus write functions
853 * and assign the chip id and I2C address of the BME280 sensor
854 * chip id is read in the register 0xD0 bit from 0 to 7
856 * @param bme280 structure pointer.
858 * @note While changing the parameter of the bme280_t
859 * @note consider the following point:
860 * Changing the reference value of the parameter
861 * will changes the local copy or local reference
862 * make sure your changes will not
863 * affect the reference value of the parameter
864 * (Better case don't change the reference value of the parameter)
869 * @return results of bus communication function
870 * @retval 0 -> Success
871 * @retval -1 -> Error
875 BME280_RETURN_FUNCTION_TYPE bme280_init(struct bme280_t *bme280);
876 /**************************************************************/
877 /**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED TEMPERATURE */
878 /**************************************************************/
880 * @brief This API is used to read uncompensated temperature
881 * in the registers 0xFA, 0xFB and 0xFC
882 * @note 0xFA -> MSB -> bit from 0 to 7
883 * @note 0xFB -> LSB -> bit from 0 to 7
884 * @note 0xFC -> LSB -> bit from 4 to 7
886 * @param v_uncomp_temperature_s32 : The value of uncompensated temperature
890 * @return results of bus communication function
891 * @retval 0 -> Success
892 * @retval -1 -> Error
896 BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_temperature(
897 s32 *v_uncomp_temperature_s32);
898 /**************************************************************/
899 /**\name FUNCTION FOR INTIALIZATION TRUE TEMPERATURE */
900 /**************************************************************/
902 * @brief Reads actual temperature from uncompensated temperature
903 * @note Returns the value in 0.01 degree Centigrade
904 * Output value of "5123" equals 51.23 DegC.
908 * @param v_uncomp_temperature_s32 : value of uncompensated temperature
911 * @return Returns the actual temperature
914 s32 bme280_compensate_temperature_int32(s32 v_uncomp_temperature_s32);
916 * @brief Reads actual temperature from uncompensated temperature
917 * @note Returns the value with 500LSB/DegC centred around 24 DegC
918 * output value of "5123" equals(5123/500)+24 = 34.246DegC
921 * @param v_uncomp_temperature_s32: value of uncompensated temperature
925 * @return Return the actual temperature as s16 output
928 s16 bme280_compensate_temperature_int32_sixteen_bit_output(
929 s32 v_uncomp_temperature_s32);
930 /**************************************************************/
931 /**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED PRESSURE */
932 /**************************************************************/
934 * @brief This API is used to read uncompensated pressure.
935 * in the registers 0xF7, 0xF8 and 0xF9
936 * @note 0xF7 -> MSB -> bit from 0 to 7
937 * @note 0xF8 -> LSB -> bit from 0 to 7
938 * @note 0xF9 -> LSB -> bit from 4 to 7
942 * @param v_uncomp_pressure_s32 : The value of uncompensated pressure
946 * @return results of bus communication function
947 * @retval 0 -> Success
948 * @retval -1 -> Error
952 BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure(
953 s32 *v_uncomp_pressure_s32);
954 /**************************************************************/
955 /**\name FUNCTION FOR INTIALIZATION TRUE PRESSURE */
956 /**************************************************************/
958 * @brief Reads actual pressure from uncompensated pressure
959 * @note Returns the value in Pascal(Pa)
960 * Output value of "96386" equals 96386 Pa =
961 * 963.86 hPa = 963.86 millibar
965 * @param v_uncomp_pressure_s32 : value of uncompensated pressure
969 * @return Return the actual pressure output as u32
972 u32 bme280_compensate_pressure_int32(s32 v_uncomp_pressure_s32);
973 /**************************************************************/
974 /**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED HUMIDITY */
975 /**************************************************************/
977 * @brief This API is used to read uncompensated humidity.
978 * in the registers 0xF7, 0xF8 and 0xF9
979 * @note 0xFD -> MSB -> bit from 0 to 7
980 * @note 0xFE -> LSB -> bit from 0 to 7
984 * @param v_uncomp_humidity_s32 : The value of uncompensated humidity
988 * @return results of bus communication function
989 * @retval 0 -> Success
990 * @retval -1 -> Error
994 BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_humidity(
995 s32 *v_uncomp_humidity_s32);
996 /**************************************************************/
997 /**\name FUNCTION FOR INTIALIZATION RELATIVE HUMIDITY */
998 /**************************************************************/
1000 * @brief Reads actual humidity from uncompensated humidity
1001 * @note Returns the value in %rH as unsigned 32bit integer
1002 * in Q22.10 format(22 integer 10 fractional bits).
1003 * @note An output value of 42313
1004 * represents 42313 / 1024 = 41.321 %rH
1008 * @param v_uncomp_humidity_s32: value of uncompensated humidity
1010 * @return Return the actual relative humidity output as u32
1013 u32 bme280_compensate_humidity_int32(s32 v_uncomp_humidity_s32);
1015 * @brief Reads actual humidity from uncompensated humidity
1016 * @note Returns the value in %rH as unsigned 16bit integer
1017 * @note An output value of 42313
1018 * represents 42313/512 = 82.643 %rH
1022 * @param v_uncomp_humidity_s32: value of uncompensated humidity
1025 * @return Return the actual relative humidity output as u16
1028 u16 bme280_compensate_humidity_int32_sixteen_bit_output(
1029 s32 v_uncomp_humidity_s32);
1030 /**************************************************************/
1031 /**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED PRESSURE,
1032 TEMPERATURE AND HUMIDITY */
1033 /**************************************************************/
1035 * @brief This API used to read uncompensated
1036 * pressure,temperature and humidity
1041 * @param v_uncomp_pressure_s32: The value of uncompensated pressure.
1042 * @param v_uncomp_temperature_s32: The value of uncompensated temperature
1043 * @param v_uncomp_humidity_s32: The value of uncompensated humidity.
1047 * @return results of bus communication function
1048 * @retval 0 -> Success
1049 * @retval -1 -> Error
1053 BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure_temperature_humidity(
1054 s32 *v_uncomp_pressure_s32,
1055 s32 *v_uncomp_temperature_s32, s32 *v_uncomp_humidity_s32);
1056 /**************************************************************/
1057 /**\name FUNCTION FOR TRUE UNCOMPENSATED PRESSURE,
1058 TEMPERATURE AND HUMIDITY */
1059 /**************************************************************/
1061 * @brief This API used to read true pressure, temperature and humidity
1066 * @param v_pressure_u32 : The value of compensated pressure.
1067 * @param v_temperature_s32 : The value of compensated temperature.
1068 * @param v_humidity_u32 : The value of compensated humidity.
1071 * @return results of bus communication function
1072 * @retval 0 -> Success
1073 * @retval -1 -> Error
1077 BME280_RETURN_FUNCTION_TYPE bme280_read_pressure_temperature_humidity(
1078 u32 *v_pressure_u32, s32 *v_temperature_s32, u32 *v_humidity_u32);
1079 /**************************************************************/
1080 /**\name FUNCTION FOR CALIBRATION */
1081 /**************************************************************/
1083 * @brief This API is used to
1084 * calibration parameters used for calculation in the registers
1086 * parameter | Register address | bit
1087 *------------|------------------|----------------
1088 * dig_T1 | 0x88 and 0x89 | from 0 : 7 to 8: 15
1089 * dig_T2 | 0x8A and 0x8B | from 0 : 7 to 8: 15
1090 * dig_T3 | 0x8C and 0x8D | from 0 : 7 to 8: 15
1091 * dig_P1 | 0x8E and 0x8F | from 0 : 7 to 8: 15
1092 * dig_P2 | 0x90 and 0x91 | from 0 : 7 to 8: 15
1093 * dig_P3 | 0x92 and 0x93 | from 0 : 7 to 8: 15
1094 * dig_P4 | 0x94 and 0x95 | from 0 : 7 to 8: 15
1095 * dig_P5 | 0x96 and 0x97 | from 0 : 7 to 8: 15
1096 * dig_P6 | 0x98 and 0x99 | from 0 : 7 to 8: 15
1097 * dig_P7 | 0x9A and 0x9B | from 0 : 7 to 8: 15
1098 * dig_P8 | 0x9C and 0x9D | from 0 : 7 to 8: 15
1099 * dig_P9 | 0x9E and 0x9F | from 0 : 7 to 8: 15
1100 * dig_H1 | 0xA1 | from 0 to 7
1101 * dig_H2 | 0xE1 and 0xE2 | from 0 : 7 to 8: 15
1102 * dig_H3 | 0xE3 | from 0 to 7
1104 * @return results of bus communication function
1105 * @retval 0 -> Success
1106 * @retval -1 -> Error
1110 BME280_RETURN_FUNCTION_TYPE bme280_get_calib_param(void);
1111 /**************************************************************/
1112 /**\name FUNCTION FOR TEMPERATURE OVER SAMPLING */
1113 /**************************************************************/
1115 * @brief This API is used to get
1116 * the temperature oversampling setting in the register 0xF4
1119 * value | Temperature oversampling
1120 * ---------------------|---------------------------------
1122 * 0x01 | BME280_OVERSAMP_1X
1123 * 0x02 | BME280_OVERSAMP_2X
1124 * 0x03 | BME280_OVERSAMP_4X
1125 * 0x04 | BME280_OVERSAMP_8X
1126 * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X
1129 * @param v_value_u8 : The value of temperature over sampling
1133 * @return results of bus communication function
1134 * @retval 0 -> Success
1135 * @retval -1 -> Error
1139 BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_temperature(
1142 * @brief This API is used to set
1143 * the temperature oversampling setting in the register 0xF4
1146 * value | Temperature oversampling
1147 * ---------------------|---------------------------------
1149 * 0x01 | BME280_OVERSAMP_1X
1150 * 0x02 | BME280_OVERSAMP_2X
1151 * 0x03 | BME280_OVERSAMP_4X
1152 * 0x04 | BME280_OVERSAMP_8X
1153 * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X
1156 * @param v_value_u8 : The value of temperature over sampling
1160 * @return results of bus communication function
1161 * @retval 0 -> Success
1162 * @retval -1 -> Error
1166 BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_temperature(
1168 /**************************************************************/
1169 /**\name FUNCTION FOR PRESSURE OVER SAMPLING */
1170 /**************************************************************/
1172 * @brief This API is used to get
1173 * the pressure oversampling setting in the register 0xF4
1176 * value | Pressure oversampling
1177 * --------------------|--------------------------
1179 * 0x01 | BME280_OVERSAMP_1X
1180 * 0x02 | BME280_OVERSAMP_2X
1181 * 0x03 | BME280_OVERSAMP_4X
1182 * 0x04 | BME280_OVERSAMP_8X
1183 * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X
1186 * @param v_value_u8 : The value of pressure oversampling
1190 * @return results of bus communication function
1191 * @retval 0 -> Success
1192 * @retval -1 -> Error
1196 BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_pressure(
1199 * @brief This API is used to set
1200 * the pressure oversampling setting in the register 0xF4
1203 * value | Pressure oversampling
1204 * --------------------|--------------------------
1206 * 0x01 | BME280_OVERSAMP_1X
1207 * 0x02 | BME280_OVERSAMP_2X
1208 * 0x03 | BME280_OVERSAMP_4X
1209 * 0x04 | BME280_OVERSAMP_8X
1210 * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X
1213 * @param v_value_u8 : The value of pressure oversampling
1217 * @return results of bus communication function
1218 * @retval 0 -> Success
1219 * @retval -1 -> Error
1223 BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_pressure(
1225 /**************************************************************/
1226 /**\name FUNCTION FOR HUMIDITY OVER SAMPLING */
1227 /**************************************************************/
1229 * @brief This API is used to get
1230 * the humidity oversampling setting in the register 0xF2
1233 * value | Humidity oversampling
1234 * ---------------------|-------------------------
1236 * 0x01 | BME280_OVERSAMP_1X
1237 * 0x02 | BME280_OVERSAMP_2X
1238 * 0x03 | BME280_OVERSAMP_4X
1239 * 0x04 | BME280_OVERSAMP_8X
1240 * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X
1243 * @param v_value_u8 : The value of humidity over sampling
1247 * @return results of bus communication function
1248 * @retval 0 -> Success
1249 * @retval -1 -> Error
1253 BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_humidity(u8 *v_value_u8);
1255 * @brief This API is used to set
1256 * the humidity oversampling setting in the register 0xF2
1259 * value | Humidity oversampling
1260 * ---------------------|-------------------------
1262 * 0x01 | BME280_OVERSAMP_1X
1263 * 0x02 | BME280_OVERSAMP_2X
1264 * 0x03 | BME280_OVERSAMP_4X
1265 * 0x04 | BME280_OVERSAMP_8X
1266 * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X
1269 * @param v_value_u8 : The value of humidity over sampling
1273 * @note The "BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY"
1274 * register sets the humidity
1275 * data acquisition options of the device.
1276 * @note changes to this registers only become
1277 * effective after a write operation to
1278 * "BME280_CTRL_MEAS_REG" register.
1279 * @note In the code automated reading and writing of
1280 * "BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY"
1281 * @note register first set the
1282 * "BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY"
1283 * and then read and write
1284 * the "BME280_CTRL_MEAS_REG" register in the function.
1287 * @return results of bus communication function
1288 * @retval 0 -> Success
1289 * @retval -1 -> Error
1293 BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_humidity(
1295 /**************************************************************/
1296 /**\name FUNCTION FOR POWER MODE*/
1297 /**************************************************************/
1299 * @brief This API used to get the
1300 * Operational Mode from the sensor in the register 0xF4 bit 0 and 1
1304 * @param v_power_mode_u8 : The value of power mode
1306 * -----------------|------------------
1307 * 0x00 | BME280_SLEEP_MODE
1308 * 0x01 and 0x02 | BME280_FORCED_MODE
1309 * 0x03 | BME280_NORMAL_MODE
1311 * @return results of bus communication function
1312 * @retval 0 -> Success
1313 * @retval -1 -> Error
1317 BME280_RETURN_FUNCTION_TYPE bme280_get_power_mode(u8 *v_power_mode_u8);
1319 * @brief This API used to set the
1320 * Operational Mode from the sensor in the register 0xF4 bit 0 and 1
1324 * @param v_power_mode_u8 : The value of power mode
1326 * -----------------|------------------
1327 * 0x00 | BME280_SLEEP_MODE
1328 * 0x01 and 0x02 | BME280_FORCED_MODE
1329 * 0x03 | BME280_NORMAL_MODE
1331 * @return results of bus communication function
1332 * @retval 0 -> Success
1333 * @retval -1 -> Error
1337 BME280_RETURN_FUNCTION_TYPE bme280_set_power_mode(u8 v_power_mode_u8);
1338 /**************************************************************/
1339 /**\name FUNCTION FOR SOFT RESET*/
1340 /**************************************************************/
1342 * @brief Used to reset the sensor
1343 * The value 0xB6 is written to the 0xE0
1344 * register the device is reset using the
1345 * complete power-on-reset procedure.
1346 * @note Soft reset can be easily set using bme280_set_softreset().
1347 * @note Usage Hint : bme280_set_softreset()
1350 * @return results of bus communication function
1351 * @retval 0 -> Success
1352 * @retval -1 -> Error
1356 BME280_RETURN_FUNCTION_TYPE bme280_set_soft_rst(void);
1357 /**************************************************************/
1358 /**\name FUNCTION FOR SPI ENABLE*/
1359 /**************************************************************/
1361 * @brief This API used to get the sensor
1362 * SPI mode(communication type) in the register 0xF5 bit 0
1366 * @param v_enable_disable_u8 : The value of SPI enable
1367 * value | Description
1368 * --------|--------------
1374 * @return results of bus communication function
1375 * @retval 0 -> Success
1376 * @retval -1 -> Error
1380 BME280_RETURN_FUNCTION_TYPE bme280_get_spi3(u8 *v_enable_disable_u8);
1382 * @brief This API used to set the sensor
1383 * SPI mode(communication type) in the register 0xF5 bit 0
1387 * @param v_enable_disable_u8 : The value of SPI enable
1388 * value | Description
1389 * --------|--------------
1395 * @return results of bus communication function
1396 * @retval 0 -> Success
1397 * @retval -1 -> Error
1401 BME280_RETURN_FUNCTION_TYPE bme280_set_spi3(u8 v_enable_disable_u8);
1402 /**************************************************************/
1403 /**\name FUNCTION FOR IIR FILTER*/
1404 /**************************************************************/
1406 * @brief This API is used to reads filter setting
1407 * in the register 0xF5 bit 3 and 4
1411 * @param v_value_u8 : The value of IIR filter coefficient
1413 * value | Filter coefficient
1414 * -------------|-------------------------
1415 * 0x00 | BME280_FILTER_COEFF_OFF
1416 * 0x01 | BME280_FILTER_COEFF_2
1417 * 0x02 | BME280_FILTER_COEFF_4
1418 * 0x03 | BME280_FILTER_COEFF_8
1419 * 0x04 | BME280_FILTER_COEFF_16
1421 * @return results of bus communication function
1422 * @retval 0 -> Success
1423 * @retval -1 -> Error
1427 BME280_RETURN_FUNCTION_TYPE bme280_get_filter(u8 *v_value_u8);
1429 * @brief This API is used to write filter setting
1430 * in the register 0xF5 bit 3 and 4
1434 * @param v_value_u8 : The value of IIR filter coefficient
1436 * value | Filter coefficient
1437 * -------------|-------------------------
1438 * 0x00 | BME280_FILTER_COEFF_OFF
1439 * 0x01 | BME280_FILTER_COEFF_2
1440 * 0x02 | BME280_FILTER_COEFF_4
1441 * 0x03 | BME280_FILTER_COEFF_8
1442 * 0x04 | BME280_FILTER_COEFF_16
1444 * @return results of bus communication function
1445 * @retval 0 -> Success
1446 * @retval -1 -> Error
1450 BME280_RETURN_FUNCTION_TYPE bme280_set_filter(u8 v_value_u8);
1451 /**************************************************************/
1452 /**\name FUNCTION FOR STANDBY DURATION*/
1453 /**************************************************************/
1455 * @brief This API used to Read the
1456 * standby duration time from the sensor in the register 0xF5 bit 5 to 7
1458 * @param v_standby_durn_u8 : The value of standby duration time value.
1459 * value | standby duration
1460 * -------------|-----------------------
1461 * 0x00 | BME280_STANDBY_TIME_1_MS
1462 * 0x01 | BME280_STANDBY_TIME_63_MS
1463 * 0x02 | BME280_STANDBY_TIME_125_MS
1464 * 0x03 | BME280_STANDBY_TIME_250_MS
1465 * 0x04 | BME280_STANDBY_TIME_500_MS
1466 * 0x05 | BME280_STANDBY_TIME_1000_MS
1467 * 0x06 | BME280_STANDBY_TIME_2000_MS
1468 * 0x07 | BME280_STANDBY_TIME_4000_MS
1471 * @return results of bus communication function
1472 * @retval 0 -> Success
1473 * @retval -1 -> Error
1477 BME280_RETURN_FUNCTION_TYPE bme280_get_standby_durn(u8 *v_standby_durn_u8);
1479 * @brief This API used to write the
1480 * standby duration time from the sensor in the register 0xF5 bit 5 to 7
1482 * @param v_standby_durn_u8 : The value of standby duration time value.
1483 * value | standby duration
1484 * -------------|-----------------------
1485 * 0x00 | BME280_STANDBY_TIME_1_MS
1486 * 0x01 | BME280_STANDBY_TIME_63_MS
1487 * 0x02 | BME280_STANDBY_TIME_125_MS
1488 * 0x03 | BME280_STANDBY_TIME_250_MS
1489 * 0x04 | BME280_STANDBY_TIME_500_MS
1490 * 0x05 | BME280_STANDBY_TIME_1000_MS
1491 * 0x06 | BME280_STANDBY_TIME_2000_MS
1492 * 0x07 | BME280_STANDBY_TIME_4000_MS
1494 * @note Normal mode comprises an automated perpetual
1495 * cycling between an (active)
1496 * Measurement period and an (inactive) standby period.
1497 * @note The standby time is determined by
1498 * the contents of the register t_sb.
1499 * Standby time can be set using BME280_STANDBY_TIME_125_MS.
1501 * @note Usage Hint : bme280_set_standby_durn(BME280_STANDBY_TIME_125_MS)
1505 * @return results of bus communication function
1506 * @retval 0 -> Success
1507 * @retval -1 -> Error
1511 BME280_RETURN_FUNCTION_TYPE bme280_set_standby_durn(u8 v_standby_durn_u8);
1512 /**************************************************************/
1513 /**\name FUNCTION FOR WORK MODE*/
1514 /**************************************************************/
1516 * @brief Writes the working mode to the sensor
1521 * @param v_work_mode_u8 : Mode to be set
1522 * value | Working mode
1523 * ----------|--------------------
1524 * 0 | BME280_ULTRALOWPOWER_MODE
1525 * 1 | BME280_LOWPOWER_MODE
1526 * 2 | BME280_STANDARDRESOLUTION_MODE
1527 * 3 | BME280_HIGHRESOLUTION_MODE
1528 * 4 | BME280_ULTRAHIGHRESOLUTION_MODE
1530 * @return results of bus communication function
1531 * @retval 0 -> Success
1532 * @retval -1 -> Error
1536 /*BME280_RETURN_FUNCTION_TYPE bme280_set_work_mode(u8 v_work_mode_u8);*/
1537 /**************************************************************/
1538 /**\name FUNCTION FOR FORCE MODE DATA READ*/
1539 /**************************************************************/
1541 * @brief This API used to read uncompensated
1542 * temperature,pressure and humidity in forced mode
1545 * @param v_uncom_pressure_s32: The value of uncompensated pressure
1546 * @param v_uncom_temperature_s32: The value of uncompensated temperature
1547 * @param v_uncom_humidity_s32: The value of uncompensated humidity
1550 * @return results of bus communication function
1551 * @retval 0 -> Success
1552 * @retval -1 -> Error
1556 BME280_RETURN_FUNCTION_TYPE
1557 bme280_get_forced_uncomp_pressure_temperature_humidity(
1558 s32 *v_uncom_pressure_s32,
1559 s32 *v_uncom_temperature_s32, s32 *v_uncom_humidity_s32);
1560 /**************************************************************/
1561 /**\name FUNCTION FOR COMMON READ AND WRITE */
1562 /**************************************************************/
1565 * This API write the data to
1566 * the given register
1569 * @param v_addr_u8 -> Address of the register
1570 * @param v_data_u8 -> The data from the register
1571 * @param v_len_u8 -> no of bytes to read
1574 * @return results of bus communication function
1575 * @retval 0 -> Success
1576 * @retval -1 -> Error
1580 BME280_RETURN_FUNCTION_TYPE bme280_write_register(u8 v_addr_u8,
1581 u8 *v_data_u8, u8 v_len_u8);
1584 * This API reads the data from
1585 * the given register
1588 * @param v_addr_u8 -> Address of the register
1589 * @param v_data_u8 -> The data from the register
1590 * @param v_len_u8 -> no of bytes to read
1593 * @return results of bus communication function
1594 * @retval 0 -> Success
1595 * @retval -1 -> Error
1599 BME280_RETURN_FUNCTION_TYPE bme280_read_register(u8 v_addr_u8,
1600 u8 *v_data_u8, u8 v_len_u8);
1601 /**************************************************************/
1602 /**\name FUNCTION FOR FLOAT OUTPUT TEMPERATURE*/
1603 /**************************************************************/
1604 #ifdef BME280_ENABLE_FLOAT
1606 * @brief Reads actual temperature from uncompensated temperature
1607 * @note returns the value in Degree centigrade
1608 * @note Output value of "51.23" equals 51.23 DegC.
1612 * @param v_uncom_temperature_s32 : value of uncompensated temperature
1616 * @return Return the actual temperature in floating point
1619 double bme280_compensate_temperature_double(
1620 s32 v_uncom_temperature_s32);
1621 /**************************************************************/
1622 /**\name FUNCTION FOR FLOAT OUTPUT PRESSURE*/
1623 /**************************************************************/
1625 * @brief Reads actual pressure from uncompensated pressure
1626 * @note Returns pressure in Pa as double.
1627 * @note Output value of "96386.2"
1628 * equals 96386.2 Pa = 963.862 hPa.
1631 * @param v_uncom_pressure_s32 : value of uncompensated pressure
1634 * @return Return the actual pressure in floating point
1637 double bme280_compensate_pressure_double(s32 v_uncom_pressure_s32);
1638 /**************************************************************/
1639 /**\name FUNCTION FOR FLOAT OUTPUT HUMIDITY*/
1640 /**************************************************************/
1642 * @brief Reads actual humidity from uncompensated humidity
1643 * @note returns the value in relative humidity (%rH)
1644 * @note Output value of "42.12" equals 42.12 %rH
1646 * @param v_uncom_humidity_s32 : value of uncompensated humidity
1650 * @return Return the actual humidity in floating point
1653 double bme280_compensate_humidity_double(s32 v_uncom_humidity_s32);
1655 /**************************************************************/
1656 /**\name FUNCTION FOR 64BIT OUTPUT PRESSURE*/
1657 /**************************************************************/
1658 #if defined(BME280_ENABLE_INT64) && defined(BME280_64BITSUPPORT_PRESENT)
1660 * @brief Reads actual pressure from uncompensated pressure
1661 * @note Returns the value in Pa as unsigned 32 bit
1662 * integer in Q24.8 format (24 integer bits and
1663 * 8 fractional bits).
1664 * @note Output value of "24674867"
1665 * represents 24674867 / 256 = 96386.2 Pa = 963.862 hPa
1669 * @param v_uncom_pressure_s32 : value of uncompensated temperature
1672 * @return Return the actual pressure in u32
1675 u32 bme280_compensate_pressure_int64(s32 v_uncom_pressure_s32);
1676 /**************************************************************/
1677 /**\name FUNCTION FOR 24BIT OUTPUT PRESSURE*/
1678 /**************************************************************/
1680 * @brief Reads actual pressure from uncompensated pressure
1681 * @note Returns the value in Pa.
1682 * @note Output value of "12337434"
1683 * @note represents 12337434 / 128 = 96386.2 Pa = 963.862 hPa
1687 * @param v_uncom_pressure_s32 : value of uncompensated pressure
1690 * @return the actual pressure in u32
1693 u32 bme280_compensate_pressure_int64_twentyfour_bit_output(
1694 s32 v_uncom_pressure_s32);
1696 /**************************************************************/
1697 /**\name FUNCTION FOR WAIT PERIOD*/
1698 /**************************************************************/
1700 * @brief Computing waiting time for sensor data read
1705 * @param v_delaytime_u8 : The value of delay time for force mode
1708 * @retval 0 -> Success
1712 BME280_RETURN_FUNCTION_TYPE bme280_compute_wait_time(u8