3 ****************************************************************************
4 * Copyright (C) 2013 - 2014 Bosch Sensortec GmbH
10 * Revision : 2.0.3(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(BMPE80_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 */
204 #define BME280_64BITSUPPORT_PRESENT
206 /* If your machine support 64 bit
207 define the MACHINE_64_BIT*/
208 #elif defined MACHINE_64_BIT
209 /*signed integer types*/
210 typedef signed char s8;/**< used for signed 8bit */
211 typedef signed short int s16;/**< used for signed 16bit */
212 typedef signed int s32;/**< used for signed 32bit */
213 typedef signed long int s64;/**< used for signed 64bit */
215 /*unsigned integer types*/
216 typedef unsigned char u8;/**< used for unsigned 8bit */
217 typedef unsigned short int u16;/**< used for unsigned 16bit */
218 typedef unsigned int u32;/**< used for unsigned 32bit */
219 typedef unsigned long int u64;/**< used for unsigned 64bit */
220 #define BME280_64BITSUPPORT_PRESENT
223 #warning The data types defined above which not supported \
224 define the data types manually
228 /*** This else will execute for the compilers
229 * which are not supported the C standards
230 * Like C89/C99/C11***/
233 * @brief By default it is defined as 32 bit machine configuration
234 * define your data types based on your
235 * machine/compiler/controller configuration
237 #define MACHINE_32_BIT
239 /* If your machine support 16 bit
240 define the MACHINE_16_BIT*/
241 #ifdef MACHINE_16_BIT
243 /*signed integer types*/
244 typedef signed char s8;/**< used for signed 8bit */
245 typedef signed short int s16;/**< used for signed 16bit */
246 typedef signed long int s32;/**< used for signed 32bit */
248 #if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL
249 typedef long int s64;/**< used for signed 64bit */
250 typedef unsigned long int u64;/**< used for unsigned 64bit */
251 #define BME280_64BITSUPPORT_PRESENT
252 #elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL)
253 typedef long long int s64;/**< used for signed 64bit */
254 typedef unsigned long long int u64;/**< used for unsigned 64bit */
255 #define BME280_64BITSUPPORT_PRESENT
257 #warning Either the correct data type for signed 64 bit integer \
258 could not be found, or 64 bit integers are not supported in your environment.
259 #warning The API will only offer 32 bit pressure calculation.This will \
260 slightly impede accuracy(noise of ~1 pascal RMS will be added to output).
261 #warning If 64 bit integers are supported on your platform, \
262 please set s64 manually and "#define(BME280_64BITSUPPORT_PRESENT)" manually.
265 /*unsigned integer types*/
266 typedef unsigned char u8;/**< used for unsigned 8bit */
267 typedef unsigned short int u16;/**< used for unsigned 16bit */
268 typedef unsigned long int u32;/**< used for unsigned 32bit */
270 /*! @brief If your machine support 32 bit
271 define the MACHINE_32_BIT*/
272 #elif defined MACHINE_32_BIT
273 /*signed integer types*/
274 typedef signed char s8;/**< used for signed 8bit */
275 typedef signed short int s16;/**< used for signed 16bit */
276 typedef signed int s32;/**< used for signed 32bit */
277 typedef signed long long int s64;/**< used for signed 64bit */
279 /*unsigned integer types*/
280 typedef unsigned char u8;/**< used for unsigned 8bit */
281 typedef unsigned short int u16;/**< used for unsigned 16bit */
282 typedef unsigned int u32;/**< used for unsigned 32bit */
283 typedef unsigned long long int u64;/**< used for unsigned 64bit */
284 #define BME280_64BITSUPPORT_PRESENT
286 /* If your machine support 64 bit
287 define the MACHINE_64_BIT*/
288 #elif defined MACHINE_64_BIT
289 /*signed integer types*/
290 typedef signed char s8;/**< used for signed 8bit */
291 typedef signed short int s16;/**< used for signed 16bit */
292 typedef signed int s32;/**< used for signed 32bit */
293 typedef signed long int s64;/**< used for signed 64bit */
295 /*unsigned integer types*/
296 typedef unsigned char u8;/**< used for unsigned 8bit */
297 typedef unsigned short int u16;/**< used for unsigned 16bit */
298 typedef unsigned int u32;/**< used for unsigned 32bit */
299 typedef unsigned long int u64;/**< used for unsigned 64bit */
300 #define BME280_64BITSUPPORT_PRESENT
303 #warning The data types defined above which not supported \
304 define the data types manually
308 /********************************************/
309 /**\name ENABLE FLATING OUTPUT */
310 /**************************************/
312 * @brief If the user wants to support floating point calculations, please set
313 the following define. If floating point
314 calculation is not wanted or allowed
315 (e.g. in Linux kernel), please do not set the define. */
316 #define BME280_ENABLE_FLOAT
318 * @brief If the user wants to support 64 bit integer calculation
319 (needed for optimal pressure accuracy) please set
320 the following define. If int64 calculation is not wanted
321 (e.g. because it would include
322 large libraries), please do not set the define. */
323 #define BME280_ENABLE_INT64
324 /***************************************************************/
325 /**\name BUS READ AND WRITE FUNCTION POINTERS */
326 /***************************************************************/
328 @brief Define the calling convention of YOUR bus communication routine.
329 @note This includes types of parameters. This example shows the
330 configuration for an SPI bus link.
332 If your communication function looks like this:
334 write_my_bus_xy(u8 device_addr, u8 register_addr,
335 u8 * data, u8 length);
337 The BME280_WR_FUNC_PTR would equal:
339 BME280_WR_FUNC_PTR s8 (* bus_write)(u8,
342 Parameters can be mixed as needed refer to the
343 refer BME280_BUS_WRITE_FUNC macro.
347 /** defines the return parameter type of the BME280_WR_FUNCTION */
348 #define BME280_BUS_WR_RETURN_TYPE s8
350 /* links the order of parameters defined in
351 BME280_BUS_WR_PARAM_TYPE to function calls used inside the API*/
352 #define BME280_BUS_WR_PARAM_TYPES u8, u8,\
355 /* links the order of parameters defined in
356 BME280_BUS_WR_PARAM_TYPE to function calls used inside the API*/
357 #define BME280_BUS_WR_PARAM_ORDER(device_addr, register_addr,\
358 register_data, wr_len)
360 /* never change this line */
361 #define BME280_BUS_WRITE_FUNC(device_addr, register_addr,\
362 register_data, wr_len) bus_write(device_addr, register_addr,\
363 register_data, wr_len)
365 @brief link macro between API function calls and bus read function
366 @note The bus write function can change since this is a
367 system dependant issue.
369 If the bus_read parameter calling order is like: reg_addr,
370 reg_data, wr_len it would be as it is here.
372 If the parameters are differently ordered or your communication
373 function like I2C need to know the device address,
374 you can change this macro accordingly.
377 BME280_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, wr_len)\
378 bus_read(dev_addr, reg_addr, reg_data, wr_len)
380 This macro lets all API functions call YOUR communication routine in a
381 way that equals your definition in the
382 refer BME280_WR_FUNC_PTR definition.
384 @note: this macro also includes the "MSB='1'
385 for reading BME280 addresses.
388 /*defines the return parameter type of the BME280_RD_FUNCTION
390 #define BME280_BUS_RD_RETURN_TYPE s8
392 /**\brief defines the calling parameter types of the BME280_RD_FUNCTION
394 #define BME280_BUS_RD_PARAM_TYPES (u8, u8,\
397 /* links the order of parameters defined in \
398 BME280_BUS_RD_PARAM_TYPE to function calls used inside the API
400 #define BME280_BUS_RD_PARAM_ORDER (device_addr, register_addr,\
403 /* never change this line */
404 #define BME280_BUS_READ_FUNC(device_addr, register_addr,\
405 register_data, rd_len)bus_read(device_addr, register_addr,\
406 register_data, rd_len)
407 /****************************************/
409 /****************************************/
410 /* defines the return parameter type of the BME280_DELAY_FUNCTION
412 #define BME280_DELAY_RETURN_TYPE void
414 /* defines the calling parameter types of the BME280_DELAY_FUNCTION
416 #define BME280_DELAY_PARAM_TYPES u16
417 /***************************************************************/
418 /**\name GET AND SET BITSLICE FUNCTIONS */
419 /***************************************************************/
420 /* never change this line */
421 #define BME280_DELAY_FUNC(delay_in_msec)\
422 delay_func(delay_in_msec)
424 #define BME280_GET_BITSLICE(regvar, bitname)\
425 ((regvar & bitname##__MSK) >> bitname##__POS)
427 #define BME280_SET_BITSLICE(regvar, bitname, val)\
428 ((regvar & ~bitname##__MSK) | ((val<<bitname##__POS)&bitname##__MSK))
430 /***************************************************************/
431 /**\name COMMON USED CONSTANTS */
432 /***************************************************************/
434 #define BME280_NULL 0
435 #define BME280_RETURN_FUNCTION_TYPE s8
436 /* right shift definitions*/
437 #define SHIFT_RIGHT_1_POSITION 1
438 #define SHIFT_RIGHT_2_POSITION 2
439 #define SHIFT_RIGHT_3_POSITION 3
440 #define SHIFT_RIGHT_4_POSITION 4
441 #define SHIFT_RIGHT_7_POSITION 7
442 #define SHIFT_RIGHT_8_POSITION 8
443 #define SHIFT_RIGHT_10_POSITION 10
444 #define SHIFT_RIGHT_11_POSITION 11
445 #define SHIFT_RIGHT_12_POSITION 12
446 #define SHIFT_RIGHT_13_POSITION 13
447 #define SHIFT_RIGHT_14_POSITION 14
448 #define SHIFT_RIGHT_15_POSITION 15
449 #define SHIFT_RIGHT_18_POSITION 18
450 #define SHIFT_RIGHT_19_POSITION 19
451 #define SHIFT_RIGHT_25_POSITION 25
452 #define SHIFT_RIGHT_33_POSITION 33
453 /* left shift definitions*/
454 #define SHIFT_LEFT_1_POSITION 1
455 #define SHIFT_LEFT_2_POSITION 2
456 #define SHIFT_LEFT_4_POSITION 4
457 #define SHIFT_LEFT_5_POSITION 5
458 #define SHIFT_LEFT_8_POSITION 8
459 #define SHIFT_LEFT_12_POSITION 12
460 #define SHIFT_LEFT_13_POSITION 13
461 #define SHIFT_LEFT_14_POSITION 14
462 #define SHIFT_LEFT_16_POSITION 16
463 #define SHIFT_LEFT_17_POSITION 17
464 #define SHIFT_LEFT_20_POSITION 20
465 #define SHIFT_LEFT_31_POSITION 31
466 #define SHIFT_LEFT_35_POSITION 35
467 #define SHIFT_LEFT_47_POSITION 47
468 /* numeric definitions*/
469 #define BME280_ONE_U8X 1
470 #define BME280_TWO_U8X 2
471 #define BME280_THREE_U8X 3
472 #define BME280_FOUR_U8X 4
473 #define BME280_FIVE_U8X 5
474 #define BME280_SEVEN_U8X 7
475 #define BME280_ZERO_U8X 0
476 #define BME280_EIGHT_U8X 8
477 #define BME280_FIVETEEN_U8X 15
478 #define BME280_SIXTEEN_U8X 16
479 #define BME280_TWENTY_FIVE_U8X 25
480 #define BME280_TWENTY_SIX_U8X 26
481 #define BME280_ONE_TWENTY_EIGHT_U8X 128
483 /***************************************************************/
484 /**\name PRESSURE AND TEMPERATURE DEFINITIONS */
485 /***************************************************************/
486 #define BME280_TEMP_1_2_2_8_8_0_DATA 122880
487 #define BME280_PRESSURE_6_4_0_0_0_DATA 64000
488 #define BME280_PRESSURE_3_1_2_5_DATA 3125
489 #define BME280_PRESSURE_3_2_7_6_8_DATA 32768
490 #define BME280_PRESSURE_1_0_4_8_5_7_6_DATA 1048576
491 #define BME280_HEX_PRESSURE_8_0_0_0_0_0_0_0_DATA 0x80000000
492 /***************************************************************/
493 /**\name HUMIDITY DEFINITIONS */
494 /***************************************************************/
495 #define BME280_HUMIDITY_7_6_8_0_0_DATA 76800
496 #define BME280_HUMIDITY_1_6_3_8_4_DATA 16384
497 #define BME280_HUMIDITY_3_2_7_6_8_DATA 32768
498 #define BME280_HUMIDITY_2_0_9_7_1_5_2_DATA 2097152
499 #define BME280_HUMIDITY_8_1_9_2_DATA 8192
500 #define BME280_HUMIDITY_4_1_9_4_3_0_4_0_0_DATA 419430400
501 /***************************************************************/
502 /**\name CALIBRATION MASK DEFINITION */
503 /***************************************************************/
504 #define BME280_HEX_CALIB_0_F_DATA 0x0F
506 /****************************************************/
507 /**\name TRUE TEMPERATURE CALUCULATION PARAMETERS */
508 /***************************************************/
509 #define BME280_DEC_TRUE_TEMP_FIVE_DATA 5
510 #define BME280_DEC_TRUE_TEMP_ONE_TWO_EIGHT_DATA 128
511 /****************************************************/
512 /**\name TRUE PRESSURE CALUCULATION PARAMETERS */
513 /***************************************************/
514 #define BME280_DEC_TRUE_PRESSURE_6_4_0_0_0_DATA 64000
515 #define BME280_DEC_TRUE_PRESSURE_TWO_DATA 2
516 #define BME280_DEC_TRUE_PRESSURE_3_2_7_6_8_DATA 32768
517 #define BME280_DEC_TRUE_PRESSURE_1_0_4_8_5_7_6_DATA 1048576
518 #define BME280_DEC_TRUE_PRESSURE_3_1_2_5_DATA 3125
519 #define BME280_HEX_TRUE_PRESSURE_8_0_0_0_0_0_0_0_DATA 0x80000000
521 /****************************************************/
522 /**\name TRUE TEMPERATURE CALUCULATION FLOAT RETURN */
523 /***************************************************/
524 #define BME280_FLOAT_TRUE_TEMP_1_6_3_8_4_DATA 16384.0
525 #define BME280_FLOAT_TRUE_TEMP_1_0_2_4_DATA 1024.0
526 #define BME280_FLOAT_TRUE_TEMP_1_3_1_0_7_2_DATA 131072.0
527 #define BME280_FLOAT_TRUE_TEMP_8_1_9_2_DATA 8192.0
528 #define BME280_FLOAT_TRUE_TEMP_5_1_2_0_DATA 5120.0
530 /****************************************************/
531 /**\name TRUE PRESSURE CALUCULATION FLOAT RETURN */
532 /***************************************************/
533 #define BME280_FLAOT_TRUE_PRESSURE_1_DATA 1.0
534 #define BME280_FLAOT_TRUE_PRESSURE_0_DATA 0.0
535 #define BME280_FLAOT_TRUE_PRESSURE_2_DATA 2.0
536 #define BME280_FLAOT_TRUE_PRESSURE_4_DATA 4.0
537 #define BME280_FLAOT_TRUE_PRESSURE_1_6_DATA 16.0
538 #define BME280_FLAOT_TRUE_PRESSURE_6_4_0_0_0_DATA 64000.0
539 #define BME280_FLAOT_TRUE_PRESSURE_3_2_7_6_8_DATA 32768.0
540 #define BME280_FLAOT_TRUE_PRESSURE_6_5_5_3_6_DATA 65536.0
541 #define BME280_FLAOT_TRUE_PRESSURE_5_2_4_2_8_8_DATA 524288.0
542 #define BME280_FLAOT_TRUE_PRESSURE_1_0_4_8_5_7_6_DATA 1048576.0
543 #define BME280_FLAOT_TRUE_PRESSURE_4_0_9_6_DATA 4096.0
544 #define BME280_FLAOT_TRUE_PRESSURE_6_2_5_0_DATA 6250.0
545 #define BME280_FLAOT_TRUE_PRESSURE_2_1_4_7_4_8_3_6_4_8_DATA \
548 /****************************************************/
549 /**\name TRUE PRESSURE CALUCULATION 64BIT RETURN */
550 /***************************************************/
551 #define BME280_TRUE_PRESSURE_1_2_8_0_0_0_DATA 128000
552 #define BME280_TRUE_PRESSURE_1_0_4_8_5_7_6_DATA 1048576
553 #define BME280_TRUE_PRESSURE_3_1_2_5_DATA 3125
554 #define BME280_TRUE_PRESSURE_1_DATA 1
555 /****************************************************/
556 /**\name TRUE HUMIDITY CALUCULATION FLOAT RETURN */
557 /***************************************************/
558 #define BME280_TRUE_HUMIDITY_7_6_8_0_0_DATA 76800.0
559 #define BME280_TRUE_HUMIDITY_6_4_DATA 64.0
560 #define BME280_TRUE_HUMIDITY_1_6_3_8_4_DATA 16384.0
561 #define BME280_TRUE_HUMIDITY_6_5_5_3_6_DATA 65536.0
562 #define BME280_TRUE_HUMIDITY_0_DATA 0.0
563 #define BME280_TRUE_HUMIDITY_1_DATA 1.0
564 #define BME280_TRUE_HUMIDITY_1_0_0_DATA 100.0
565 #define BME280_TRUE_HUMIDITY_6_7_1_0_8_8_6_4_DATA 67108864.0
566 #define BME280_TRUE_HUMIDITY_5_2_4_2_8_8_DATA 524288.0
567 #define BME280_TRUE_HUMIDITY_
568 /****************************************************/
569 /**\name ERROR CODE DEFINITIONS */
570 /***************************************************/
571 #define SUCCESS ((u8)0)
572 #define E_BME280_NULL_PTR ((s8)-127)
573 #define E_BME280_COMM_RES ((s8)-1)
574 #define E_BME280_OUT_OF_RANGE ((s8)-2)
575 #define ERROR ((s8)-1)
576 /****************************************************/
577 /**\name I2C ADDRESS DEFINITIONS */
578 /***************************************************/
579 #define BME280_I2C_ADDRESS1 0x76
580 #define BME280_I2C_ADDRESS2 0x77
581 /****************************************************/
582 /**\name POWER MODE DEFINITIONS */
583 /***************************************************/
584 /* Sensor Specific constants */
585 #define BME280_SLEEP_MODE 0x00
586 #define BME280_FORCED_MODE 0x01
587 #define BME280_NORMAL_MODE 0x03
588 #define BME280_SOFT_RESET_CODE 0xB6
589 /****************************************************/
590 /**\name STANDBY DEFINITIONS */
591 /***************************************************/
592 #define BME280_STANDBY_TIME_1_MS 0x00
593 #define BME280_STANDBY_TIME_63_MS 0x01
594 #define BME280_STANDBY_TIME_125_MS 0x02
595 #define BME280_STANDBY_TIME_250_MS 0x03
596 #define BME280_STANDBY_TIME_500_MS 0x04
597 #define BME280_STANDBY_TIME_1000_MS 0x05
598 #define BME280_STANDBY_TIME_10_MS 0x06
599 #define BME280_STANDBY_TIME_20_MS 0x07
600 /****************************************************/
601 /**\name OVER SAMPLING DEFINITIONS */
602 /***************************************************/
603 #define BME280_OVERSAMP_SKIPPED 0x00
604 #define BME280_OVERSAMP_1X 0x01
605 #define BME280_OVERSAMP_2X 0x02
606 #define BME280_OVERSAMP_4X 0x03
607 #define BME280_OVERSAMP_8X 0x04
608 #define BME280_OVERSAMP_16X 0x05
609 /****************************************************/
610 /**\name WORK MODE DEFINITIONS */
611 /***************************************************/
612 /*#define BME280_ULTRALOWPOWER_MODE 0x00
613 #define BME280_LOWPOWER_MODE 0x01
614 #define BME280_STANDARDRESOLUTION_MODE 0x02
615 #define BME280_HIGHRESOLUTION_MODE 0x03
616 #define BME280_ULTRAHIGHRESOLUTION_MODE 0x04
618 #define BME280_ULTRALOWPOWER_OSRS_P BME280_OVERSAMP_1X
619 #define BME280_ULTRALOWPOWER_OSRS_T BME280_OVERSAMP_1X
621 #define BME280_LOWPOWER_OSRS_P BME280_OVERSAMP_2X
622 #define BME280_LOWPOWER_OSRS_T BME280_OVERSAMP_1X
624 #define BME280_STANDARDRESOLUTION_OSRS_P BME280_OVERSAMP_4X
625 #define BME280_STANDARDRESOLUTION_OSRS_T BME280_OVERSAMP_1X
627 #define BME280_HIGHRESOLUTION_OSRS_P BME280_OVERSAMP_8X
628 #define BME280_HIGHRESOLUTION_OSRS_T BME280_OVERSAMP_1X
630 #define BME280_ULTRAHIGHRESOLUTION_OSRS_P BME280_OVERSAMP_16X
631 #define BME280_ULTRAHIGHRESOLUTION_OSRS_T BME280_OVERSAMP_2X */
633 #define BME280_STANDARD_OVERSAMP_HUMIDITY BME280_OVERSAMP_1X
634 /****************************************************/
635 /**\name FILTER DEFINITIONS */
636 /***************************************************/
637 #define BME280_FILTER_COEFF_OFF 0x00
638 #define BME280_FILTER_COEFF_2 0x01
639 #define BME280_FILTER_COEFF_4 0x02
640 #define BME280_FILTER_COEFF_8 0x03
641 #define BME280_FILTER_COEFF_16 0x04
642 /****************************************************/
643 /**\name DELAY DEFINITIONS */
644 /***************************************************/
645 #define T_INIT_MAX 20
646 /* 20/16 = 1.25 ms */
647 #define T_MEASURE_PER_OSRS_MAX 37
648 /* 37/16 = 2.3125 ms*/
650 #define T_SETUP_PRESSURE_MAX 10
651 /* 10/16 = 0.625 ms */
653 #define T_SETUP_HUMIDITY_MAX 10
654 /* 10/16 = 0.625 ms */
655 /****************************************************/
656 /**\name ARRAY SIZE DEFINITIONS */
657 /***************************************************/
658 #define ARRAY_SIZE_TWO 2
659 #define ARRAY_SIZE_THREE 3
660 #define ARRAY_SIZE_SIX 6
661 #define ARRAY_SIZE_FIVE 5
662 #define ARRAY_SIZE_EIGHT 8
663 #define ARRAY_SIZE_TWELVE 12
664 #define ARRAY_SIZE_FOURTEEN 14
665 #define ARRAY_SIZE_TWENTY_SIX 26
670 #define INDEX_THREE 3
674 #define INDEX_SEVEN 7
675 #define INDEX_EIGHT 8
678 #define INDEX_ELEVEN 11
679 #define INDEX_TWELVE 12
680 #define INDEX_THIRTEEN 13
681 #define INDEX_FOURTEEN 14
682 #define INDEX_FIVETEEN 15
683 #define INDEX_SIXTEEN 16
684 #define INDEX_SEVENTEEN 17
685 #define INDEX_EIGHTEEN 18
686 #define INDEX_NINETEEN 19
687 #define INDEX_TWENTY 20
688 #define INDEX_TWENTY_ONE 21
689 #define INDEX_TWENTY_TWO 22
690 #define INDEX_TWENTY_THREE 23
691 #define INDEX_TWENTY_FIVE 25
692 /****************************************************/
693 /**\name ARRAY PARAMETERS */
694 /***************************************************/
703 /****************************************************/
704 /**\name CALIBRATION REGISTER ADDRESS DEFINITIONS */
705 /***************************************************/
706 /*calibration parameters */
707 #define BME280_DIG_T1_LSB_REG 0x88
708 #define BME280_DIG_T1_MSB_REG 0x89
709 #define BME280_DIG_T2_LSB_REG 0x8A
710 #define BME280_DIG_T2_MSB_REG 0x8B
711 #define BME280_DIG_T3_LSB_REG 0x8C
712 #define BME280_DIG_T3_MSB_REG 0x8D
713 #define BME280_DIG_P1_LSB_REG 0x8E
714 #define BME280_DIG_P1_MSB_REG 0x8F
715 #define BME280_DIG_P2_LSB_REG 0x90
716 #define BME280_DIG_P2_MSB_REG 0x91
717 #define BME280_DIG_P3_LSB_REG 0x92
718 #define BME280_DIG_P3_MSB_REG 0x93
719 #define BME280_DIG_P4_LSB_REG 0x94
720 #define BME280_DIG_P4_MSB_REG 0x95
721 #define BME280_DIG_P5_LSB_REG 0x96
722 #define BME280_DIG_P5_MSB_REG 0x97
723 #define BME280_DIG_P6_LSB_REG 0x98
724 #define BME280_DIG_P6_MSB_REG 0x99
725 #define BME280_DIG_P7_LSB_REG 0x9A
726 #define BME280_DIG_P7_MSB_REG 0x9B
727 #define BME280_DIG_P8_LSB_REG 0x9C
728 #define BME280_DIG_P8_MSB_REG 0x9D
729 #define BME280_DIG_P9_LSB_REG 0x9E
730 #define BME280_DIG_P9_MSB_REG 0x9F
732 #define BME280_DIG_H1_REG 0xA1
734 #define BME280_DIG_H2_LSB_REG 0xE1
735 #define BME280_DIG_H2_MSB_REG 0xE2
736 #define BME280_DIG_H3_REG 0xE3
737 #define BME280_DIG_H4_MSB_REG 0xE4
738 #define BME280_DIG_H5_LSB_H4_LSB_REG 0xE5
739 #define BME280_DIG_H5_MSB_REG 0xE6
740 #define BME280_DIG_H6_REG 0xE7
741 /****************************************************/
742 /**\name REGISTER ADDRESS DEFINITIONS */
743 /***************************************************/
744 #define BME280_CHIP_ID_REG 0xD0 /*Chip ID Register */
745 #define BME280_RST_REG 0xE0 /*Softreset Register */
746 #define BME280_STAT_REG 0xF3 /*Status Register */
747 #define BME280_CTRL_MEAS_REG 0xF4 /*Ctrl Measure Register */
748 #define BME280_CTRL_HUMIDITY_REG 0xF2 /*Ctrl Humidity Register*/
749 #define BME280_CONFIG_REG 0xF5 /*Configuration Register */
750 #define BME280_PRESSURE_MSB_REG 0xF7 /*Pressure MSB Register */
751 #define BME280_PRESSURE_LSB_REG 0xF8 /*Pressure LSB Register */
752 #define BME280_PRESSURE_XLSB_REG 0xF9 /*Pressure XLSB Register */
753 #define BME280_TEMPERATURE_MSB_REG 0xFA /*Temperature MSB Reg */
754 #define BME280_TEMPERATURE_LSB_REG 0xFB /*Temperature LSB Reg */
755 #define BME280_TEMPERATURE_XLSB_REG 0xFC /*Temperature XLSB Reg */
756 #define BME280_HUMIDITY_MSB_REG 0xFD /*Humidity MSB Reg */
757 #define BME280_HUMIDITY_LSB_REG 0xFE /*Humidity LSB Reg */
758 /****************************************************/
759 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS */
760 /***************************************************/
761 /* Status Register */
762 #define BME280_STAT_REG_MEASURING__POS 3
763 #define BME280_STAT_REG_MEASURING__MSK 0x08
764 #define BME280_STAT_REG_MEASURING__LEN 1
765 #define BME280_STAT_REG_MEASURING__REG BME280_STAT_REG
767 #define BME280_STAT_REG_IM_UPDATE__POS 0
768 #define BME280_STAT_REG_IM_UPDATE__MSK 0x01
769 #define BME280_STAT_REG_IM_UPDATE__LEN 1
770 #define BME280_STAT_REG_IM_UPDATE__REG BME280_STAT_REG
771 /****************************************************/
772 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
773 FOR TEMPERATURE OVERSAMPLING */
774 /***************************************************/
775 /* Control Measurement Register */
776 #define BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__POS 5
777 #define BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__MSK 0xE0
778 #define BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__LEN 3
779 #define BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__REG \
781 /****************************************************/
782 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
783 FOR PRESSURE OVERSAMPLING */
784 /***************************************************/
785 #define BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__POS 2
786 #define BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__MSK 0x1C
787 #define BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__LEN 3
788 #define BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__REG \
790 /****************************************************/
791 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
793 /***************************************************/
794 #define BME280_CTRL_MEAS_REG_POWER_MODE__POS 0
795 #define BME280_CTRL_MEAS_REG_POWER_MODE__MSK 0x03
796 #define BME280_CTRL_MEAS_REG_POWER_MODE__LEN 2
797 #define BME280_CTRL_MEAS_REG_POWER_MODE__REG \
799 /****************************************************/
800 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
801 FOR HUMIDITY OVERSAMPLING */
802 /***************************************************/
803 #define BME280_CTRL_HUMIDITY_REG_OVERSAM_HUMIDITY__POS 0
804 #define BME280_CTRL_HUMIDITY_REG_OVERSAM_HUMIDITY__MSK 0x07
805 #define BME280_CTRL_HUMIDITY_REG_OVERSAM_HUMIDITY__LEN 3
806 #define BME280_CTRL_HUMIDITY_REG_OVERSAM_HUMIDITY__REG \
807 BME280_CTRL_HUMIDITY_REG
808 /****************************************************/
809 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
811 /***************************************************/
812 /* Configuration Register */
813 #define BME280_CONFIG_REG_TSB__POS 5
814 #define BME280_CONFIG_REG_TSB__MSK 0xE0
815 #define BME280_CONFIG_REG_TSB__LEN 3
816 #define BME280_CONFIG_REG_TSB__REG BME280_CONFIG_REG
817 /****************************************************/
818 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
820 /***************************************************/
821 #define BME280_CONFIG_REG_FILTER__POS 2
822 #define BME280_CONFIG_REG_FILTER__MSK 0x1C
823 #define BME280_CONFIG_REG_FILTER__LEN 3
824 #define BME280_CONFIG_REG_FILTER__REG BME280_CONFIG_REG
825 /****************************************************/
826 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
828 /***************************************************/
829 #define BME280_CONFIG_REG_SPI3_ENABLE__POS 0
830 #define BME280_CONFIG_REG_SPI3_ENABLE__MSK 0x01
831 #define BME280_CONFIG_REG_SPI3_ENABLE__LEN 1
832 #define BME280_CONFIG_REG_SPI3_ENABLE__REG BME280_CONFIG_REG
833 /****************************************************/
834 /**\name BIT MASK, LENGTH AND POSITION DEFINITIONS
835 FOR PRESSURE AND TEMPERATURE DATA */
836 /***************************************************/
838 #define BME280_PRESSURE_XLSB_REG_DATA__POS 4
839 #define BME280_PRESSURE_XLSB_REG_DATA__MSK 0xF0
840 #define BME280_PRESSURE_XLSB_REG_DATA__LEN 4
841 #define BME280_PRESSURE_XLSB_REG_DATA__REG BME280_PRESSURE_XLSB_REG
843 #define BME280_TEMPERATURE_XLSB_REG_DATA__POS 4
844 #define BME280_TEMPERATURE_XLSB_REG_DATA__MSK 0xF0
845 #define BME280_TEMPERATURE_XLSB_REG_DATA__LEN 4
846 #define BME280_TEMPERATURE_XLSB_REG_DATA__REG BME280_TEMPERATURE_XLSB_REG
847 /****************************************************/
848 /**\name BUS READ AND WRITE FUNCTION POINTERS */
849 /***************************************************/
850 #define BME280_WR_FUNC_PTR\
851 s8 (*bus_write)(u8, u8,\
854 #define BME280_RD_FUNC_PTR\
855 s8 (*bus_read)(u8, u8,\
858 #define BME280_MDELAY_DATA_TYPE u16
860 #define BME280_3MS_DELAY 3
861 /**************************************************************/
862 /**\name STRUCTURE DEFINITIONS */
863 /**************************************************************/
865 * @brief This structure holds all device specific calibration parameters
867 struct bme280_calibration_param_t {
868 u16 dig_T1;/**<calibration T1 data*/
869 s16 dig_T2;/**<calibration T2 data*/
870 s16 dig_T3;/**<calibration T3 data*/
871 u16 dig_P1;/**<calibration P1 data*/
872 s16 dig_P2;/**<calibration P2 data*/
873 s16 dig_P3;/**<calibration P3 data*/
874 s16 dig_P4;/**<calibration P4 data*/
875 s16 dig_P5;/**<calibration P5 data*/
876 s16 dig_P6;/**<calibration P6 data*/
877 s16 dig_P7;/**<calibration P7 data*/
878 s16 dig_P8;/**<calibration P8 data*/
879 s16 dig_P9;/**<calibration P9 data*/
881 u8 dig_H1;/**<calibration H1 data*/
882 s16 dig_H2;/**<calibration H2 data*/
883 u8 dig_H3;/**<calibration H3 data*/
884 s16 dig_H4;/**<calibration H4 data*/
885 s16 dig_H5;/**<calibration H5 data*/
886 s8 dig_H6;/**<calibration H6 data*/
888 s32 t_fine;/**<calibration T_FINE data*/
891 * @brief This structure holds BME280 initialization parameters
894 struct bme280_calibration_param_t cal_param;
895 /**< calibration parameters*/
897 u8 chip_id;/**< chip id of the sensor*/
898 u8 dev_addr;/**< device address of the sensor*/
900 u8 oversamp_temperature;/**< temperature over sampling*/
901 u8 oversamp_pressure;/**< pressure over sampling*/
902 u8 oversamp_humidity;/**< humidity over sampling*/
903 u8 ctrl_hum_reg;/**< status of control humidity register*/
904 u8 ctrl_meas_reg;/**< status of control measurement register*/
905 u8 config_reg;/**< status of configuration register*/
906 BME280_WR_FUNC_PTR;/**< bus write function pointer*/
907 BME280_RD_FUNC_PTR;/**< bus read function pointer*/
908 void(*delay_msec)(BME280_MDELAY_DATA_TYPE);/**< delay function pointer*/
910 /**************************************************************/
911 /**\name FUNCTION DECLARATIONS */
912 /**************************************************************/
913 /**************************************************************/
914 /**\name FUNCTION FOR INTIALIZATION */
915 /**************************************************************/
917 * @brief This function is used for initialize
918 * the bus read and bus write functions
919 * and assign the chip id and I2C address of the BME280 sensor
920 * chip id is read in the register 0xD0 bit from 0 to 7
922 * @param bme280 structure pointer.
924 * @note While changing the parameter of the bme280_t
925 * @note consider the following point:
926 * Changing the reference value of the parameter
927 * will changes the local copy or local reference
928 * make sure your changes will not
929 * affect the reference value of the parameter
930 * (Better case don't change the reference value of the parameter)
935 * @return results of bus communication function
936 * @retval 0 -> Success
937 * @retval -1 -> Error
941 BME280_RETURN_FUNCTION_TYPE bme280_init(struct bme280_t *bme280);
942 /**************************************************************/
943 /**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED TEMPERATURE */
944 /**************************************************************/
946 * @brief This API is used to read uncompensated temperature
947 * in the registers 0xFA, 0xFB and 0xFC
948 * @note 0xFA -> MSB -> bit from 0 to 7
949 * @note 0xFB -> LSB -> bit from 0 to 7
950 * @note 0xFC -> LSB -> bit from 4 to 7
952 * @param v_uncomp_temperature_s32 : The value of uncompensated temperature
956 * @return results of bus communication function
957 * @retval 0 -> Success
958 * @retval -1 -> Error
962 BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_temperature(
963 s32 *v_uncomp_temperature_s32);
964 /**************************************************************/
965 /**\name FUNCTION FOR INTIALIZATION TRUE TEMPERATURE */
966 /**************************************************************/
968 * @brief Reads actual temperature from uncompensated temperature
969 * @note Returns the value in 0.01 degree Centigrade
970 * Output value of "5123" equals 51.23 DegC.
974 * @param v_uncomp_temperature_s32 : value of uncompensated temperature
977 * @return Returns the actual temperature
980 s32 bme280_compensate_T_int32(s32 v_uncomp_temperature_s32);
982 * @brief Reads actual temperature from uncompensated temperature
983 * @note Returns the value with 500LSB/DegC centred around 24 DegC
984 * output value of "5123" equals(5123/500)+24 = 34.246DegC
987 * @param v_uncomp_temperature_s32: value of uncompensated temperature
991 * @return Return the actual temperature as s16 output
994 s16 bme280_compensate_T_int32_sixteen_bit_output(s32 v_uncomp_temperature_s32);
995 /**************************************************************/
996 /**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED PRESSURE */
997 /**************************************************************/
999 * @brief This API is used to read uncompensated pressure.
1000 * in the registers 0xF7, 0xF8 and 0xF9
1001 * @note 0xF7 -> MSB -> bit from 0 to 7
1002 * @note 0xF8 -> LSB -> bit from 0 to 7
1003 * @note 0xF9 -> LSB -> bit from 4 to 7
1007 * @param v_uncomp_pressure_s32 : The value of uncompensated pressure
1011 * @return results of bus communication function
1012 * @retval 0 -> Success
1013 * @retval -1 -> Error
1017 BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure(
1018 s32 *v_uncomp_pressure_s32);
1019 /**************************************************************/
1020 /**\name FUNCTION FOR INTIALIZATION TRUE PRESSURE */
1021 /**************************************************************/
1023 * @brief Reads actual pressure from uncompensated pressure
1024 * @note Returns the value in Pascal(Pa)
1025 * Output value of "96386" equals 96386 Pa =
1026 * 963.86 hPa = 963.86 millibar
1030 * @param v_uncomp_pressure_s32 : value of uncompensated pressure
1034 * @return Return the actual pressure output as u32
1037 u32 bme280_compensate_P_int32(s32 v_uncomp_pressure_s32);
1038 /**************************************************************/
1039 /**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED HUMIDITY */
1040 /**************************************************************/
1042 * @brief This API is used to read uncompensated humidity.
1043 * in the registers 0xF7, 0xF8 and 0xF9
1044 * @note 0xFD -> MSB -> bit from 0 to 7
1045 * @note 0xFE -> LSB -> bit from 0 to 7
1049 * @param v_uncomp_humidity_s32 : The value of uncompensated humidity
1053 * @return results of bus communication function
1054 * @retval 0 -> Success
1055 * @retval -1 -> Error
1059 BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_humidity(
1060 s32 *v_uncomp_humidity_s32);
1061 /**************************************************************/
1062 /**\name FUNCTION FOR INTIALIZATION RELATIVE HUMIDITY */
1063 /**************************************************************/
1065 * @brief Reads actual humidity from uncompensated humidity
1066 * @note Returns the value in %rH as unsigned 32bit integer
1067 * in Q22.10 format(22 integer 10 fractional bits).
1068 * @note An output value of 42313
1069 * represents 42313 / 1024 = 41.321 %rH
1073 * @param v_uncomp_humidity_s32: value of uncompensated humidity
1075 * @return Return the actual relative humidity output as u32
1078 u32 bme280_compensate_H_int32(s32 v_uncomp_humidity_s32);
1080 * @brief Reads actual humidity from uncompensated humidity
1081 * @note Returns the value in %rH as unsigned 16bit integer
1082 * @note An output value of 42313
1083 * represents 42313/512 = 82.643 %rH
1087 * @param v_uncomp_humidity_s32: value of uncompensated humidity
1090 * @return Return the actual relative humidity output as u16
1093 u16 bme280_compensate_H_int32_sixteen_bit_output(s32 v_uncomp_humidity_s32);
1094 /**************************************************************/
1095 /**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED PRESSURE,
1096 TEMPERATURE AND HUMIDITY */
1097 /**************************************************************/
1099 * @brief This API used to read uncompensated
1100 * pressure,temperature and humidity
1105 * @param v_uncomp_pressure_s32: The value of uncompensated pressure.
1106 * @param v_uncomp_temperature_s32: The value of uncompensated temperature
1107 * @param v_uncomp_humidity_s32: The value of uncompensated humidity.
1111 * @return results of bus communication function
1112 * @retval 0 -> Success
1113 * @retval -1 -> Error
1117 BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure_temperature_humidity(
1118 s32 *v_uncomp_pressure_s32,
1119 s32 *v_uncomp_temperature_s32, s32 *v_uncomp_humidity_s32);
1120 /**************************************************************/
1121 /**\name FUNCTION FOR TRUE UNCOMPENSATED PRESSURE,
1122 TEMPERATURE AND HUMIDITY */
1123 /**************************************************************/
1125 * @brief This API used to read true pressure, temperature and humidity
1130 * @param v_pressure_u32 : The value of compensated pressure.
1131 * @param v_temperature_s32 : The value of compensated temperature.
1132 * @param v_humidity_u32 : The value of compensated humidity.
1135 * @return results of bus communication function
1136 * @retval 0 -> Success
1137 * @retval -1 -> Error
1141 BME280_RETURN_FUNCTION_TYPE bme280_read_pressure_temperature_humidity(
1142 u32 *v_pressure_u32, s32 *v_temperature_s32, u32 *v_humidity_u32);
1143 /**************************************************************/
1144 /**\name FUNCTION FOR CALIBRATION */
1145 /**************************************************************/
1147 * @brief This API is used to
1148 * calibration parameters used for calculation in the registers
1150 * parameter | Register address | bit
1151 *------------|------------------|----------------
1152 * dig_T1 | 0x88 and 0x89 | from 0 : 7 to 8: 15
1153 * dig_T2 | 0x8A and 0x8B | from 0 : 7 to 8: 15
1154 * dig_T3 | 0x8C and 0x8D | from 0 : 7 to 8: 15
1155 * dig_P1 | 0x8E and 0x8F | from 0 : 7 to 8: 15
1156 * dig_P2 | 0x90 and 0x91 | from 0 : 7 to 8: 15
1157 * dig_P3 | 0x92 and 0x93 | from 0 : 7 to 8: 15
1158 * dig_P4 | 0x94 and 0x95 | from 0 : 7 to 8: 15
1159 * dig_P5 | 0x96 and 0x97 | from 0 : 7 to 8: 15
1160 * dig_P6 | 0x98 and 0x99 | from 0 : 7 to 8: 15
1161 * dig_P7 | 0x9A and 0x9B | from 0 : 7 to 8: 15
1162 * dig_P8 | 0x9C and 0x9D | from 0 : 7 to 8: 15
1163 * dig_P9 | 0x9E and 0x9F | from 0 : 7 to 8: 15
1164 * dig_H1 | 0xA1 | from 0 to 7
1165 * dig_H2 | 0xE1 and 0xE2 | from 0 : 7 to 8: 15
1166 * dig_H3 | 0xE3 | from 0 to 7
1168 * @return results of bus communication function
1169 * @retval 0 -> Success
1170 * @retval -1 -> Error
1174 BME280_RETURN_FUNCTION_TYPE bme280_get_calib_param(void);
1175 /**************************************************************/
1176 /**\name FUNCTION FOR TEMPERATURE OVER SAMPLING */
1177 /**************************************************************/
1179 * @brief This API is used to get
1180 * the temperature oversampling setting in the register 0xF4
1183 * value | Temperature oversampling
1184 * ---------------------|---------------------------------
1186 * 0x01 | BME280_OVERSAMP_1X
1187 * 0x02 | BME280_OVERSAMP_2X
1188 * 0x03 | BME280_OVERSAMP_4X
1189 * 0x04 | BME280_OVERSAMP_8X
1190 * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X
1193 * @param v_value_u8 : The value of temperature over sampling
1197 * @return results of bus communication function
1198 * @retval 0 -> Success
1199 * @retval -1 -> Error
1203 BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_temperature(
1206 * @brief This API is used to set
1207 * the temperature oversampling setting in the register 0xF4
1210 * value | Temperature oversampling
1211 * ---------------------|---------------------------------
1213 * 0x01 | BME280_OVERSAMP_1X
1214 * 0x02 | BME280_OVERSAMP_2X
1215 * 0x03 | BME280_OVERSAMP_4X
1216 * 0x04 | BME280_OVERSAMP_8X
1217 * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X
1220 * @param v_value_u8 : The value of temperature over sampling
1224 * @return results of bus communication function
1225 * @retval 0 -> Success
1226 * @retval -1 -> Error
1230 BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_temperature(
1232 /**************************************************************/
1233 /**\name FUNCTION FOR PRESSURE OVER SAMPLING */
1234 /**************************************************************/
1236 * @brief This API is used to get
1237 * the pressure oversampling setting in the register 0xF4
1240 * value | Pressure oversampling
1241 * --------------------|--------------------------
1243 * 0x01 | BME280_OVERSAMP_1X
1244 * 0x02 | BME280_OVERSAMP_2X
1245 * 0x03 | BME280_OVERSAMP_4X
1246 * 0x04 | BME280_OVERSAMP_8X
1247 * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X
1250 * @param v_value_u8 : The value of pressure oversampling
1254 * @return results of bus communication function
1255 * @retval 0 -> Success
1256 * @retval -1 -> Error
1260 BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_pressure(
1263 * @brief This API is used to set
1264 * the pressure oversampling setting in the register 0xF4
1267 * value | Pressure oversampling
1268 * --------------------|--------------------------
1270 * 0x01 | BME280_OVERSAMP_1X
1271 * 0x02 | BME280_OVERSAMP_2X
1272 * 0x03 | BME280_OVERSAMP_4X
1273 * 0x04 | BME280_OVERSAMP_8X
1274 * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X
1277 * @param v_value_u8 : The value of pressure oversampling
1281 * @return results of bus communication function
1282 * @retval 0 -> Success
1283 * @retval -1 -> Error
1287 BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_pressure(
1289 /**************************************************************/
1290 /**\name FUNCTION FOR HUMIDITY OVER SAMPLING */
1291 /**************************************************************/
1293 * @brief This API is used to get
1294 * the humidity oversampling setting in the register 0xF2
1297 * value | Humidity oversampling
1298 * ---------------------|-------------------------
1300 * 0x01 | BME280_OVERSAMP_1X
1301 * 0x02 | BME280_OVERSAMP_2X
1302 * 0x03 | BME280_OVERSAMP_4X
1303 * 0x04 | BME280_OVERSAMP_8X
1304 * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X
1307 * @param v_value_u8 : The value of humidity over sampling
1311 * @return results of bus communication function
1312 * @retval 0 -> Success
1313 * @retval -1 -> Error
1317 BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_humidity(u8 *v_value_u8);
1319 * @brief This API is used to set
1320 * the humidity oversampling setting in the register 0xF2
1323 * value | Humidity oversampling
1324 * ---------------------|-------------------------
1326 * 0x01 | BME280_OVERSAMP_1X
1327 * 0x02 | BME280_OVERSAMP_2X
1328 * 0x03 | BME280_OVERSAMP_4X
1329 * 0x04 | BME280_OVERSAMP_8X
1330 * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X
1333 * @param v_value_u8 : The value of humidity over sampling
1337 * @note The "BME280_CTRL_HUMIDITY_REG_OVERSAM_HUMIDITY"
1338 * register sets the humidity
1339 * data acquisition options of the device.
1340 * @note changes to this registers only become
1341 * effective after a write operation to
1342 * "BME280_CTRL_MEAS_REG" register.
1343 * @note In the code automated reading and writing of
1344 * "BME280_CTRL_HUMIDITY_REG_OVERSAM_HUMIDITY"
1345 * @note register first set the
1346 * "BME280_CTRL_HUMIDITY_REG_OVERSAM_HUMIDITY"
1347 * and then read and write
1348 * the "BME280_CTRL_MEAS_REG" register in the function.
1351 * @return results of bus communication function
1352 * @retval 0 -> Success
1353 * @retval -1 -> Error
1357 BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_humidity(
1359 /**************************************************************/
1360 /**\name FUNCTION FOR POWER MODE*/
1361 /**************************************************************/
1363 * @brief This API used to get the
1364 * Operational Mode from the sensor in the register 0xF4 bit 0 and 1
1368 * @param v_power_mode_u8 : The value of power mode
1370 * -----------------|------------------
1371 * 0x00 | BME280_SLEEP_MODE
1372 * 0x01 and 0x02 | BME280_FORCED_MODE
1373 * 0x03 | BME280_NORMAL_MODE
1375 * @return results of bus communication function
1376 * @retval 0 -> Success
1377 * @retval -1 -> Error
1381 BME280_RETURN_FUNCTION_TYPE bme280_get_power_mode(u8 *v_power_mode_u8);
1383 * @brief This API used to set the
1384 * Operational Mode from the sensor in the register 0xF4 bit 0 and 1
1388 * @param v_power_mode_u8 : The value of power mode
1390 * -----------------|------------------
1391 * 0x00 | BME280_SLEEP_MODE
1392 * 0x01 and 0x02 | BME280_FORCED_MODE
1393 * 0x03 | BME280_NORMAL_MODE
1395 * @return results of bus communication function
1396 * @retval 0 -> Success
1397 * @retval -1 -> Error
1401 BME280_RETURN_FUNCTION_TYPE bme280_set_power_mode(u8 v_power_mode_u8);
1402 /**************************************************************/
1403 /**\name FUNCTION FOR SOFT RESET*/
1404 /**************************************************************/
1406 * @brief Used to reset the sensor
1407 * The value 0xB6 is written to the 0xE0
1408 * register the device is reset using the
1409 * complete power-on-reset procedure.
1410 * @note Soft reset can be easily set using bme280_set_softreset().
1411 * @note Usage Hint : bme280_set_softreset()
1414 * @return results of bus communication function
1415 * @retval 0 -> Success
1416 * @retval -1 -> Error
1420 BME280_RETURN_FUNCTION_TYPE bme280_set_soft_rst(void);
1421 /**************************************************************/
1422 /**\name FUNCTION FOR SPI ENABLE*/
1423 /**************************************************************/
1425 * @brief This API used to get the sensor
1426 * SPI mode(communication type) in the register 0xF5 bit 0
1430 * @param v_enable_disable_u8 : The value of SPI enable
1431 * value | Description
1432 * --------|--------------
1438 * @return results of bus communication function
1439 * @retval 0 -> Success
1440 * @retval -1 -> Error
1444 BME280_RETURN_FUNCTION_TYPE bme280_get_spi3(u8 *v_enable_disable_u8);
1446 * @brief This API used to set the sensor
1447 * SPI mode(communication type) in the register 0xF5 bit 0
1451 * @param v_enable_disable_u8 : The value of SPI enable
1452 * value | Description
1453 * --------|--------------
1459 * @return results of bus communication function
1460 * @retval 0 -> Success
1461 * @retval -1 -> Error
1465 BME280_RETURN_FUNCTION_TYPE bme280_set_spi3(u8 v_enable_disable_u8);
1466 /**************************************************************/
1467 /**\name FUNCTION FOR IIR FILTER*/
1468 /**************************************************************/
1470 * @brief This API is used to reads filter setting
1471 * in the register 0xF5 bit 3 and 4
1475 * @param v_value_u8 : The value of IIR filter coefficient
1477 * value | Filter coefficient
1478 * -------------|-------------------------
1479 * 0x00 | BME280_FILTER_COEFF_OFF
1480 * 0x01 | BME280_FILTER_COEFF_2
1481 * 0x02 | BME280_FILTER_COEFF_4
1482 * 0x03 | BME280_FILTER_COEFF_8
1483 * 0x04 | BME280_FILTER_COEFF_16
1485 * @return results of bus communication function
1486 * @retval 0 -> Success
1487 * @retval -1 -> Error
1491 BME280_RETURN_FUNCTION_TYPE bme280_get_filter(u8 *v_value_u8);
1493 * @brief This API is used to write filter setting
1494 * in the register 0xF5 bit 3 and 4
1498 * @param v_value_u8 : The value of IIR filter coefficient
1500 * value | Filter coefficient
1501 * -------------|-------------------------
1502 * 0x00 | BME280_FILTER_COEFF_OFF
1503 * 0x01 | BME280_FILTER_COEFF_2
1504 * 0x02 | BME280_FILTER_COEFF_4
1505 * 0x03 | BME280_FILTER_COEFF_8
1506 * 0x04 | BME280_FILTER_COEFF_16
1508 * @return results of bus communication function
1509 * @retval 0 -> Success
1510 * @retval -1 -> Error
1514 BME280_RETURN_FUNCTION_TYPE bme280_set_filter(u8 v_value_u8);
1515 /**************************************************************/
1516 /**\name FUNCTION FOR STANDBY DURATION*/
1517 /**************************************************************/
1519 * @brief This API used to Read the
1520 * standby duration time from the sensor in the register 0xF5 bit 5 to 7
1522 * @param v_standby_durn_u8 : The value of standby duration time value.
1523 * value | standby duration
1524 * -------------|-----------------------
1525 * 0x00 | BME280_STANDBY_TIME_1_MS
1526 * 0x01 | BME280_STANDBY_TIME_63_MS
1527 * 0x02 | BME280_STANDBY_TIME_125_MS
1528 * 0x03 | BME280_STANDBY_TIME_250_MS
1529 * 0x04 | BME280_STANDBY_TIME_500_MS
1530 * 0x05 | BME280_STANDBY_TIME_1000_MS
1531 * 0x06 | BME280_STANDBY_TIME_2000_MS
1532 * 0x07 | BME280_STANDBY_TIME_4000_MS
1535 * @return results of bus communication function
1536 * @retval 0 -> Success
1537 * @retval -1 -> Error
1541 BME280_RETURN_FUNCTION_TYPE bme280_get_standby_durn(u8 *v_standby_durn_u8);
1543 * @brief This API used to write the
1544 * standby duration time from the sensor in the register 0xF5 bit 5 to 7
1546 * @param v_standby_durn_u8 : The value of standby duration time value.
1547 * value | standby duration
1548 * -------------|-----------------------
1549 * 0x00 | BME280_STANDBY_TIME_1_MS
1550 * 0x01 | BME280_STANDBY_TIME_63_MS
1551 * 0x02 | BME280_STANDBY_TIME_125_MS
1552 * 0x03 | BME280_STANDBY_TIME_250_MS
1553 * 0x04 | BME280_STANDBY_TIME_500_MS
1554 * 0x05 | BME280_STANDBY_TIME_1000_MS
1555 * 0x06 | BME280_STANDBY_TIME_2000_MS
1556 * 0x07 | BME280_STANDBY_TIME_4000_MS
1558 * @note Normal mode comprises an automated perpetual
1559 * cycling between an (active)
1560 * Measurement period and an (inactive) standby period.
1561 * @note The standby time is determined by
1562 * the contents of the register t_sb.
1563 * Standby time can be set using BME280_STANDBY_TIME_125_MS.
1565 * @note Usage Hint : bme280_set_standby_durn(BME280_STANDBY_TIME_125_MS)
1569 * @return results of bus communication function
1570 * @retval 0 -> Success
1571 * @retval -1 -> Error
1575 BME280_RETURN_FUNCTION_TYPE bme280_set_standby_durn(u8 v_standby_durn_u8);
1576 /**************************************************************/
1577 /**\name FUNCTION FOR WORK MODE*/
1578 /**************************************************************/
1580 * @brief Writes the working mode to the sensor
1585 * @param v_work_mode_u8 : Mode to be set
1586 * value | Working mode
1587 * ----------|--------------------
1588 * 0 | BME280_ULTRALOWPOWER_MODE
1589 * 1 | BME280_LOWPOWER_MODE
1590 * 2 | BME280_STANDARDRESOLUTION_MODE
1591 * 3 | BME280_HIGHRESOLUTION_MODE
1592 * 4 | BME280_ULTRAHIGHRESOLUTION_MODE
1594 * @return results of bus communication function
1595 * @retval 0 -> Success
1596 * @retval -1 -> Error
1600 /*BME280_RETURN_FUNCTION_TYPE bme280_set_work_mode(u8 v_work_mode_u8);*/
1601 /**************************************************************/
1602 /**\name FUNCTION FOR FORCE MODE DATA READ*/
1603 /**************************************************************/
1605 * @brief This API used to read uncompensated
1606 * temperature,pressure and humidity in forced mode
1609 * @param v_uncom_pressure_s32: The value of uncompensated pressure
1610 * @param v_uncom_temperature_s32: The value of uncompensated temperature
1611 * @param v_uncom_humidity_s32: The value of uncompensated humidity
1614 * @return results of bus communication function
1615 * @retval 0 -> Success
1616 * @retval -1 -> Error
1620 BME280_RETURN_FUNCTION_TYPE
1621 bme280_get_forced_uncomp_pressure_temperature_humidity(
1622 s32 *v_uncom_pressure_s32,
1623 s32 *v_uncom_temperature_s32, s32 *v_uncom_humidity_s32);
1624 /**************************************************************/
1625 /**\name FUNCTION FOR COMMON READ AND WRITE */
1626 /**************************************************************/
1629 * This API write the data to
1630 * the given register
1633 * @param v_addr_u8 -> Address of the register
1634 * @param v_data_u8 -> The data from the register
1635 * @param v_len_u8 -> no of bytes to read
1638 * @return results of bus communication function
1639 * @retval 0 -> Success
1640 * @retval -1 -> Error
1644 BME280_RETURN_FUNCTION_TYPE bme280_write_register(u8 v_addr_u8,
1645 u8 *v_data_u8, u8 v_len_u8);
1648 * This API reads the data from
1649 * the given register
1652 * @param v_addr_u8 -> Address of the register
1653 * @param v_data_u8 -> The data from the register
1654 * @param v_len_u8 -> no of bytes to read
1657 * @return results of bus communication function
1658 * @retval 0 -> Success
1659 * @retval -1 -> Error
1663 BME280_RETURN_FUNCTION_TYPE bme280_read_register(u8 v_addr_u8,
1664 u8 *v_data_u8, u8 v_len_u8);
1665 /**************************************************************/
1666 /**\name FUNCTION FOR FLOAT OUTPUT TEMPERATURE*/
1667 /**************************************************************/
1668 #ifdef BME280_ENABLE_FLOAT
1670 * @brief Reads actual temperature from uncompensated temperature
1671 * @note returns the value in Degree centigrade
1672 * @note Output value of "51.23" equals 51.23 DegC.
1676 * @param v_uncom_temperature_s32 : value of uncompensated temperature
1680 * @return Return the actual temperature in floating point
1683 double bme280_compensate_T_double(s32 v_uncom_temperature_s32);
1684 /**************************************************************/
1685 /**\name FUNCTION FOR FLOAT OUTPUT PRESSURE*/
1686 /**************************************************************/
1688 * @brief Reads actual pressure from uncompensated pressure
1689 * @note Returns pressure in Pa as double.
1690 * @note Output value of "96386.2"
1691 * equals 96386.2 Pa = 963.862 hPa.
1694 * @param v_uncom_pressure_s32 : value of uncompensated pressure
1697 * @return Return the actual pressure in floating point
1700 double bme280_compensate_P_double(s32 v_uncom_pressure_s32);
1701 /**************************************************************/
1702 /**\name FUNCTION FOR FLOAT OUTPUT HUMIDITY*/
1703 /**************************************************************/
1705 * @brief Reads actual humidity from uncompensated humidity
1706 * @note returns the value in relative humidity (%rH)
1707 * @note Output value of "42.12" equals 42.12 %rH
1709 * @param v_uncom_humidity_s32 : value of uncompensated humidity
1713 * @return Return the actual humidity in floating point
1716 double bme280_compensate_H_double(s32 v_uncom_humidity_s32);
1718 /**************************************************************/
1719 /**\name FUNCTION FOR 64BIT OUTPUT PRESSURE*/
1720 /**************************************************************/
1721 #if defined(BME280_ENABLE_INT64) && defined(BME280_64BITSUPPORT_PRESENT)
1723 * @brief Reads actual pressure from uncompensated pressure
1724 * @note Returns the value in Pa as unsigned 32 bit
1725 * integer in Q24.8 format (24 integer bits and
1726 * 8 fractional bits).
1727 * @note Output value of "24674867"
1728 * represents 24674867 / 256 = 96386.2 Pa = 963.862 hPa
1732 * @param v_uncom_pressure_s32 : value of uncompensated temperature
1735 * @return Return the actual pressure in u32
1738 u32 bme280_compensate_P_int64(s32 v_uncom_pressure_s32);
1739 /**************************************************************/
1740 /**\name FUNCTION FOR 24BIT OUTPUT PRESSURE*/
1741 /**************************************************************/
1743 * @brief Reads actual pressure from uncompensated pressure
1744 * @note Returns the value in Pa.
1745 * @note Output value of "12337434"
1746 * @note represents 12337434 / 128 = 96386.2 Pa = 963.862 hPa
1750 * @param v_uncom_pressure_s32 : value of uncompensated pressure
1753 * @return the actual pressure in u32
1756 u32 bme280_compensate_P_int64_twentyfour_bit_output(s32 v_uncom_pressure_s32);
1758 /**************************************************************/
1759 /**\name FUNCTION FOR WAIT PERIOD*/
1760 /**************************************************************/
1762 * @brief Computing waiting time for sensor data read
1767 * @param v_delaytime_u8 : The value of delay time for force mode
1770 * @retval 0 -> Success
1774 BME280_RETURN_FUNCTION_TYPE bme280_compute_wait_time(u8