LibDriver BMP180
Loading...
Searching...
No Matches
driver_bmp180.c
Go to the documentation of this file.
1
37
38#include "driver_bmp180.h"
39
43#define CHIP_NAME "Bosch BMP180"
44#define MANUFACTURER_NAME "Bosch"
45#define SUPPLY_VOLTAGE_MIN 1.8f
46#define SUPPLY_VOLTAGE_MAX 3.6f
47#define MAX_CURRENT 0.65f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 2000
51
55#define BMP180_ADDRESS 0xEE
56
60#define BMP180_REG_AC1_MSB 0xAA
61#define BMP180_REG_AC1_LSB 0xAB
62#define BMP180_REG_AC2_MSB 0xAC
63#define BMP180_REG_AC2_LSB 0xAD
64#define BMP180_REG_AC3_MSB 0xAE
65#define BMP180_REG_AC3_LSB 0xAF
66#define BMP180_REG_AC4_MSB 0xB0
67#define BMP180_REG_AC4_LSB 0xB1
68#define BMP180_REG_AC5_MSB 0xB2
69#define BMP180_REG_AC5_LSB 0xB3
70#define BMP180_REG_AC6_MSB 0xB4
71#define BMP180_REG_AC6_LSB 0xB5
72#define BMP180_REG_B1_MSB 0xB6
73#define BMP180_REG_B1_LSB 0xB7
74#define BMP180_REG_B2_MSB 0xB8
75#define BMP180_REG_B2_LSB 0xB9
76#define BMP180_REG_MB_MSB 0xBA
77#define BMP180_REG_MB_LSB 0xBB
78#define BMP180_REG_MC_MSB 0xBC
79#define BMP180_REG_MC_LSB 0xBD
80#define BMP180_REG_MD_MSB 0xBE
81#define BMP180_REG_MD_LSB 0xBF
82#define BMP180_REG_CTRL_MEAS 0xF4
83#define BMP180_REG_OUT_MSB 0xF6
84#define BMP180_REG_OUT_LSB 0xF7
85#define BMP180_REG_OUT_XLSB 0xF8
86#define BMP180_REG_SOFT 0xE0
87#define BMP180_REG_ID 0xD0
88
100static uint8_t a_bmp180_iic_read(bmp180_handle_t *handle, uint8_t addr, uint8_t reg, uint8_t *data)
101{
102 if (handle->iic_read(addr, reg, data, 1) != 0) /* read */
103 {
104 return 1; /* return error */
105 }
106 else
107 {
108 return 0; /* success return 0 */
109 }
110}
111
123static uint8_t a_bmp180_iic_write(bmp180_handle_t *handle, uint8_t addr, uint8_t reg, uint8_t data)
124{
125 if (handle->iic_write(addr, reg, &data, 1) != 0) /* write */
126 {
127 return 1; /* return error */
128 }
129 else
130 {
131 return 0; /* success return 0 */
132 }
133}
134
148{
149 uint8_t buf[22];
150 int16_t temp1 = 0;
151 uint16_t temp2 = 0;
152 uint8_t id;
153
154 if (handle == NULL) /* check handle */
155 {
156 return 2; /* return error */
157 }
158 if (handle->debug_print == NULL) /* check debug_print */
159 {
160 return 3; /* return error */
161 }
162 if (handle->iic_init == NULL) /* check iic_init */
163 {
164 handle->debug_print("bmp180: iic_init is null.\n"); /* iic_init is nul */
165
166 return 3; /* return error */
167 }
168 if (handle->iic_deinit == NULL) /* check iic_deinit */
169 {
170 handle->debug_print("bmp180: iic_deinit is null.\n"); /* iic_deinit is null */
171
172 return 3; /* return error */
173 }
174 if (handle->iic_read == NULL) /* check iic_read */
175 {
176 handle->debug_print("bmp180: iic_read is null.\n"); /* iic_read is null */
177
178 return 3; /* return error */
179 }
180 if (handle->iic_write == NULL) /* check iic_write */
181 {
182 handle->debug_print("bmp180: iic_write is null.\n"); /* iic_write is null */
183
184 return 3; /* return error */
185 }
186 if (handle->delay_ms == NULL) /* check delay_ms */
187 {
188 handle->debug_print("bmp180: delay_ms is null.\n"); /* delay_ms is null */
189
190 return 3; /* return error */
191 }
192
193 if (handle->iic_init() != 0) /* iic init */
194 {
195 handle->debug_print("bmp180: iic init failed.\n"); /* iic init failed */
196
197 return 1; /* return error */
198 }
199 if (a_bmp180_iic_read(handle, BMP180_ADDRESS, BMP180_REG_ID, (uint8_t *)&id) != 0) /* read chip id */
200 {
201 handle->debug_print("bmp180: read id failed.\n"); /* read id failed */
202 (void)handle->iic_deinit(); /* iic deinit */
203
204 return 1; /* return error */
205 }
206 if (id != 0x55) /* check id */
207 {
208 handle->debug_print("bmp180: id is error.\n"); /* id is error */
209 (void)handle->iic_deinit(); /* iic deinit */
210
211 return 4; /* return error */
212 }
213 if (handle->iic_read(BMP180_ADDRESS, BMP180_REG_AC1_MSB, (uint8_t *)buf, 22) != 0) /* read ac1-md */
214 {
215 handle->debug_print("bmp180: read AC1_MSB-MD_LSB failed.\n"); /* read ac1 -md failed */
216 (void)handle->iic_deinit(); /* deinit iic */
217
218 return 5; /* return error */
219 }
220 temp1 = buf[0] << 8; /* get MSB */
221 temp1 = temp1 | buf[1]; /* get LSB */
222 handle->ac1 = temp1; /* save ac1 */
223 temp1 = 0; /* reset temp1 */
224 temp1 = buf[2] << 8; /* get MSB */
225 temp1 = temp1 | buf[3]; /* get LSB */
226 handle->ac2 = temp1; /* save ac2 */
227 temp1 = 0; /* reset temp1 */
228 temp1 = buf[4] << 8; /* get MSB */
229 temp1 = temp1 | buf[5]; /* get LSB */
230 handle->ac3 = temp1; /* save ac3 */
231 temp1 = 0; /* reset temp1 */
232 temp2 = buf[6] << 8; /* get MSB */
233 temp2 = temp2 | buf[7]; /* get LSB */
234 handle->ac4 = temp2; /* save ac4 */
235 temp2 = 0; /* reset temp1 */
236 temp2 = buf[8] << 8; /* get MSB */
237 temp2 = temp2 | buf[9]; /* get LSB */
238 handle->ac5 = temp2; /* save ac5 */
239 temp2 = 0; /* reset temp2 */
240 temp2 = buf[10] << 8; /* get MSB */
241 temp2 = temp2 | buf[11]; /* get LSB */
242 handle->ac6 = temp2; /* save ac6 */
243 temp1 = buf[12] << 8; /* get MSB */
244 temp1 = temp1 | buf[13]; /* get LSB */
245 handle->b1 = temp1; /* save b1 */
246 temp1 = 0; /* reset temp1 */
247 temp1 = buf[14] << 8; /* get MSB */
248 temp1 = temp1 | buf[15]; /* get LSB */
249 handle->b2 = temp1; /* save b2 */
250 temp1 = 0; /* reset temp1 */
251 temp1 = buf[16] << 8; /* get MSB */
252 temp1 = temp1 | buf[17]; /* get LSB */
253 handle->mb = temp1; /* save mb */
254 temp1 = 0; /* reset temp1 */
255 temp1 = buf[18] << 8; /* get MSB */
256 temp1 = temp1 | buf[19]; /* get LSB */
257 handle->mc = temp1; /* save mc */
258 temp1 = 0; /* reset temp1 */
259 temp1 = buf[20] << 8; /* get MSB */
260 temp1 = temp1 | buf[21]; /* get LSB */
261 handle->md = temp1; /* save md */
262 handle->inited = 1; /* flag finish initialization */
263
264 return 0; /* success return 0 */
265}
266
278{
279 if (handle == NULL) /* check handle */
280 {
281 return 2; /* return error */
282 }
283 if (handle->inited != 1) /* check handle initialization */
284 {
285 return 3; /* return error */
286 }
287
288 if (handle->iic_deinit() != 0) /* iic deinit */
289 {
290 handle->debug_print("bmp180: iic deinit failed.\n"); /* iic deinit failed */
291
292 return 1; /* return error */
293 }
294 handle->inited = 0; /* flag close */
295
296 return 0; /* success return 0 */
297}
298
310{
311 if (handle == NULL) /* check handle */
312 {
313 return 2; /* return error */
314 }
315 if (handle->inited != 1) /* check handle initialization */
316 {
317 return 3; /* return error */
318 }
319
320 handle->oss = (uint8_t)mode; /* set mode */
321
322 return 0; /* success return 0 */
323}
324
336{
337 if (handle == NULL) /* check handle */
338 {
339 return 2; /* return error */
340 }
341 if (handle->inited != 1) /* check handle initialization */
342 {
343 return 3; /* return error */
344 }
345
346 *mode = (bmp180_mode_t)handle->oss; /* get mode */
347
348 return 0; /* success return 0 */
349}
350
363uint8_t bmp180_read_pressure(bmp180_handle_t *handle, uint32_t *raw, uint32_t *pa)
364{
365 uint8_t buf[3];
366 uint8_t status;
367 uint16_t num;
368 int32_t ut = 0, up = 0, x1 ,x2, x3, b5, b6, b3, p;
369 uint32_t b4,b7;
370
371 if (handle == NULL) /* check handle */
372 {
373 return 2; /* return error */
374 }
375 if (handle->inited != 1) /* check handle initialization */
376 {
377 return 3; /* return error */
378 }
379
380 num = 5000; /* set timeout 5000 ms */
381 if (a_bmp180_iic_write(handle, BMP180_ADDRESS, BMP180_REG_CTRL_MEAS, 0x2E) != 0) /* write temperature measurement command */
382 {
383 handle->debug_print("bmp180: write CTRL_MEAS failed.\n"); /* write CTRL_MEAS failed */
384
385 return 1; /* return error */
386 }
387 while (num != 0) /* check times */
388 {
389 handle->delay_ms(1); /* wait 1 ms */
390 if (a_bmp180_iic_read(handle, BMP180_ADDRESS, BMP180_REG_CTRL_MEAS, (uint8_t *)&status) != 0) /* read ctrl status */
391 {
392 handle->debug_print("bmp180: read CTRL_MEAS failed.\n"); /* return ctrl meas failed */
393
394 return 1; /* return error */
395 }
396 status = status & 0x20; /* get finished flag */
397 if (status == 0) /* check flag */
398 {
399 goto t_read; /* goto next step */
400 }
401 else
402 {
403 num = num-1; /* times-1 */
404 }
405 }
406 handle->debug_print("bmp180: read temperature failed.\n"); /* read temperature failed */
407
408 return 1; /* return error */
409
410 t_read:
411 memset(buf, 0, sizeof(uint8_t) * 3); /* clear the buffer */
412 if (handle->iic_read(BMP180_ADDRESS, BMP180_REG_OUT_MSB, (uint8_t *)buf ,2) != 0) /* read raw temperature */
413 {
414 handle->debug_print("bmp180: read OUT MSB LSB failed.\n"); /* read OUT MSB LSB failed */
415
416 return 1; /* return error */
417 }
418 ut = buf[0] << 8; /* get MSB */
419 ut = ut | buf[1]; /* get LSB */
420 ut = ut & 0x0000FFFFU; /* get valid part */
421 if (a_bmp180_iic_write(handle, BMP180_ADDRESS, BMP180_REG_CTRL_MEAS, 0x34+(handle->oss<<6)) != 0) /* write pressure measurement command */
422 {
423 handle->debug_print("bmp180: write CTRL_MEAS failed.\n"); /* write CTRL_MEAS failed */
424
425 return 1; /* return error */
426 }
427 num = 5000; /* set timeout 5000 ms */
428 while (num != 0) /* check times */
429 {
430 handle->delay_ms(1); /* wait 1 ms */
431 if (a_bmp180_iic_read(handle, BMP180_ADDRESS, BMP180_REG_CTRL_MEAS, (uint8_t *)&status) != 0) /* read status */
432 {
433 handle->debug_print("bmp180: read CTRL_MEAS failed.\n"); /* read CTRL_MEAS failed */
434
435 return 1; /* return error */
436 }
437 status = status & 0x20; /* get finished flag */
438 if (status == 0) /* check flag */
439 {
440 goto p_read; /* goto next step */
441 }
442 else
443 {
444 num = num-1; /* times-1 */
445 }
446 }
447 handle->debug_print("bmp180: read pressure failed.\n"); /* read pressure failed */
448
449 return 1; /* return error */
450
451 p_read:
452 memset(buf, 0, sizeof(uint8_t) * 3); /* clear the buffer */
453 if (handle->iic_read(BMP180_ADDRESS, BMP180_REG_OUT_MSB, (uint8_t *)buf ,3) != 0) /* read pressure */
454 {
455 handle->debug_print("bmp180: read OUT MSB LSB XLSB failed.\n"); /* read OUT MSB LSB XLSB failed */
456
457 return 1; /* return error */
458 }
459 up = buf[0] << 8; /* get MSB */
460 up = up | buf[1]; /* get LSB */
461 up = up << 8; /* left shift 8 */
462 up = up | buf[2]; /* get XLSB */
463 *raw = up; /* get raw data */
464 up = up >> (8-handle->oss); /* shift */
465 if (handle->oss == 0) /* ultra low */
466 {
467 up = up & 0x0000FFFFU; /* set mask */
468 }
469 else if (handle->oss == 1) /* standard */
470 {
471 up = up & 0x0001FFFFU; /* set mask */
472 }
473 else if (handle->oss == 2) /* high */
474 {
475 up= up & 0x0003FFFFU; /* set mask */
476 }
477 else if (handle->oss == 3) /* ultra high */
478 {
479 up = up & 0x0007FFFFU; /* set mask */
480 }
481 else
482 {
483 handle->debug_print("bmp180: oss param error.\n"); /* oss param error */
484
485 return 1; /* return error */
486 }
487 x1 = (((ut - (int32_t)handle->ac6) * (int32_t)handle->ac5)) >> 15; /* calculate x1 */
488 x2 = (int32_t)((((int32_t)handle->mc) << 11) / (x1 + (int32_t)handle->md)); /* calculate x2 */
489 b5 = x1 + x2; /* calculate b5 */
490 b6 = b5 - 4000; /* calculate b6 */
491 x1 = ((int32_t)handle->b2 * ((b6 * b6) >> 12)) >> 11; /* calculate x1 */
492 x2 = ((int32_t)handle->ac2 * b6) >> 11; /* calculate x2 */
493 x3 = x1 + x2; /* calculate x3 */
494 b3 = (((((int32_t)handle->ac1) * 4 + x3) << handle->oss) + 2) >> 2; /* calculate b3 */
495 x1 = ((int32_t)handle->ac3 * b6) >> 13; /* calculate x1 */
496 x2 = ((int32_t)handle->b1*(((b6 * b6)) >> 12)) >> 16; /* calculate x2 */
497 x3 = ((x1 + x2) + 2) >> 2; /* calculate x3 */
498 b4 = (uint32_t)((((uint32_t)handle->ac4 * (uint32_t)(x3 + 32768))) >> 15); /* calculate b4 */
499 b7 = (uint32_t)((uint32_t)(up - b3) * (50000>>handle->oss)); /* calculate b7 */
500 if (b7 < 0x80000000U)
501 {
502 p = (int32_t)((b7 << 1) / b4); /* calculate p */
503 }
504 else
505 {
506 p = (int32_t)((b7 / b4) << 1); /* calculate p */
507 }
508 x1 = (p >> 8) * (p >> 8); /* calculate x1 */
509 x1 = (x1 * 3038) >> 16; /* calculate x1 */
510 x2 = (-7357 * p) >> 16; /* calculate x2 */
511 *pa = p + ((x1 + x2 + 3791) >> 4); /* calculate x2 */
512
513 return 0; /* success return 0 */
514}
515
528uint8_t bmp180_read_temperature(bmp180_handle_t *handle, uint16_t *raw, float *c)
529{
530 uint8_t buf[3];
531 uint8_t status;
532 uint16_t num;
533 int32_t ut = 0, x1 ,x2, b5;
534
535 if (handle == NULL) /* check handle */
536 {
537 return 2; /* return error */
538 }
539 if (handle->inited != 1) /* check handle initialization */
540 {
541 return 3; /* return error */
542 }
543
544 num = 5000; /* set timeout 5000 */
545 if (a_bmp180_iic_write(handle, BMP180_ADDRESS, BMP180_REG_CTRL_MEAS, 0x2E) != 0) /* write temperature measurement command */
546 {
547 handle->debug_print("bmp180: write CTRL_MEAS failed.\n"); /* write CTRL_MEAS failed */
548
549 return 1; /* return error */
550 }
551 while (num != 0) /* check times */
552 {
553 handle->delay_ms(1); /* delay 1 ms */
554 if (a_bmp180_iic_read(handle, BMP180_ADDRESS, BMP180_REG_CTRL_MEAS, (uint8_t *)&status) != 0) /* read status */
555 {
556 handle->debug_print("bmp180: read CTRL_MEAS failed.\n"); /* read CTRL_MEAS failed */
557
558 return 1; /* return error */
559 }
560 status = status & 0x20; /* get finished flag */
561 if (status == 0) /* check flag */
562 {
563 goto t_read; /* goto next step */
564 }
565 else
566 {
567 num = num-1; /* times-1 */
568 }
569 }
570 handle->debug_print("bmp180: read temperature failed.\n"); /* read temperature failed */
571
572 return 1; /* return error */
573
574 t_read:
575 memset(buf, 0, sizeof(uint8_t) * 3); /* clear the buffer */
576 if (handle->iic_read(BMP180_ADDRESS, BMP180_REG_OUT_MSB, (uint8_t *)buf ,2) != 0) /* read raw temperature */
577 {
578 handle->debug_print("bmp180: read OUT MSB LSB failed.\n"); /* read OUT MSB LSB failed */
579
580 return 1; /* return error */
581 }
582 ut = buf[0] << 8; /* get MSB */
583 ut = ut | buf[1]; /* get LSB */
584 ut = ut & 0x0000FFFFU; /* set mask */
585 *raw = (uint16_t)ut; /* get raw temperature */
586 x1 = (((ut - (int32_t)handle->ac6) * (int32_t)handle->ac5)) >> 15; /* calculate x1 */
587 x2 =(int32_t)((((int32_t)handle->mc) << 11) / (x1 + (int32_t)handle->md)); /* calculate x2 */
588 b5 = x1 + x2; /* calculate b5 */
589 *c = ((uint16_t)((b5 + 8) >> 4)) * 0.1f; /* calculate temperature */
590
591 return 0; /* success return 0 */
592}
593
608uint8_t bmp180_read_temperature_pressure(bmp180_handle_t *handle, uint16_t *temperature_raw, float *temperature_c,
609 uint32_t *pressure_raw, uint32_t *pressure_pa)
610{
611 uint8_t buf[3];
612 uint8_t status;
613 uint16_t num;
614 int32_t ut = 0, up = 0, x1 ,x2, x3, b5, b6, b3, p;
615 uint32_t b4,b7;
616
617 if (handle == NULL) /* check handle */
618 {
619 return 2; /* return error */
620 }
621 if (handle->inited != 1) /* check handle initialization */
622 {
623 return 3; /* return error */
624 }
625
626 num = 5000; /* set timeout 5000 */
627 if (a_bmp180_iic_write(handle, BMP180_ADDRESS, BMP180_REG_CTRL_MEAS, 0x2E) != 0) /* write temperature measurement command */
628 {
629 handle->debug_print("bmp180: write CTRL_MEAS failed.\n"); /* write CTRL_MEAS failed */
630
631 return 1; /* return error */
632 }
633 while (num != 0) /* check times */
634 {
635 handle->delay_ms(1); /* wait 1 ms */
636 if (a_bmp180_iic_read(handle, BMP180_ADDRESS, BMP180_REG_CTRL_MEAS, (uint8_t *)&status) != 0) /* read status */
637 {
638 handle->debug_print("bmp180: read CTRL_MEAS failed.\n"); /* read CTRL_MEAS failed */
639
640 return 1; /* return error */
641 }
642 status = status & 0x20; /* get finished flag */
643 if (status == 0) /* check flag */
644 {
645 goto t_read; /* goto next step */
646 }
647 else
648 {
649 num = num-1; /* times-1 */
650 }
651 }
652 handle->debug_print("bmp180: read temperature failed.\n"); /* read temperature failed */
653
654 return 1; /* return error */
655
656 t_read:
657 memset(buf, 0, sizeof(uint8_t) * 3); /* clear the buffer */
658 if (handle->iic_read(BMP180_ADDRESS, BMP180_REG_OUT_MSB, (uint8_t *)buf ,2) != 0) /* read raw temperature */
659 {
660 handle->debug_print("bmp180: read OUT MSB LSB failed.\n"); /* read OUT MSB LSB failed */
661
662 return 1; /* return error */
663 }
664 ut = buf[0] << 8; /* get MSB */
665 ut = ut | buf[1]; /* get LSB */
666 ut = ut & 0x0000FFFFU; /* set mask */
667 *temperature_raw = (uint16_t)ut; /* get temperature */
668 if (a_bmp180_iic_write(handle, BMP180_ADDRESS, BMP180_REG_CTRL_MEAS, 0x34+(handle->oss<<6)) != 0) /* write pressure measurement command */
669 {
670 handle->debug_print("bmp180: write CTRL_MEAS failed.\n"); /* write CTRL_MEAS failed */
671
672 return 1; /* return error */
673 }
674 num = 5000; /* set timeout 5000 */
675 while (num != 0) /* check times */
676 {
677 handle->delay_ms(1); /* wait 1 ms */
678 if (a_bmp180_iic_read(handle, BMP180_ADDRESS, BMP180_REG_CTRL_MEAS, (uint8_t *)&status) != 0) /* read status */
679 {
680 handle->debug_print("bmp180: read CTRL_MEAS failed.\n"); /* read CTRL_MEAS failed */
681
682 return 1; /* return error */
683 }
684 status = status & 0x20; /* get finished flag */
685 if (status == 0) /* check flag */
686 {
687 goto p_read; /* goto next step */
688 }
689 else
690 {
691 num = num-1; /* times-1 */
692 }
693 }
694 handle->debug_print("bmp180: read pressure failed.\n"); /* read pressure failed */
695
696 return 1; /* return error */
697
698 p_read:
699 memset(buf, 0, sizeof(uint8_t) * 3); /* clear the buffer */
700 if (handle->iic_read(BMP180_ADDRESS, BMP180_REG_OUT_MSB, (uint8_t *)buf ,3) != 0) /* read raw pressure */
701 {
702 handle->debug_print("bmp180: read OUT MSB LSB XLSB failed.\n"); /* read OUT MSB LSB XLSB failed */
703
704 return 1; /* return error */
705 }
706 up = buf[0] << 8; /* get MSB */
707 up = up | buf[1]; /* get LSB */
708 up = up << 8; /* left shit */
709 up = up | buf[2]; /* get XLSB */
710 *pressure_raw = up; /* get pressure */
711 up = up >> (8-handle->oss); /* right shift */
712 if (handle->oss == 0) /* ultra low */
713 {
714 up = up & 0x0000FFFFU; /* set mask */
715 }
716 else if (handle->oss == 1) /* standard */
717 {
718 up = up & 0x0001FFFFU; /* set mask */
719 }
720 else if (handle->oss == 2) /* high */
721 {
722 up= up & 0x0003FFFFU; /* set mask */
723 }
724 else if (handle->oss == 3) /* ultra high */
725 {
726 up = up & 0x0007FFFFU; /* set mask */
727 }
728 else
729 {
730 handle->debug_print("bmp180: oss param error.\n"); /* oss param error */
731
732 return 1; /* return error */
733 }
734 x1 = (((ut - (int32_t)handle->ac6) * (int32_t)handle->ac5)) >> 15; /* calculate x1 */
735 x2 = (int32_t)((((int32_t)handle->mc) << 11) / (x1 + (int32_t)handle->md)); /* calculate x2 */
736 b5 = x1 + x2; /* calculate b5 */
737 *temperature_c = ((uint16_t)((b5 + 8) >> 4)) * 0.1f; /* get temperature */
738 b6 = b5 - 4000; /* calculate b6 */
739 x1 = ((int32_t)handle->b2 * ((b6 * b6) >> 12)) >> 11; /* calculate x1 */
740 x2 = ((int32_t)handle->ac2 * b6) >> 11; /* calculate x2 */
741 x3 = x1 + x2; /* calculate x3 */
742 b3 = (((((int32_t)handle->ac1) * 4 + x3)<<handle->oss) + 2) >> 2; /* calculate b3 */
743 x1 = ((int32_t)handle->ac3 * b6) >> 13; /* calculate x1 */
744 x2 = ((int32_t)handle->b1 * (((b6 * b6)) >> 12)) >> 16; /* calculate x2 */
745 x3 = ((x1 + x2) + 2) >> 2; /* calculate x3 */
746 b4 = (uint32_t)((((uint32_t)handle->ac4 * (uint32_t)(x3 + 32768))) >> 15); /* calculate b4 */
747 b7 = (uint32_t)((uint32_t)(up - b3) * (50000 >> handle->oss)); /* calculate b7 */
748 if (b7 < 0x80000000U)
749 {
750 p = (int32_t)((b7 << 1) / b4); /* calculate p */
751 }
752 else
753 {
754 p = (int32_t)((b7 / b4) << 1); /* calculate p */
755 }
756 x1 = (p >> 8) * (p >> 8); /* calculate x1 */
757 x1 = (x1 * 3038) >> 16; /* calculate x1 */
758 x2 = (-7357 * p) >> 16; /* calculate x2 */
759 *pressure_pa = p + ((x1 + x2 + 3791) >> 4); /* set pressure */
760
761 return 0; /* success return 0 */
762}
763
776uint8_t bmp180_set_reg(bmp180_handle_t *handle, uint8_t reg, uint8_t value)
777{
778 if (handle == NULL) /* check handle */
779 {
780 return 2; /* return error */
781 }
782 if (handle->inited != 1) /* check handle initialization */
783 {
784 return 3; /* return error */
785 }
786
787 return a_bmp180_iic_write(handle, BMP180_ADDRESS, reg, value); /* write register */
788}
789
802uint8_t bmp180_get_reg(bmp180_handle_t *handle, uint8_t reg, uint8_t *value)
803{
804 if (handle == NULL) /* check handle */
805 {
806 return 2; /* return error */
807 }
808 if (handle->inited != 1) /* check handle initialization */
809 {
810 return 3; /* return error */
811 }
812
813 return a_bmp180_iic_read(handle, BMP180_ADDRESS, reg, value); /* read register */
814}
815
825{
826 if (info == NULL) /* check handle */
827 {
828 return 2; /* return error */
829 }
830
831 memset(info, 0, sizeof(bmp180_info_t)); /* initialize bmp180 info structure */
832 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
833 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
834 strncpy(info->interface, "IIC", 8); /* copy interface name */
835 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
836 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
837 info->max_current_ma = MAX_CURRENT; /* set maximum current */
838 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
839 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
840 info->driver_version = DRIVER_VERSION; /* set driver version */
841
842 return 0; /* success return 0 */
843}
#define MAX_CURRENT
#define BMP180_REG_ID
#define BMP180_REG_CTRL_MEAS
#define BMP180_REG_AC1_MSB
chip register definition
#define SUPPLY_VOLTAGE_MAX
#define BMP180_REG_OUT_MSB
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define BMP180_ADDRESS
chip address definition
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
driver bmp180 header file
uint8_t bmp180_deinit(bmp180_handle_t *handle)
close the chip
struct bmp180_info_s bmp180_info_t
bmp180 information structure definition
bmp180_mode_t
bmp180 mode enumeration definition
struct bmp180_handle_s bmp180_handle_t
bmp180 handle structure definition
uint8_t bmp180_init(bmp180_handle_t *handle)
initialize the chip
uint8_t bmp180_info(bmp180_info_t *info)
get chip's information
uint8_t bmp180_read_temperature(bmp180_handle_t *handle, uint16_t *raw, float *c)
read the temperature data
uint8_t bmp180_read_pressure(bmp180_handle_t *handle, uint32_t *raw, uint32_t *pa)
read the pressure data
uint8_t bmp180_read_temperature_pressure(bmp180_handle_t *handle, uint16_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, uint32_t *pressure_pa)
read the temperature and pressure data
uint8_t bmp180_get_mode(bmp180_handle_t *handle, bmp180_mode_t *mode)
get the measurement mode
uint8_t bmp180_set_mode(bmp180_handle_t *handle, bmp180_mode_t mode)
set the measurement mode
uint8_t bmp180_set_reg(bmp180_handle_t *handle, uint8_t reg, uint8_t value)
set the chip register
uint8_t bmp180_get_reg(bmp180_handle_t *handle, uint8_t reg, uint8_t *value)
get the chip register
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(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]