LibDriver BMP280
Loading...
Searching...
No Matches
driver_bmp280.c
Go to the documentation of this file.
1
36
37#include "driver_bmp280.h"
38
42#define CHIP_NAME "Bosch BMP280"
43#define MANUFACTURER_NAME "Bosch"
44#define SUPPLY_VOLTAGE_MIN 1.71f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 1.12f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
50
54#define BMP280_REG_NVM_PAR_T1_L 0x88
55#define BMP280_REG_NVM_PAR_T1_H 0x89
56#define BMP280_REG_NVM_PAR_T2_L 0x8A
57#define BMP280_REG_NVM_PAR_T2_H 0x8B
58#define BMP280_REG_NVM_PAR_T3_L 0x8C
59#define BMP280_REG_NVM_PAR_T3_H 0x8D
60#define BMP280_REG_NVM_PAR_P1_L 0x8E
61#define BMP280_REG_NVM_PAR_P1_H 0x8F
62#define BMP280_REG_NVM_PAR_P2_L 0x90
63#define BMP280_REG_NVM_PAR_P2_H 0x91
64#define BMP280_REG_NVM_PAR_P3_L 0x92
65#define BMP280_REG_NVM_PAR_P3_H 0x93
66#define BMP280_REG_NVM_PAR_P4_L 0x94
67#define BMP280_REG_NVM_PAR_P4_H 0x95
68#define BMP280_REG_NVM_PAR_P5_L 0x96
69#define BMP280_REG_NVM_PAR_P5_H 0x97
70#define BMP280_REG_NVM_PAR_P6_L 0x98
71#define BMP280_REG_NVM_PAR_P6_H 0x99
72#define BMP280_REG_NVM_PAR_P7_L 0x9A
73#define BMP280_REG_NVM_PAR_P7_H 0x9B
74#define BMP280_REG_NVM_PAR_P8_L 0x9C
75#define BMP280_REG_NVM_PAR_P8_H 0x9D
76#define BMP280_REG_NVM_PAR_P9_L 0x9E
77#define BMP280_REG_NVM_PAR_P9_H 0x9F
78#define BMP280_REG_TEMP_XLSB 0xFC
79#define BMP280_REG_TEMP_LSB 0xFB
80#define BMP280_REG_TEMP_MSB 0xFA
81#define BMP280_REG_PRESS_XLSB 0xF9
82#define BMP280_REG_PRESS_LSB 0xF8
83#define BMP280_REG_PRESS_MSB 0xF7
84#define BMP280_REG_CONFIG 0xF5
85#define BMP280_REG_CTRL_MEAS 0xF4
86#define BMP280_REG_STATUS 0xF3
87#define BMP280_REG_RESET 0xE0
88#define BMP280_REG_ID 0xD0
89
101static uint8_t a_bmp280_iic_spi_read(bmp280_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
102{
103 if (handle->iic_spi == BMP280_INTERFACE_IIC) /* iic interface */
104 {
105 if (handle->iic_read(handle->iic_addr, reg, buf, len) != 0) /* iic read */
106 {
107 return 1; /* return error */
108 }
109
110 return 0; /* success return 0 */
111 }
112 else /* spi interface */
113 {
114 reg |= 1 << 7; /* set read mode */
115 if (handle->spi_read(reg, buf, len) != 0) /* spi read */
116 {
117 return 1; /* return error */
118 }
119
120 return 0; /* success return 0 */
121 }
122}
123
135static uint8_t a_bmp280_iic_spi_write(bmp280_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
136{
137 if (handle->iic_spi == BMP280_INTERFACE_IIC) /* iic interface */
138 {
139 if (handle->iic_write(handle->iic_addr, reg, buf, len) != 0) /* iic write */
140 {
141 return 1; /* return error */
142 }
143
144 return 0; /* success return 0 */
145 }
146 else /* spi interface */
147 {
148 reg &= ~(1 << 7); /* write mode */
149 if (handle->spi_write(reg, buf, len) != 0) /* spi write */
150 {
151 return 1; /* return error */
152 }
153
154 return 0; /* success return 0 */
155 }
156}
157
166static uint8_t a_bmp280_get_nvm_calibration(bmp280_handle_t *handle)
167{
168 uint8_t buf[2];
169
170 if (a_bmp280_iic_spi_read(handle, BMP280_REG_NVM_PAR_T1_L, (uint8_t *)buf, 2) != 0) /* read t1 */
171 {
172 handle->debug_print("bmp280: get calibration data failed.\n"); /* get calibration data failed */
173
174 return 1; /* return error */
175 }
176 handle->t1 = (uint16_t)buf[1] << 8 | buf[0]; /* set t1 */
177 if (a_bmp280_iic_spi_read(handle, BMP280_REG_NVM_PAR_T2_L, (uint8_t *)buf, 2) != 0) /* read t2 */
178 {
179 handle->debug_print("bmp280: get calibration data failed.\n"); /* get calibration data failed */
180
181 return 1; /* return error */
182 }
183 handle->t2 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set t2 */
184 if (a_bmp280_iic_spi_read(handle, BMP280_REG_NVM_PAR_T3_L, (uint8_t *)buf, 2) != 0) /* read t3 */
185 {
186 handle->debug_print("bmp280: get calibration data failed.\n"); /* get calibration data failed */
187
188 return 1; /* return error */
189 }
190 handle->t3 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set t3 */
191 if (a_bmp280_iic_spi_read(handle, BMP280_REG_NVM_PAR_P1_L, (uint8_t *)buf, 2) != 0) /* read p1 */
192 {
193 handle->debug_print("bmp280: get calibration data failed.\n"); /* get calibration data failed */
194
195 return 1; /* return error */
196 }
197 handle->p1 = (uint16_t)buf[1] << 8 | buf[0]; /* set p1 */
198 if (a_bmp280_iic_spi_read(handle, BMP280_REG_NVM_PAR_P2_L, (uint8_t *)buf, 2) != 0) /* read p2 */
199 {
200 handle->debug_print("bmp280: get calibration data failed.\n"); /* get calibration data failed */
201
202 return 1; /* return error */
203 }
204 handle->p2 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p2 */
205 if (a_bmp280_iic_spi_read(handle, BMP280_REG_NVM_PAR_P3_L, (uint8_t *)buf, 2) != 0) /* read p3 */
206 {
207 handle->debug_print("bmp280: get calibration data failed.\n"); /* get calibration data failed */
208
209 return 1; /* return error */
210 }
211 handle->p3 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p3 */
212 if (a_bmp280_iic_spi_read(handle, BMP280_REG_NVM_PAR_P4_L, (uint8_t *)buf, 2) != 0) /* read p4 */
213 {
214 handle->debug_print("bmp280: get calibration data failed.\n"); /* get calibration data failed */
215
216 return 1; /* return error */
217 }
218 handle->p4 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p4 */
219 if (a_bmp280_iic_spi_read(handle, BMP280_REG_NVM_PAR_P5_L, (uint8_t *)buf, 2) != 0) /* read p5 */
220 {
221 handle->debug_print("bmp280: get calibration data failed.\n"); /* get calibration data failed */
222
223 return 1; /* return error */
224 }
225 handle->p5 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p5 */
226 if (a_bmp280_iic_spi_read(handle, BMP280_REG_NVM_PAR_P6_L, (uint8_t *)buf, 2) != 0) /* read p6 */
227 {
228 handle->debug_print("bmp280: get calibration data failed.\n"); /* get calibration data failed */
229
230 return 1; /* return error */
231 }
232 handle->p6 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p6 */
233 if (a_bmp280_iic_spi_read(handle, BMP280_REG_NVM_PAR_P7_L, (uint8_t *)buf, 2) != 0) /* read p7 */
234 {
235 handle->debug_print("bmp280: get calibration data failed.\n"); /* get calibration data failed */
236
237 return 1; /* return error */
238 }
239 handle->p7 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p7 */
240 if (a_bmp280_iic_spi_read(handle, BMP280_REG_NVM_PAR_P8_L, (uint8_t *)buf, 2) != 0) /* read p8 */
241 {
242 handle->debug_print("bmp280: get calibration data failed.\n"); /* get calibration data failed */
243
244 return 1; /* return error */
245 }
246 handle->p8 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p8 */
247 if (a_bmp280_iic_spi_read(handle, BMP280_REG_NVM_PAR_P9_L, (uint8_t *)buf, 2) != 0) /* read p9 */
248 {
249 handle->debug_print("bmp280: get calibration data failed.\n"); /* get calibration data failed */
250
251 return 1; /* return error */
252 }
253 handle->p9 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p9 */
254 handle->t_fine = 0; /* init 0 */
255
256 return 0; /* success return 0 */
257}
258
269static uint8_t a_bmp280_compensate_temperature(bmp280_handle_t *handle, uint32_t raw, float *output)
270{
271 uint8_t res;
272 float var1;
273 float var2;
274 float temperature;
275
276 var1 = (((float)raw) / 16384.0f - ((float)handle->t1) / 1024.0f) * ((float)handle->t2); /* set var1 */
277 var2 = ((((float)raw) / 131072.0f - ((float)handle->t1) / 8192.0f) *
278 (((float)raw) / 131072.0f - ((float)handle->t1) / 8192.0f)) *
279 ((float)handle->t3); /* set var2 */
280 handle->t_fine = (int32_t)(var1 + var2); /* set t_fine */
281 temperature = (var1 + var2) / 5120.0f; /* set temperature */
282 res = 0; /* init 0 */
283 if (temperature < -40.0f) /* check temperature min */
284 {
285 temperature = -40.0f; /* set min */
286 res = 1; /* set failed */
287 }
288 if (temperature > 85.0f) /* check temperature max */
289 {
290 temperature = 85.0f; /* set max */
291 res = 1; /* set failed */
292 }
293 (*output) = temperature; /* set output temperature */
294
295 return res; /* return result */
296}
297
308static uint8_t a_bmp280_compensate_pressure(bmp280_handle_t *handle, uint32_t raw, float *output)
309{
310 uint8_t res;
311 float var1;
312 float var2;
313 float pressure;
314
315 var1 = ((float)handle->t_fine / 2.0f) - 64000.0f; /* set var1 */
316 var2 = var1 * var1 * ((float)handle->p6) / 32768.0f; /* set var2 */
317 var2 = var2 + var1 * ((float)handle->p5) * 2.0f; /* set var2 */
318 var2 = (var2 / 4.0f) + (((float)handle->p4) * 65536.0f); /* set var2 */
319 var1 = (((float)handle->p3) * var1 * var1 / 524288.0f +
320 ((float)handle->p2) * var1) / 524288.0f; /* set var1 */
321 var1 = (1.0f + var1 / 32768.0f) * ((float)handle->p1); /* set var1 */
322 pressure = 0.0f; /* init 0 */
323 if (var1 < 0.0f || var1 > 0.0f) /* check not zero */
324 {
325 pressure = 1048576.0f - (float)raw; /* set pressure */
326 pressure = (pressure - (var2 / 4096.0f)) * 6250.0f / var1; /* set pressure */
327 var1 = ((float)handle->p9) * pressure * pressure / 2147483648.0f; /* set var1 */
328 var2 = pressure * ((float)handle->p8) / 32768.0f; /* set var2 */
329 pressure = pressure + (var1 + var2 + ((float)handle->p7)) / 16.0f; /* set pressure */
330 res = 0; /* init 0 */
331 if (pressure < 30000.0f) /* check pressure min */
332 {
333 pressure = 30000.0f; /* set pressure min */
334 res = 1; /* set failed */
335 }
336 if (pressure > 110000.0f) /* check pressure max */
337 {
338 pressure = 110000.0f; /* set pressure max */
339 res = 1; /* set failed */
340 }
341
342 (*output) = pressure; /* set pressure output */
343
344 return res; /* return result */
345 }
346 else
347 {
348 res = 1; /* set failed */
349 (*output) = pressure; /* set pressure output */
350
351 return res; /* return result */
352 }
353}
354
365{
366 if (handle == NULL) /* check handle */
367 {
368 return 2; /* return error */
369 }
370
371 handle->iic_addr = (uint8_t)addr_pin; /* set iic address */
372
373 return 0; /* success return 0 */
374}
375
386{
387 if (handle == NULL) /* check handle */
388 {
389 return 2; /* return error */
390 }
391
392 *addr_pin = (bmp280_address_t)handle->iic_addr; /* get iic address */
393
394 return 0; /* success return 0 */
395}
396
407{
408 if (handle == NULL) /* check handle */
409 {
410 return 2; /* return error */
411 }
412
413 handle->iic_spi = (uint8_t)interface; /* set interface */
414
415 return 0; /* success return 0 */
416}
417
428{
429 if (handle == NULL) /* check handle */
430 {
431 return 2; /* return error */
432 }
433
434 *interface = (bmp280_interface_t)(handle->iic_spi); /* get interface */
435
436 return 0; /* success return 0 */
437}
438
453{
454 uint8_t id;
455 uint8_t reg;
456
457 if (handle == NULL) /* check handle */
458 {
459 return 2; /* return error */
460 }
461 if (handle->debug_print == NULL) /* check debug_print */
462 {
463 return 3; /* return error */
464 }
465 if (handle->iic_init == NULL) /* check iic_init */
466 {
467 handle->debug_print("bmp280: iic_init is null.\n"); /* iic_init is nul */
468
469 return 3; /* return error */
470 }
471 if (handle->iic_deinit == NULL) /* check iic_deinit */
472 {
473 handle->debug_print("bmp280: iic_deinit is null.\n"); /* iic_deinit is null */
474
475 return 3; /* return error */
476 }
477 if (handle->iic_read == NULL) /* check iic_read */
478 {
479 handle->debug_print("bmp280: iic_read is null.\n"); /* iic_read is null */
480
481 return 3; /* return error */
482 }
483 if (handle->iic_write == NULL) /* check iic_write */
484 {
485 handle->debug_print("bmp280: iic_write is null.\n"); /* iic_write is null */
486
487 return 3; /* return error */
488 }
489 if (handle->spi_init == NULL) /* check spi_init */
490 {
491 handle->debug_print("bmp280: spi_init is null.\n"); /* spi_init is nul */
492
493 return 3; /* return error */
494 }
495 if (handle->spi_deinit == NULL) /* check spi_deinit */
496 {
497 handle->debug_print("bmp280: spi_deinit is null.\n"); /* spi_deinit is nul */
498
499 return 3; /* return error */
500 }
501 if (handle->spi_read == NULL) /* check spi_read */
502 {
503 handle->debug_print("bmp280: spi_read is null.\n"); /* spi_read is nul */
504
505 return 3; /* return error */
506 }
507 if (handle->spi_write == NULL) /* check spi_write */
508 {
509 handle->debug_print("bmp280: spi_write is null.\n"); /* spi_write is nul */
510
511 return 3; /* return error */
512 }
513 if (handle->delay_ms == NULL) /* check delay_ms */
514 {
515 handle->debug_print("bmp280: delay_ms is null.\n"); /* delay_ms is null */
516
517 return 3; /* return error */
518 }
519
520 if (handle->iic_spi == BMP280_INTERFACE_IIC) /* iic interface */
521 {
522 if (handle->iic_init() != 0) /* iic init */
523 {
524 handle->debug_print("bmp280: iic init failed.\n"); /* iic init failed */
525
526 return 1; /* return error */
527 }
528 }
529 else /* spi interface */
530 {
531 if (handle->spi_init() != 0) /* spi init */
532 {
533 handle->debug_print("bmp280: spi init failed.\n"); /* spi init failed */
534
535 return 1; /* return error */
536 }
537 }
538
539 if (a_bmp280_iic_spi_read(handle, BMP280_REG_ID, (uint8_t *)&id, 1) != 0) /* read chip id */
540 {
541 handle->debug_print("bmp280: read id failed.\n"); /* read id failed */
542 if (handle->iic_spi == BMP280_INTERFACE_IIC) /* iic interface */
543 {
544 (void)handle->iic_deinit(); /* iic deinit */
545 }
546 else /* spi interface */
547 {
548 (void)handle->spi_deinit(); /* spi deinit */
549 }
550
551 return 4; /* return error */
552 }
553 if (id != 0x58) /* check id */
554 {
555 handle->debug_print("bmp280: id is error.\n"); /* id is error */
556 if (handle->iic_spi == BMP280_INTERFACE_IIC) /* iic interface */
557 {
558 (void)handle->iic_deinit(); /* iic deinit */
559 }
560 else /* spi interface */
561 {
562 (void)handle->spi_deinit(); /* spi deinit */
563 }
564
565 return 4; /* return error */
566 }
567 reg = 0xB6; /* set the reset value */
568 if (a_bmp280_iic_spi_write(handle, BMP280_REG_RESET, &reg, 1) != 0) /* reset the chip */
569 {
570 handle->debug_print("bmp280: reset failed.\n"); /* reset failed */
571 if (handle->iic_spi == BMP280_INTERFACE_IIC) /* iic interface */
572 {
573 (void)handle->iic_deinit(); /* iic deinit */
574 }
575 else /* spi interface */
576 {
577 (void)handle->spi_deinit(); /* spi deinit */
578 }
579
580 return 5; /* return error */
581 }
582 handle->delay_ms(5); /* delay 5ms */
583 if (a_bmp280_get_nvm_calibration(handle) != 0) /* get nvm calibration */
584 {
585 if (handle->iic_spi == BMP280_INTERFACE_IIC) /* iic interface */
586 {
587 (void)handle->iic_deinit(); /* iic deinit */
588 }
589 else /* spi interface */
590 {
591 (void)handle->spi_deinit(); /* spi deinit */
592 }
593
594 return 6; /* return error */
595 }
596 handle->inited = 1; /* flag finish initialization */
597
598 return 0; /* success return 0 */
599}
600
613{
614 uint8_t prev;
615
616 if (handle == NULL) /* check handle */
617 {
618 return 2; /* return error */
619 }
620 if (handle->inited != 1) /* check handle initialization */
621 {
622 return 3; /* return error */
623 }
624
625 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
626 {
627 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
628
629 return 4; /* return error */
630 }
631 prev &= ~(3 << 0); /* clear settings */
632 prev |= 0 << 0; /* set sleep mode */
633 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
634 {
635 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
636
637 return 4; /* return error */
638 }
639 if (handle->iic_spi == BMP280_INTERFACE_IIC) /* iic interface */
640 {
641 if (handle->iic_deinit() != 0) /* iic deinit */
642 {
643 handle->debug_print("bmp280: iic deinit failed.\n"); /* iic deinit failed */
644
645 return 1; /* return error */
646 }
647 }
648 else /* spi interface */
649 {
650 if (handle->spi_deinit() != 0) /* spi deinit */
651 {
652 handle->debug_print("bmp280: spi deinit failed.\n"); /* spi deinit failed */
653
654 return 1; /* return error */
655 }
656 }
657 handle->inited = 0; /* flag close */
658
659 return 0; /* success return 0 */
660}
661
673{
674 uint8_t reg;
675
676 if (handle == NULL) /* check handle */
677 {
678 return 2; /* return error */
679 }
680 if (handle->inited != 1) /* check handle initialization */
681 {
682 return 3; /* return error */
683 }
684
685 reg = 0xB6; /* set the reset value */
686 if (a_bmp280_iic_spi_write(handle, BMP280_REG_RESET, &reg, 1) != 0) /* reset the chip */
687 {
688 handle->debug_print("bmp280: reset failed.\n"); /* reset failed */
689
690 return 1; /* return error */
691 }
692 handle->delay_ms(5); /* delay 5ms */
693
694 return 0; /* success return 0 */
695}
696
708uint8_t bmp280_get_status(bmp280_handle_t *handle, uint8_t *status)
709{
710 if (handle == NULL) /* check handle */
711 {
712 return 2; /* return error */
713 }
714 if (handle->inited != 1) /* check handle initialization */
715 {
716 return 3; /* return error */
717 }
718
719 if (a_bmp280_iic_spi_read(handle, BMP280_REG_STATUS, status, 1) != 0) /* read status */
720 {
721 handle->debug_print("bmp280: read status failed.\n"); /* read status failed */
722
723 return 1; /* return error */
724 }
725
726 return 0; /* success return 0 */
727}
728
741{
742 uint8_t prev;
743
744 if (handle == NULL) /* check handle */
745 {
746 return 2; /* return error */
747 }
748 if (handle->inited != 1) /* check handle initialization */
749 {
750 return 3; /* return error */
751 }
752
753 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
754 {
755 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
756
757 return 1; /* return error */
758 }
759 prev &= ~(7 << 5); /* clear settings */
760 prev |= oversampling << 5; /* set oversampling */
761 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
762 {
763 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
764
765 return 1; /* return error */
766 }
767
768 return 0; /* success return 0 */
769}
770
783{
784 uint8_t prev;
785
786 if (handle == NULL) /* check handle */
787 {
788 return 2; /* return error */
789 }
790 if (handle->inited != 1) /* check handle initialization */
791 {
792 return 3; /* return error */
793 }
794
795 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
796 {
797 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
798
799 return 1; /* return error */
800 }
801 *oversampling = (bmp280_oversampling_t)((prev >> 5) & 0x7); /* set oversampling */
802
803 return 0; /* success return 0 */
804}
805
818{
819 uint8_t prev;
820
821 if (handle == NULL) /* check handle */
822 {
823 return 2; /* return error */
824 }
825 if (handle->inited != 1) /* check handle initialization */
826 {
827 return 3; /* return error */
828 }
829
830 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
831 {
832 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
833
834 return 1; /* return error */
835 }
836 prev &= ~(7 << 2); /* clear settings */
837 prev |= oversampling << 2; /* set oversampling */
838 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
839 {
840 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
841
842 return 1; /* return error */
843 }
844
845 return 0; /* success return 0 */
846}
847
860{
861 uint8_t prev;
862
863 if (handle == NULL) /* check handle */
864 {
865 return 2; /* return error */
866 }
867 if (handle->inited != 1) /* check handle initialization */
868 {
869 return 3; /* return error */
870 }
871
872 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
873 {
874 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
875
876 return 1; /* return error */
877 }
878 *oversampling = (bmp280_oversampling_t)((prev >> 2) & 0x7); /* set oversampling */
879
880 return 0; /* success return 0 */
881}
882
895{
896 uint8_t prev;
897
898 if (handle == NULL) /* check handle */
899 {
900 return 2; /* return error */
901 }
902 if (handle->inited != 1) /* check handle initialization */
903 {
904 return 3; /* return error */
905 }
906
907 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
908 {
909 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
910
911 return 1; /* return error */
912 }
913 prev &= ~(3 << 0); /* clear settings */
914 prev |= mode << 0; /* set mode */
915 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
916 {
917 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
918
919 return 1; /* return error */
920 }
921
922 return 0; /* success return 0 */
923}
924
937{
938 uint8_t prev;
939
940 if (handle == NULL) /* check handle */
941 {
942 return 2; /* return error */
943 }
944 if (handle->inited != 1) /* check handle initialization */
945 {
946 return 3; /* return error */
947 }
948
949 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
950 {
951 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
952
953 return 1; /* return error */
954 }
955 *mode = (bmp280_mode_t)((prev >> 0) & 0x3); /* set mode */
956
957 return 0; /* success return 0 */
958}
959
972{
973 uint8_t prev;
974
975 if (handle == NULL) /* check handle */
976 {
977 return 2; /* return error */
978 }
979 if (handle->inited != 1) /* check handle initialization */
980 {
981 return 3; /* return error */
982 }
983
984 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* read config */
985 {
986 handle->debug_print("bmp280: read config failed.\n"); /* read config failed */
987
988 return 1; /* return error */
989 }
990 prev &= ~(7 << 5); /* clear settings */
991 prev |= standby_time << 5; /* set standby time */
992 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* write config */
993 {
994 handle->debug_print("bmp280: write config failed.\n"); /* write config failed */
995
996 return 1; /* return error */
997 }
998
999 return 0; /* success return 0 */
1000}
1001
1014{
1015 uint8_t prev;
1016
1017 if (handle == NULL) /* check handle */
1018 {
1019 return 2; /* return error */
1020 }
1021 if (handle->inited != 1) /* check handle initialization */
1022 {
1023 return 3; /* return error */
1024 }
1025
1026 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* read config */
1027 {
1028 handle->debug_print("bmp280: read config failed.\n"); /* read config failed */
1029
1030 return 1; /* return error */
1031 }
1032 *standby_time = (bmp280_standby_time_t)((prev >> 5) & 0x7); /* get standby time */
1033
1034 return 0; /* success return 0 */
1035}
1036
1049{
1050 uint8_t prev;
1051
1052 if (handle == NULL) /* check handle */
1053 {
1054 return 2; /* return error */
1055 }
1056 if (handle->inited != 1) /* check handle initialization */
1057 {
1058 return 3; /* return error */
1059 }
1060
1061 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* read config */
1062 {
1063 handle->debug_print("bmp280: read config failed.\n"); /* read config failed */
1064
1065 return 1; /* return error */
1066 }
1067 prev &= ~(7 << 2); /* clear settings */
1068 prev |= (filter & 0x07) << 2; /* set filter */
1069 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* write config */
1070 {
1071 handle->debug_print("bmp280: write config failed.\n"); /* write config failed */
1072
1073 return 1; /* return error */
1074 }
1075
1076 return 0; /* success return 0 */
1077}
1078
1091{
1092 uint8_t prev;
1093
1094 if (handle == NULL) /* check handle */
1095 {
1096 return 2; /* return error */
1097 }
1098 if (handle->inited != 1) /* check handle initialization */
1099 {
1100 return 3; /* return error */
1101 }
1102
1103 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* read config */
1104 {
1105 handle->debug_print("bmp280: read config failed.\n"); /* read config failed */
1106
1107 return 1; /* return error */
1108 }
1109 *filter = (bmp280_filter_t)((prev >> 2) & 0x07); /* set filter */
1110
1111 return 0; /* success return 0 */
1112}
1113
1126{
1127 uint8_t prev;
1128
1129 if (handle == NULL) /* check handle */
1130 {
1131 return 2; /* return error */
1132 }
1133 if (handle->inited != 1) /* check handle initialization */
1134 {
1135 return 3; /* return error */
1136 }
1137
1138 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* read config */
1139 {
1140 handle->debug_print("bmp280: read config failed.\n"); /* read config failed */
1141
1142 return 1; /* return error */
1143 }
1144 prev &= ~(1 << 0); /* clear settings */
1145 prev |= spi << 0; /* set spi wire */
1146 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* write config */
1147 {
1148 handle->debug_print("bmp280: write config failed.\n"); /* write config failed */
1149
1150 return 1; /* return error */
1151 }
1152
1153 return 0; /* success return 0 */
1154}
1155
1168{
1169 uint8_t prev;
1170
1171 if (handle == NULL) /* check handle */
1172 {
1173 return 2; /* return error */
1174 }
1175 if (handle->inited != 1) /* check handle initialization */
1176 {
1177 return 3; /* return error */
1178 }
1179
1180 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* read config */
1181 {
1182 handle->debug_print("bmp280: read config failed.\n"); /* read config failed */
1183
1184 return 1; /* return error */
1185 }
1186 *spi = (bmp280_spi_wire_t)((prev >> 0) & 0x01); /* get spi */
1187
1188 return 0; /* success return 0 */
1189}
1190
1205uint8_t bmp280_read_pressure(bmp280_handle_t *handle, uint32_t *pressure_raw, float *pressure_pa)
1206{
1207 uint8_t res;
1208 uint8_t prev;
1209 uint32_t timeout;
1210 uint32_t temperature_raw;
1211 float temperature_c;
1212 uint8_t buf[6];
1213
1214 if (handle == NULL) /* check handle */
1215 {
1216 return 2; /* return error */
1217 }
1218 if (handle->inited != 1) /* check handle initialization */
1219 {
1220 return 3; /* return error */
1221 }
1222
1223 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1224 {
1225 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1226
1227 return 1; /* return error */
1228 }
1229 if ((prev & 0x3) == 3) /* normal mode */
1230 {
1231 res = a_bmp280_iic_spi_read(handle, BMP280_REG_PRESS_MSB, buf, 6); /* read temperature and pressure */
1232 if (res != 0)
1233 {
1234 handle->debug_print("bmp280: read failed.\n"); /* read failed */
1235
1236 return 1; /* return error */
1237 }
1238 temperature_raw = ((((uint32_t)(buf[3])) << 12) |
1239 (((uint32_t)(buf[4])) << 4) |
1240 ((uint32_t)buf[5] >> 4)); /* set temperature raw */
1241 res = a_bmp280_compensate_temperature(handle, temperature_raw, &temperature_c); /* compensate temperature */
1242 if (res != 0)
1243 {
1244 handle->debug_print("bmp280: compensate temperature failed.\n"); /* compensate temperature failed */
1245
1246 return 4; /* return error */
1247 }
1248 *pressure_raw = ((((int32_t)(buf[0])) << 12) |
1249 (((int32_t)(buf[1])) << 4) |
1250 (((int32_t)(buf[2])) >> 4)); /* set pressure raw */
1251 res = a_bmp280_compensate_pressure(handle, *pressure_raw, pressure_pa); /* compensate pressure */
1252 if (res != 0)
1253 {
1254 handle->debug_print("bmp280: compensate pressure failed.\n"); /* compensate pressure failed */
1255
1256 return 4; /* return error */
1257 }
1258 }
1259 else /* forced mode */
1260 {
1261 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1262 {
1263 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1264
1265 return 1; /* return error */
1266 }
1267 prev &= ~(3 << 0); /* clear settings */
1268 prev |= 0x01 << 0; /* set forced mode */
1269 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
1270 {
1271 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
1272
1273 return 1; /* return error */
1274 }
1275 timeout = 10 * 1000; /* set timeout */
1276 while (timeout != 0) /* check timeout */
1277 {
1278 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1279 {
1280 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1281
1282 return 1; /* return error */
1283 }
1284 if ((prev & 0x03) == 0) /* if finished */
1285 {
1286 break; /* break */
1287 }
1288 handle->delay_ms(1); /* delay 1ms */
1289 timeout--; /* timeout-- */
1290 }
1291 if (timeout == 0) /* check timeout */
1292 {
1293 handle->debug_print("bmp280: read timeout.\n"); /* read timeout */
1294
1295 return 5; /* return error */
1296 }
1297 res = a_bmp280_iic_spi_read(handle, BMP280_REG_PRESS_MSB, buf, 6); /* read temperature and pressure */
1298 if (res != 0)
1299 {
1300 handle->debug_print("bmp280: read failed.\n"); /* read failed */
1301
1302 return 1; /* return error */
1303 }
1304 temperature_raw = ((((uint32_t)(buf[3])) << 12) |
1305 (((uint32_t)(buf[4])) << 4) |
1306 ((uint32_t)buf[5] >> 4)); /* set temperature raw */
1307 res = a_bmp280_compensate_temperature(handle, temperature_raw, &temperature_c); /* compensate temperature */
1308 if (res != 0)
1309 {
1310 handle->debug_print("bmp280: compensate temperature failed.\n"); /* compensate temperature failed */
1311
1312 return 4; /* return error */
1313 }
1314 *pressure_raw = ((((int32_t)(buf[0])) << 12) |
1315 (((int32_t)(buf[1])) << 4) |
1316 (((int32_t)(buf[2])) >> 4)); /* set pressure raw */
1317 res = a_bmp280_compensate_pressure(handle, *pressure_raw, pressure_pa); /* compensate pressure */
1318 if (res != 0)
1319 {
1320 handle->debug_print("bmp280: compensate pressure failed.\n"); /* compensate pressure failed */
1321
1322 return 4; /* return error */
1323 }
1324 }
1325
1326 return 0; /* success return 0 */
1327}
1328
1343uint8_t bmp280_read_temperature(bmp280_handle_t *handle, uint32_t *temperature_raw, float *temperature_c)
1344{
1345 uint8_t res;
1346 uint8_t prev;
1347 uint32_t timeout;
1348 uint8_t buf[6];
1349
1350 if (handle == NULL) /* check handle */
1351 {
1352 return 2; /* return error */
1353 }
1354 if (handle->inited != 1) /* check handle initialization */
1355 {
1356 return 3; /* return error */
1357 }
1358
1359 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1360 {
1361 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1362
1363 return 1; /* return error */
1364 }
1365 if ((prev & 0x3) == 3) /* normal mode */
1366 {
1367 res = a_bmp280_iic_spi_read(handle, BMP280_REG_PRESS_MSB, buf, 6); /* read temperature and pressure */
1368 if (res != 0)
1369 {
1370 handle->debug_print("bmp280: read failed.\n"); /* read failed */
1371
1372 return 1; /* return error */
1373 }
1374 *temperature_raw = ((((uint32_t)(buf[3])) << 12) |
1375 (((uint32_t)(buf[4])) << 4) |
1376 ((uint32_t)buf[5] >> 4)); /* set temperature raw */
1377 res = a_bmp280_compensate_temperature(handle, *temperature_raw, temperature_c); /* compensate temperature */
1378 if (res != 0)
1379 {
1380 handle->debug_print("bmp280: compensate temperature failed.\n"); /* compensate temperature failed */
1381
1382 return 4; /* return error */
1383 }
1384 }
1385 else /* forced mode */
1386 {
1387 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1388 {
1389 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1390
1391 return 1; /* return error */
1392 }
1393 prev &= ~(3 << 0); /* clear settings */
1394 prev |= 0x01 << 0; /* set forced mode */
1395 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
1396 {
1397 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
1398
1399 return 1; /* return error */
1400 }
1401 timeout = 10 * 1000; /* set timeout */
1402 while (timeout != 0) /* check timeout */
1403 {
1404 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1405 {
1406 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1407
1408 return 1; /* return error */
1409 }
1410 if ((prev & 0x03) == 0) /* if finished */
1411 {
1412 break; /* break */
1413 }
1414 handle->delay_ms(1); /* delay 1ms */
1415 timeout--; /* timeout-- */
1416 }
1417 if (timeout == 0) /* check timeout */
1418 {
1419 handle->debug_print("bmp280: read timeout.\n"); /* read timeout */
1420
1421 return 5; /* return error */
1422 }
1423 res = a_bmp280_iic_spi_read(handle, BMP280_REG_PRESS_MSB, buf, 6); /* read temperature and pressure */
1424 if (res != 0)
1425 {
1426 handle->debug_print("bmp280: read failed.\n"); /* read failed */
1427
1428 return 1; /* return error */
1429 }
1430 *temperature_raw = ((((uint32_t)(buf[3])) << 12) |
1431 (((uint32_t)(buf[4])) << 4) |
1432 ((uint32_t)buf[5] >> 4)); /* set temperature raw */
1433 res = a_bmp280_compensate_temperature(handle, *temperature_raw, temperature_c); /* compensate temperature */
1434 if (res != 0)
1435 {
1436 handle->debug_print("bmp280: compensate temperature failed.\n"); /* compensate temperature failed */
1437
1438 return 4; /* return error */
1439 }
1440 }
1441
1442 return 0; /* success return 0 */
1443}
1444
1461uint8_t bmp280_read_temperature_pressure(bmp280_handle_t *handle, uint32_t *temperature_raw, float *temperature_c,
1462 uint32_t *pressure_raw, float *pressure_pa)
1463{
1464 uint8_t res;
1465 uint8_t prev;
1466 uint32_t timeout;
1467 uint8_t buf[6];
1468
1469 if (handle == NULL) /* check handle */
1470 {
1471 return 2; /* return error */
1472 }
1473 if (handle->inited != 1) /* check handle initialization */
1474 {
1475 return 3; /* return error */
1476 }
1477
1478 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1479 {
1480 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1481
1482 return 1; /* return error */
1483 }
1484 if ((prev & 0x3) == 3) /* normal mode */
1485 {
1486 res = a_bmp280_iic_spi_read(handle, BMP280_REG_PRESS_MSB, buf, 6); /* read temperature and pressure */
1487 if (res != 0)
1488 {
1489 handle->debug_print("bmp280: read failed.\n"); /* read failed */
1490
1491 return 1; /* return error */
1492 }
1493 *temperature_raw = ((((uint32_t)(buf[3])) << 12) |
1494 (((uint32_t)(buf[4])) << 4) |
1495 ((uint32_t)buf[5] >> 4)); /* set temperature raw */
1496 res = a_bmp280_compensate_temperature(handle, *temperature_raw, temperature_c); /* compensate temperature */
1497 if (res != 0)
1498 {
1499 handle->debug_print("bmp280: compensate temperature failed.\n"); /* compensate temperature failed */
1500
1501 return 4; /* return error */
1502 }
1503 *pressure_raw = ((((int32_t)(buf[0])) << 12) |
1504 (((int32_t)(buf[1])) << 4) |
1505 (((int32_t)(buf[2])) >> 4)); /* set pressure raw */
1506 res = a_bmp280_compensate_pressure(handle, *pressure_raw, pressure_pa); /* compensate pressure */
1507 if (res != 0)
1508 {
1509 handle->debug_print("bmp280: compensate pressure failed.\n"); /* compensate pressure failed */
1510
1511 return 4; /* return error */
1512 }
1513 }
1514 else /* forced mode */
1515 {
1516 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1517 {
1518 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1519
1520 return 1; /* return error */
1521 }
1522 prev &= ~(3 << 0); /* clear settings */
1523 prev |= 0x01 << 0; /* set forced mode */
1524 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
1525 {
1526 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
1527
1528 return 1; /* return error */
1529 }
1530 timeout = 10 * 1000; /* set timeout */
1531 while (timeout != 0) /* check timeout */
1532 {
1533 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1534 {
1535 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1536
1537 return 1; /* return error */
1538 }
1539 if ((prev & 0x03) == 0) /* if finished */
1540 {
1541 break; /* break */
1542 }
1543 handle->delay_ms(1); /* delay 1ms */
1544 timeout--; /* timeout-- */
1545 }
1546 if (timeout == 0) /* check timeout */
1547 {
1548 handle->debug_print("bmp280: read timeout.\n"); /* read timeout */
1549
1550 return 5; /* return error */
1551 }
1552 res = a_bmp280_iic_spi_read(handle, BMP280_REG_PRESS_MSB, buf, 6); /* read temperature and pressure */
1553 if (res != 0)
1554 {
1555 handle->debug_print("bmp280: read failed.\n"); /* read failed */
1556
1557 return 1; /* return error */
1558 }
1559 *temperature_raw = ((((uint32_t)(buf[3])) << 12) |
1560 (((uint32_t)(buf[4])) << 4) |
1561 ((uint32_t)buf[5] >> 4)); /* set temperature raw */
1562 res = a_bmp280_compensate_temperature(handle, *temperature_raw, temperature_c); /* compensate temperature */
1563 if (res != 0)
1564 {
1565 handle->debug_print("bmp280: compensate temperature failed.\n"); /* compensate temperature failed */
1566
1567 return 4; /* return error */
1568 }
1569 *pressure_raw = ((((int32_t)(buf[0])) << 12) |
1570 (((int32_t)(buf[1])) << 4) |
1571 (((int32_t)(buf[2])) >> 4)); /* set pressure raw */
1572 res = a_bmp280_compensate_pressure(handle, *pressure_raw, pressure_pa); /* compensate pressure */
1573 if (res != 0)
1574 {
1575 handle->debug_print("bmp280: compensate pressure failed.\n"); /* compensate pressure failed */
1576
1577 return 4; /* return error */
1578 }
1579 }
1580
1581 return 0; /* success return 0 */
1582}
1583
1596uint8_t bmp280_set_reg(bmp280_handle_t *handle, uint8_t reg, uint8_t value)
1597{
1598 if (handle == NULL) /* check handle */
1599 {
1600 return 2; /* return error */
1601 }
1602 if (handle->inited != 1) /* check handle initialization */
1603 {
1604 return 3; /* return error */
1605 }
1606
1607 return a_bmp280_iic_spi_write(handle, reg, &value, 1); /* write register */
1608}
1609
1622uint8_t bmp280_get_reg(bmp280_handle_t *handle, uint8_t reg, uint8_t *value)
1623{
1624 if (handle == NULL) /* check handle */
1625 {
1626 return 2; /* return error */
1627 }
1628 if (handle->inited != 1) /* check handle initialization */
1629 {
1630 return 3; /* return error */
1631 }
1632
1633 return a_bmp280_iic_spi_read(handle, reg, value, 1); /* read register */
1634}
1635
1645{
1646 if (info == NULL) /* check handle */
1647 {
1648 return 2; /* return error */
1649 }
1650
1651 memset(info, 0, sizeof(bmp280_info_t)); /* initialize bmp280 info structure */
1652 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1653 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1654 strncpy(info->interface, "IIC SPI", 8); /* copy interface name */
1655 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1656 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1657 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1658 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1659 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1660 info->driver_version = DRIVER_VERSION; /* set driver version */
1661
1662 return 0; /* success return 0 */
1663}
#define BMP280_REG_NVM_PAR_P2_L
#define BMP280_REG_NVM_PAR_P6_L
#define BMP280_REG_NVM_PAR_P3_L
#define MAX_CURRENT
#define BMP280_REG_RESET
#define BMP280_REG_NVM_PAR_P4_L
#define BMP280_REG_ID
#define BMP280_REG_CONFIG
#define BMP280_REG_NVM_PAR_P5_L
#define BMP280_REG_STATUS
#define BMP280_REG_NVM_PAR_P8_L
#define SUPPLY_VOLTAGE_MAX
#define BMP280_REG_NVM_PAR_T2_L
#define BMP280_REG_NVM_PAR_P1_L
#define TEMPERATURE_MAX
#define BMP280_REG_NVM_PAR_P9_L
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define BMP280_REG_NVM_PAR_T3_L
#define BMP280_REG_CTRL_MEAS
#define BMP280_REG_NVM_PAR_P7_L
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define BMP280_REG_NVM_PAR_T1_L
chip register definition
#define BMP280_REG_PRESS_MSB
driver bmp280 header file
uint8_t bmp280_get_temperature_oversampling(bmp280_handle_t *handle, bmp280_oversampling_t *oversampling)
get temperature oversampling
uint8_t bmp280_soft_reset(bmp280_handle_t *handle)
soft reset
uint8_t bmp280_set_filter(bmp280_handle_t *handle, bmp280_filter_t filter)
set filter
uint8_t bmp280_get_pressure_oversampling(bmp280_handle_t *handle, bmp280_oversampling_t *oversampling)
get pressure oversampling
bmp280_spi_wire_t
bmp280 spi wire enumeration definition
uint8_t bmp280_info(bmp280_info_t *info)
get chip's information
uint8_t bmp280_set_temperature_oversampling(bmp280_handle_t *handle, bmp280_oversampling_t oversampling)
set temperature oversampling
uint8_t bmp280_set_mode(bmp280_handle_t *handle, bmp280_mode_t mode)
set mode
uint8_t bmp280_get_mode(bmp280_handle_t *handle, bmp280_mode_t *mode)
get mode
uint8_t bmp280_read_temperature_pressure(bmp280_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa)
read the temperature and pressure data
bmp280_filter_t
bmp280 filter enumeration definition
uint8_t bmp280_deinit(bmp280_handle_t *handle)
close the chip
bmp280_mode_t
bmp280 mode enumeration definition
uint8_t bmp280_get_filter(bmp280_handle_t *handle, bmp280_filter_t *filter)
get filter
uint8_t bmp280_get_addr_pin(bmp280_handle_t *handle, bmp280_address_t *addr_pin)
get the iic address pin
bmp280_interface_t
bmp280 interface enumeration definition
uint8_t bmp280_set_interface(bmp280_handle_t *handle, bmp280_interface_t interface)
set the interface
uint8_t bmp280_get_standby_time(bmp280_handle_t *handle, bmp280_standby_time_t *standby_time)
get standby time
uint8_t bmp280_set_spi_wire(bmp280_handle_t *handle, bmp280_spi_wire_t spi)
set spi wire
uint8_t bmp280_read_pressure(bmp280_handle_t *handle, uint32_t *pressure_raw, float *pressure_pa)
read the pressure data
uint8_t bmp280_get_spi_wire(bmp280_handle_t *handle, bmp280_spi_wire_t *spi)
get spi wire
uint8_t bmp280_set_pressure_oversampling(bmp280_handle_t *handle, bmp280_oversampling_t oversampling)
set pressure oversampling
uint8_t bmp280_set_addr_pin(bmp280_handle_t *handle, bmp280_address_t addr_pin)
set the iic address pin
bmp280_address_t
bmp280 address enumeration definition
struct bmp280_info_s bmp280_info_t
bmp280 information structure definition
uint8_t bmp280_get_interface(bmp280_handle_t *handle, bmp280_interface_t *interface)
get the interface
uint8_t bmp280_set_standby_time(bmp280_handle_t *handle, bmp280_standby_time_t standby_time)
set standby time
bmp280_oversampling_t
bmp280 oversampling enumeration definition
uint8_t bmp280_get_status(bmp280_handle_t *handle, uint8_t *status)
get status
uint8_t bmp280_init(bmp280_handle_t *handle)
initialize the chip
struct bmp280_handle_s bmp280_handle_t
bmp280 handle structure definition
uint8_t bmp280_read_temperature(bmp280_handle_t *handle, uint32_t *temperature_raw, float *temperature_c)
read the temperature data
bmp280_standby_time_t
bmp280 standby time enumeration definition
@ BMP280_INTERFACE_IIC
uint8_t bmp280_set_reg(bmp280_handle_t *handle, uint8_t reg, uint8_t value)
set the chip register
uint8_t bmp280_get_reg(bmp280_handle_t *handle, uint8_t reg, uint8_t *value)
get the chip register
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* spi_deinit)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]