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 (void)handle->iic_deinit(); /* iic deinit */
543
544 return 4; /* return error */
545 }
546 if (id != 0x58) /* check id */
547 {
548 handle->debug_print("bmp280: id is error.\n"); /* id is error */
549 (void)handle->iic_deinit(); /* iic deinit */
550
551 return 4; /* return error */
552 }
553 reg = 0xB6; /* set the reset value */
554 if (a_bmp280_iic_spi_write(handle, BMP280_REG_RESET, &reg, 1) != 0) /* reset the chip */
555 {
556 handle->debug_print("bmp280: reset failed.\n"); /* reset failed */
557 (void)handle->iic_deinit(); /* iic deinit */
558
559 return 5; /* return error */
560 }
561 handle->delay_ms(5); /* delay 5ms */
562 if (a_bmp280_get_nvm_calibration(handle) != 0) /* get nvm calibration */
563 {
564 (void)handle->iic_deinit(); /* iic deinit */
565
566 return 6; /* return error */
567 }
568 handle->inited = 1; /* flag finish initialization */
569
570 return 0; /* success return 0 */
571}
572
585{
586 uint8_t prev;
587
588 if (handle == NULL) /* check handle */
589 {
590 return 2; /* return error */
591 }
592 if (handle->inited != 1) /* check handle initialization */
593 {
594 return 3; /* return error */
595 }
596
597 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
598 {
599 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
600
601 return 4; /* return error */
602 }
603 prev &= ~(3 << 0); /* clear settings */
604 prev |= 0 << 0; /* set sleep mode */
605 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
606 {
607 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
608
609 return 4; /* return error */
610 }
611 if (handle->iic_spi == BMP280_INTERFACE_IIC) /* iic interface */
612 {
613 if (handle->iic_deinit() != 0) /* iic deinit */
614 {
615 handle->debug_print("bmp280: iic deinit failed.\n"); /* iic deinit failed */
616
617 return 1; /* return error */
618 }
619 }
620 else /* spi interface */
621 {
622 if (handle->spi_deinit() != 0) /* spi deinit */
623 {
624 handle->debug_print("bmp280: spi deinit failed.\n"); /* spi deinit failed */
625
626 return 1; /* return error */
627 }
628 }
629 handle->inited = 0; /* flag close */
630
631 return 0; /* success return 0 */
632}
633
645{
646 uint8_t reg;
647
648 if (handle == NULL) /* check handle */
649 {
650 return 2; /* return error */
651 }
652 if (handle->inited != 1) /* check handle initialization */
653 {
654 return 3; /* return error */
655 }
656
657 reg = 0xB6; /* set the reset value */
658 if (a_bmp280_iic_spi_write(handle, BMP280_REG_RESET, &reg, 1) != 0) /* reset the chip */
659 {
660 handle->debug_print("bmp280: reset failed.\n"); /* reset failed */
661
662 return 1; /* return error */
663 }
664 handle->delay_ms(5); /* delay 5ms */
665
666 return 0; /* success return 0 */
667}
668
680uint8_t bmp280_get_status(bmp280_handle_t *handle, uint8_t *status)
681{
682 if (handle == NULL) /* check handle */
683 {
684 return 2; /* return error */
685 }
686 if (handle->inited != 1) /* check handle initialization */
687 {
688 return 3; /* return error */
689 }
690
691 if (a_bmp280_iic_spi_read(handle, BMP280_REG_STATUS, status, 1) != 0) /* read status */
692 {
693 handle->debug_print("bmp280: read status failed.\n"); /* read status failed */
694
695 return 1; /* return error */
696 }
697
698 return 0; /* success return 0 */
699}
700
713{
714 uint8_t prev;
715
716 if (handle == NULL) /* check handle */
717 {
718 return 2; /* return error */
719 }
720 if (handle->inited != 1) /* check handle initialization */
721 {
722 return 3; /* return error */
723 }
724
725 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
726 {
727 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
728
729 return 1; /* return error */
730 }
731 prev &= ~(7 << 5); /* clear settings */
732 prev |= oversampling << 5; /* set oversampling */
733 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
734 {
735 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
736
737 return 1; /* return error */
738 }
739
740 return 0; /* success return 0 */
741}
742
755{
756 uint8_t prev;
757
758 if (handle == NULL) /* check handle */
759 {
760 return 2; /* return error */
761 }
762 if (handle->inited != 1) /* check handle initialization */
763 {
764 return 3; /* return error */
765 }
766
767 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
768 {
769 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
770
771 return 1; /* return error */
772 }
773 *oversampling = (bmp280_oversampling_t)((prev >> 5) & 0x7); /* set oversampling */
774
775 return 0; /* success return 0 */
776}
777
790{
791 uint8_t prev;
792
793 if (handle == NULL) /* check handle */
794 {
795 return 2; /* return error */
796 }
797 if (handle->inited != 1) /* check handle initialization */
798 {
799 return 3; /* return error */
800 }
801
802 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
803 {
804 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
805
806 return 1; /* return error */
807 }
808 prev &= ~(7 << 2); /* clear settings */
809 prev |= oversampling << 2; /* set oversampling */
810 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
811 {
812 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
813
814 return 1; /* return error */
815 }
816
817 return 0; /* success return 0 */
818}
819
832{
833 uint8_t prev;
834
835 if (handle == NULL) /* check handle */
836 {
837 return 2; /* return error */
838 }
839 if (handle->inited != 1) /* check handle initialization */
840 {
841 return 3; /* return error */
842 }
843
844 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
845 {
846 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
847
848 return 1; /* return error */
849 }
850 *oversampling = (bmp280_oversampling_t)((prev >> 2) & 0x7); /* set oversampling */
851
852 return 0; /* success return 0 */
853}
854
867{
868 uint8_t prev;
869
870 if (handle == NULL) /* check handle */
871 {
872 return 2; /* return error */
873 }
874 if (handle->inited != 1) /* check handle initialization */
875 {
876 return 3; /* return error */
877 }
878
879 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
880 {
881 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
882
883 return 1; /* return error */
884 }
885 prev &= ~(3 << 0); /* clear settings */
886 prev |= mode << 0; /* set mode */
887 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
888 {
889 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
890
891 return 1; /* return error */
892 }
893
894 return 0; /* success return 0 */
895}
896
909{
910 uint8_t prev;
911
912 if (handle == NULL) /* check handle */
913 {
914 return 2; /* return error */
915 }
916 if (handle->inited != 1) /* check handle initialization */
917 {
918 return 3; /* return error */
919 }
920
921 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
922 {
923 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
924
925 return 1; /* return error */
926 }
927 *mode = (bmp280_mode_t)((prev >> 0) & 0x3); /* set mode */
928
929 return 0; /* success return 0 */
930}
931
944{
945 uint8_t prev;
946
947 if (handle == NULL) /* check handle */
948 {
949 return 2; /* return error */
950 }
951 if (handle->inited != 1) /* check handle initialization */
952 {
953 return 3; /* return error */
954 }
955
956 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* read config */
957 {
958 handle->debug_print("bmp280: read config failed.\n"); /* read config failed */
959
960 return 1; /* return error */
961 }
962 prev &= ~(7 << 5); /* clear settings */
963 prev |= standby_time << 5; /* set standby time */
964 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* write config */
965 {
966 handle->debug_print("bmp280: write config failed.\n"); /* write config failed */
967
968 return 1; /* return error */
969 }
970
971 return 0; /* success return 0 */
972}
973
986{
987 uint8_t prev;
988
989 if (handle == NULL) /* check handle */
990 {
991 return 2; /* return error */
992 }
993 if (handle->inited != 1) /* check handle initialization */
994 {
995 return 3; /* return error */
996 }
997
998 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* read config */
999 {
1000 handle->debug_print("bmp280: read config failed.\n"); /* read config failed */
1001
1002 return 1; /* return error */
1003 }
1004 *standby_time = (bmp280_standby_time_t)((prev >> 5) & 0x7); /* get standby time */
1005
1006 return 0; /* success return 0 */
1007}
1008
1021{
1022 uint8_t prev;
1023
1024 if (handle == NULL) /* check handle */
1025 {
1026 return 2; /* return error */
1027 }
1028 if (handle->inited != 1) /* check handle initialization */
1029 {
1030 return 3; /* return error */
1031 }
1032
1033 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* read config */
1034 {
1035 handle->debug_print("bmp280: read config failed.\n"); /* read config failed */
1036
1037 return 1; /* return error */
1038 }
1039 prev &= ~(7 << 2); /* clear settings */
1040 prev |= (filter & 0x07) << 2; /* set filter */
1041 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* write config */
1042 {
1043 handle->debug_print("bmp280: write config failed.\n"); /* write config failed */
1044
1045 return 1; /* return error */
1046 }
1047
1048 return 0; /* success return 0 */
1049}
1050
1063{
1064 uint8_t prev;
1065
1066 if (handle == NULL) /* check handle */
1067 {
1068 return 2; /* return error */
1069 }
1070 if (handle->inited != 1) /* check handle initialization */
1071 {
1072 return 3; /* return error */
1073 }
1074
1075 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* read config */
1076 {
1077 handle->debug_print("bmp280: read config failed.\n"); /* read config failed */
1078
1079 return 1; /* return error */
1080 }
1081 *filter = (bmp280_filter_t)((prev >> 2) & 0x07); /* set filter */
1082
1083 return 0; /* success return 0 */
1084}
1085
1098{
1099 uint8_t prev;
1100
1101 if (handle == NULL) /* check handle */
1102 {
1103 return 2; /* return error */
1104 }
1105 if (handle->inited != 1) /* check handle initialization */
1106 {
1107 return 3; /* return error */
1108 }
1109
1110 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* read config */
1111 {
1112 handle->debug_print("bmp280: read config failed.\n"); /* read config failed */
1113
1114 return 1; /* return error */
1115 }
1116 prev &= ~(1 << 0); /* clear settings */
1117 prev |= spi << 0; /* set spi wire */
1118 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* write config */
1119 {
1120 handle->debug_print("bmp280: write config failed.\n"); /* write config failed */
1121
1122 return 1; /* return error */
1123 }
1124
1125 return 0; /* success return 0 */
1126}
1127
1140{
1141 uint8_t prev;
1142
1143 if (handle == NULL) /* check handle */
1144 {
1145 return 2; /* return error */
1146 }
1147 if (handle->inited != 1) /* check handle initialization */
1148 {
1149 return 3; /* return error */
1150 }
1151
1152 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CONFIG, &prev, 1) != 0) /* read config */
1153 {
1154 handle->debug_print("bmp280: read config failed.\n"); /* read config failed */
1155
1156 return 1; /* return error */
1157 }
1158 *spi = (bmp280_spi_wire_t)((prev >> 0) & 0x01); /* get spi */
1159
1160 return 0; /* success return 0 */
1161}
1162
1177uint8_t bmp280_read_pressure(bmp280_handle_t *handle, uint32_t *pressure_raw, float *pressure_pa)
1178{
1179 uint8_t res;
1180 uint8_t prev;
1181 uint32_t timeout;
1182 uint32_t temperature_raw;
1183 float temperature_c;
1184 uint8_t buf[6];
1185
1186 if (handle == NULL) /* check handle */
1187 {
1188 return 2; /* return error */
1189 }
1190 if (handle->inited != 1) /* check handle initialization */
1191 {
1192 return 3; /* return error */
1193 }
1194
1195 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1196 {
1197 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1198
1199 return 1; /* return error */
1200 }
1201 if ((prev & 0x3) == 3) /* normal mode */
1202 {
1203 res = a_bmp280_iic_spi_read(handle, BMP280_REG_PRESS_MSB, buf, 6); /* read temperature and pressure */
1204 if (res != 0)
1205 {
1206 handle->debug_print("bmp280: read failed.\n"); /* read failed */
1207
1208 return 1; /* return error */
1209 }
1210 temperature_raw = ((((uint32_t)(buf[3])) << 12) |
1211 (((uint32_t)(buf[4])) << 4) |
1212 ((uint32_t)buf[5] >> 4)); /* set temperature raw */
1213 res = a_bmp280_compensate_temperature(handle, temperature_raw, &temperature_c); /* compensate temperature */
1214 if (res != 0)
1215 {
1216 handle->debug_print("bmp280: compensate temperature failed.\n"); /* compensate temperature failed */
1217
1218 return 4; /* return error */
1219 }
1220 *pressure_raw = ((((int32_t)(buf[0])) << 12) |
1221 (((int32_t)(buf[1])) << 4) |
1222 (((int32_t)(buf[2])) >> 4)); /* set pressure raw */
1223 res = a_bmp280_compensate_pressure(handle, *pressure_raw, pressure_pa); /* compensate pressure */
1224 if (res != 0)
1225 {
1226 handle->debug_print("bmp280: compensate pressure failed.\n"); /* compensate pressure failed */
1227
1228 return 4; /* return error */
1229 }
1230 }
1231 else /* forced mode */
1232 {
1233 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1234 {
1235 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1236
1237 return 1; /* return error */
1238 }
1239 prev &= ~(3 << 0); /* clear settings */
1240 prev |= 0x01 << 0; /* set forced mode */
1241 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
1242 {
1243 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
1244
1245 return 1; /* return error */
1246 }
1247 timeout = 10 * 1000; /* set timeout */
1248 while (timeout != 0) /* check timeout */
1249 {
1250 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1251 {
1252 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1253
1254 return 1; /* return error */
1255 }
1256 if ((prev & 0x03) == 0) /* if finished */
1257 {
1258 break; /* break */
1259 }
1260 handle->delay_ms(1); /* delay 1ms */
1261 timeout--; /* timeout-- */
1262 }
1263 if (timeout == 0) /* check timeout */
1264 {
1265 handle->debug_print("bmp280: read timeout.\n"); /* read timeout */
1266
1267 return 5; /* return error */
1268 }
1269 res = a_bmp280_iic_spi_read(handle, BMP280_REG_PRESS_MSB, buf, 6); /* read temperature and pressure */
1270 if (res != 0)
1271 {
1272 handle->debug_print("bmp280: read failed.\n"); /* read failed */
1273
1274 return 1; /* return error */
1275 }
1276 temperature_raw = ((((uint32_t)(buf[3])) << 12) |
1277 (((uint32_t)(buf[4])) << 4) |
1278 ((uint32_t)buf[5] >> 4)); /* set temperature raw */
1279 res = a_bmp280_compensate_temperature(handle, temperature_raw, &temperature_c); /* compensate temperature */
1280 if (res != 0)
1281 {
1282 handle->debug_print("bmp280: compensate temperature failed.\n"); /* compensate temperature failed */
1283
1284 return 4; /* return error */
1285 }
1286 *pressure_raw = ((((int32_t)(buf[0])) << 12) |
1287 (((int32_t)(buf[1])) << 4) |
1288 (((int32_t)(buf[2])) >> 4)); /* set pressure raw */
1289 res = a_bmp280_compensate_pressure(handle, *pressure_raw, pressure_pa); /* compensate pressure */
1290 if (res != 0)
1291 {
1292 handle->debug_print("bmp280: compensate pressure failed.\n"); /* compensate pressure failed */
1293
1294 return 4; /* return error */
1295 }
1296 }
1297
1298 return 0; /* success return 0 */
1299}
1300
1315uint8_t bmp280_read_temperature(bmp280_handle_t *handle, uint32_t *temperature_raw, float *temperature_c)
1316{
1317 uint8_t res;
1318 uint8_t prev;
1319 uint32_t timeout;
1320 uint8_t buf[6];
1321
1322 if (handle == NULL) /* check handle */
1323 {
1324 return 2; /* return error */
1325 }
1326 if (handle->inited != 1) /* check handle initialization */
1327 {
1328 return 3; /* return error */
1329 }
1330
1331 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1332 {
1333 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1334
1335 return 1; /* return error */
1336 }
1337 if ((prev & 0x3) == 3) /* normal mode */
1338 {
1339 res = a_bmp280_iic_spi_read(handle, BMP280_REG_PRESS_MSB, buf, 6); /* read temperature and pressure */
1340 if (res != 0)
1341 {
1342 handle->debug_print("bmp280: read failed.\n"); /* read failed */
1343
1344 return 1; /* return error */
1345 }
1346 *temperature_raw = ((((uint32_t)(buf[3])) << 12) |
1347 (((uint32_t)(buf[4])) << 4) |
1348 ((uint32_t)buf[5] >> 4)); /* set temperature raw */
1349 res = a_bmp280_compensate_temperature(handle, *temperature_raw, temperature_c); /* compensate temperature */
1350 if (res != 0)
1351 {
1352 handle->debug_print("bmp280: compensate temperature failed.\n"); /* compensate temperature failed */
1353
1354 return 4; /* return error */
1355 }
1356 }
1357 else /* forced mode */
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 prev &= ~(3 << 0); /* clear settings */
1366 prev |= 0x01 << 0; /* set forced mode */
1367 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
1368 {
1369 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
1370
1371 return 1; /* return error */
1372 }
1373 timeout = 10 * 1000; /* set timeout */
1374 while (timeout != 0) /* check timeout */
1375 {
1376 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1377 {
1378 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1379
1380 return 1; /* return error */
1381 }
1382 if ((prev & 0x03) == 0) /* if finished */
1383 {
1384 break; /* break */
1385 }
1386 handle->delay_ms(1); /* delay 1ms */
1387 timeout--; /* timeout-- */
1388 }
1389 if (timeout == 0) /* check timeout */
1390 {
1391 handle->debug_print("bmp280: read timeout.\n"); /* read timeout */
1392
1393 return 5; /* return error */
1394 }
1395 res = a_bmp280_iic_spi_read(handle, BMP280_REG_PRESS_MSB, buf, 6); /* read temperature and pressure */
1396 if (res != 0)
1397 {
1398 handle->debug_print("bmp280: read failed.\n"); /* read failed */
1399
1400 return 1; /* return error */
1401 }
1402 *temperature_raw = ((((uint32_t)(buf[3])) << 12) |
1403 (((uint32_t)(buf[4])) << 4) |
1404 ((uint32_t)buf[5] >> 4)); /* set temperature raw */
1405 res = a_bmp280_compensate_temperature(handle, *temperature_raw, temperature_c); /* compensate temperature */
1406 if (res != 0)
1407 {
1408 handle->debug_print("bmp280: compensate temperature failed.\n"); /* compensate temperature failed */
1409
1410 return 4; /* return error */
1411 }
1412 }
1413
1414 return 0; /* success return 0 */
1415}
1416
1433uint8_t bmp280_read_temperature_pressure(bmp280_handle_t *handle, uint32_t *temperature_raw, float *temperature_c,
1434 uint32_t *pressure_raw, float *pressure_pa)
1435{
1436 uint8_t res;
1437 uint8_t prev;
1438 uint32_t timeout;
1439 uint8_t buf[6];
1440
1441 if (handle == NULL) /* check handle */
1442 {
1443 return 2; /* return error */
1444 }
1445 if (handle->inited != 1) /* check handle initialization */
1446 {
1447 return 3; /* return error */
1448 }
1449
1450 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1451 {
1452 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1453
1454 return 1; /* return error */
1455 }
1456 if ((prev & 0x3) == 3) /* normal mode */
1457 {
1458 res = a_bmp280_iic_spi_read(handle, BMP280_REG_PRESS_MSB, buf, 6); /* read temperature and pressure */
1459 if (res != 0)
1460 {
1461 handle->debug_print("bmp280: read failed.\n"); /* read failed */
1462
1463 return 1; /* return error */
1464 }
1465 *temperature_raw = ((((uint32_t)(buf[3])) << 12) |
1466 (((uint32_t)(buf[4])) << 4) |
1467 ((uint32_t)buf[5] >> 4)); /* set temperature raw */
1468 res = a_bmp280_compensate_temperature(handle, *temperature_raw, temperature_c); /* compensate temperature */
1469 if (res != 0)
1470 {
1471 handle->debug_print("bmp280: compensate temperature failed.\n"); /* compensate temperature failed */
1472
1473 return 4; /* return error */
1474 }
1475 *pressure_raw = ((((int32_t)(buf[0])) << 12) |
1476 (((int32_t)(buf[1])) << 4) |
1477 (((int32_t)(buf[2])) >> 4)); /* set pressure raw */
1478 res = a_bmp280_compensate_pressure(handle, *pressure_raw, pressure_pa); /* compensate pressure */
1479 if (res != 0)
1480 {
1481 handle->debug_print("bmp280: compensate pressure failed.\n"); /* compensate pressure failed */
1482
1483 return 4; /* return error */
1484 }
1485 }
1486 else /* forced mode */
1487 {
1488 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1489 {
1490 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1491
1492 return 1; /* return error */
1493 }
1494 prev &= ~(3 << 0); /* clear settings */
1495 prev |= 0x01 << 0; /* set forced mode */
1496 if (a_bmp280_iic_spi_write(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* write ctrl meas */
1497 {
1498 handle->debug_print("bmp280: write ctrl meas failed.\n"); /* write ctrl meas failed */
1499
1500 return 1; /* return error */
1501 }
1502 timeout = 10 * 1000; /* set timeout */
1503 while (timeout != 0) /* check timeout */
1504 {
1505 if (a_bmp280_iic_spi_read(handle, BMP280_REG_CTRL_MEAS, &prev, 1) != 0) /* read ctrl meas */
1506 {
1507 handle->debug_print("bmp280: read ctrl meas failed.\n"); /* read ctrl meas failed */
1508
1509 return 1; /* return error */
1510 }
1511 if ((prev & 0x03) == 0) /* if finished */
1512 {
1513 break; /* break */
1514 }
1515 handle->delay_ms(1); /* delay 1ms */
1516 timeout--; /* timeout-- */
1517 }
1518 if (timeout == 0) /* check timeout */
1519 {
1520 handle->debug_print("bmp280: read timeout.\n"); /* read timeout */
1521
1522 return 5; /* return error */
1523 }
1524 res = a_bmp280_iic_spi_read(handle, BMP280_REG_PRESS_MSB, buf, 6); /* read temperature and pressure */
1525 if (res != 0)
1526 {
1527 handle->debug_print("bmp280: read failed.\n"); /* read failed */
1528
1529 return 1; /* return error */
1530 }
1531 *temperature_raw = ((((uint32_t)(buf[3])) << 12) |
1532 (((uint32_t)(buf[4])) << 4) |
1533 ((uint32_t)buf[5] >> 4)); /* set temperature raw */
1534 res = a_bmp280_compensate_temperature(handle, *temperature_raw, temperature_c); /* compensate temperature */
1535 if (res != 0)
1536 {
1537 handle->debug_print("bmp280: compensate temperature failed.\n"); /* compensate temperature failed */
1538
1539 return 4; /* return error */
1540 }
1541 *pressure_raw = ((((int32_t)(buf[0])) << 12) |
1542 (((int32_t)(buf[1])) << 4) |
1543 (((int32_t)(buf[2])) >> 4)); /* set pressure raw */
1544 res = a_bmp280_compensate_pressure(handle, *pressure_raw, pressure_pa); /* compensate pressure */
1545 if (res != 0)
1546 {
1547 handle->debug_print("bmp280: compensate pressure failed.\n"); /* compensate pressure failed */
1548
1549 return 4; /* return error */
1550 }
1551 }
1552
1553 return 0; /* success return 0 */
1554}
1555
1568uint8_t bmp280_set_reg(bmp280_handle_t *handle, uint8_t reg, uint8_t value)
1569{
1570 if (handle == NULL) /* check handle */
1571 {
1572 return 2; /* return error */
1573 }
1574 if (handle->inited != 1) /* check handle initialization */
1575 {
1576 return 3; /* return error */
1577 }
1578
1579 return a_bmp280_iic_spi_write(handle, reg, &value, 1); /* write register */
1580}
1581
1594uint8_t bmp280_get_reg(bmp280_handle_t *handle, uint8_t reg, uint8_t *value)
1595{
1596 if (handle == NULL) /* check handle */
1597 {
1598 return 2; /* return error */
1599 }
1600 if (handle->inited != 1) /* check handle initialization */
1601 {
1602 return 3; /* return error */
1603 }
1604
1605 return a_bmp280_iic_spi_read(handle, reg, value, 1); /* read register */
1606}
1607
1617{
1618 if (info == NULL) /* check handle */
1619 {
1620 return 2; /* return error */
1621 }
1622
1623 memset(info, 0, sizeof(bmp280_info_t)); /* initialize bmp280 info structure */
1624 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1625 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1626 strncpy(info->interface, "IIC SPI", 8); /* copy interface name */
1627 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1628 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1629 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1630 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1631 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1632 info->driver_version = DRIVER_VERSION; /* set driver version */
1633
1634 return 0; /* success return 0 */
1635}
#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_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_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_get_temperatue_oversampling(bmp280_handle_t *handle, bmp280_oversampling_t *oversampling)
get temperatue oversampling
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
uint8_t bmp280_set_temperatue_oversampling(bmp280_handle_t *handle, bmp280_oversampling_t oversampling)
set temperatue oversampling
@ 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]