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
55#define BMP180_ADDRESS 0xEE
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
100static uint8_t a_bmp180_iic_read(
bmp180_handle_t *handle, uint8_t addr, uint8_t reg, uint8_t *data)
102 if (handle->
iic_read(addr, reg, data, 1) != 0)
123static uint8_t a_bmp180_iic_write(
bmp180_handle_t *handle, uint8_t addr, uint8_t reg, uint8_t data)
125 if (handle->
iic_write(addr, reg, &data, 1) != 0)
164 handle->
debug_print(
"bmp180: iic_init is null.\n");
170 handle->
debug_print(
"bmp180: iic_deinit is null.\n");
176 handle->
debug_print(
"bmp180: iic_read is null.\n");
182 handle->
debug_print(
"bmp180: iic_write is null.\n");
188 handle->
debug_print(
"bmp180: delay_ms is null.\n");
215 handle->
debug_print(
"bmp180: read AC1_MSB-MD_LSB failed.\n");
221 temp1 = temp1 | buf[1];
225 temp1 = temp1 | buf[3];
229 temp1 = temp1 | buf[5];
233 temp2 = temp2 | buf[7];
237 temp2 = temp2 | buf[9];
240 temp2 = buf[10] << 8;
241 temp2 = temp2 | buf[11];
243 temp1 = buf[12] << 8;
244 temp1 = temp1 | buf[13];
247 temp1 = buf[14] << 8;
248 temp1 = temp1 | buf[15];
251 temp1 = buf[16] << 8;
252 temp1 = temp1 | buf[17];
255 temp1 = buf[18] << 8;
256 temp1 = temp1 | buf[19];
259 temp1 = buf[20] << 8;
260 temp1 = temp1 | buf[21];
290 handle->
debug_print(
"bmp180: iic deinit failed.\n");
320 handle->
oss = (uint8_t)mode;
368 int32_t ut = 0, up = 0, x1 ,x2, x3, b5, b6, b3, p;
383 handle->
debug_print(
"bmp180: write CTRL_MEAS failed.\n");
392 handle->
debug_print(
"bmp180: read CTRL_MEAS failed.\n");
396 status = status & 0x20;
406 handle->
debug_print(
"bmp180: read temperature failed.\n");
411 memset(buf, 0,
sizeof(uint8_t) * 3);
414 handle->
debug_print(
"bmp180: read OUT MSB LSB failed.\n");
420 ut = ut & 0x0000FFFFU;
423 handle->
debug_print(
"bmp180: write CTRL_MEAS failed.\n");
433 handle->
debug_print(
"bmp180: read CTRL_MEAS failed.\n");
437 status = status & 0x20;
447 handle->
debug_print(
"bmp180: read pressure failed.\n");
452 memset(buf, 0,
sizeof(uint8_t) * 3);
455 handle->
debug_print(
"bmp180: read OUT MSB LSB XLSB failed.\n");
464 up = up >> (8-handle->
oss);
465 if (handle->
oss == 0)
467 up = up & 0x0000FFFFU;
469 else if (handle->
oss == 1)
471 up = up & 0x0001FFFFU;
473 else if (handle->
oss == 2)
475 up= up & 0x0003FFFFU;
477 else if (handle->
oss == 3)
479 up = up & 0x0007FFFFU;
487 x1 = (((ut - (int32_t)handle->
ac6) * (int32_t)handle->
ac5)) >> 15;
488 x2 = (int32_t)((((int32_t)handle->
mc) << 11) / (x1 + (int32_t)handle->
md));
491 x1 = ((int32_t)handle->
b2 * ((b6 * b6) >> 12)) >> 11;
492 x2 = ((int32_t)handle->
ac2 * b6) >> 11;
494 b3 = (((((int32_t)handle->
ac1) * 4 + x3) << handle->
oss) + 2) >> 2;
495 x1 = ((int32_t)handle->
ac3 * b6) >> 13;
496 x2 = ((int32_t)handle->
b1*(((b6 * b6)) >> 12)) >> 16;
497 x3 = ((x1 + x2) + 2) >> 2;
498 b4 = (uint32_t)((((uint32_t)handle->
ac4 * (uint32_t)(x3 + 32768))) >> 15);
499 b7 = (uint32_t)((uint32_t)(up - b3) * (50000>>handle->
oss));
500 if (b7 < 0x80000000U)
502 p = (int32_t)((b7 << 1) / b4);
506 p = (int32_t)((b7 / b4) << 1);
508 x1 = (p >> 8) * (p >> 8);
509 x1 = (x1 * 3038) >> 16;
510 x2 = (-7357 * p) >> 16;
511 *pa = p + ((x1 + x2 + 3791) >> 4);
533 int32_t ut = 0, x1 ,x2, b5;
547 handle->
debug_print(
"bmp180: write CTRL_MEAS failed.\n");
556 handle->
debug_print(
"bmp180: read CTRL_MEAS failed.\n");
560 status = status & 0x20;
570 handle->
debug_print(
"bmp180: read temperature failed.\n");
575 memset(buf, 0,
sizeof(uint8_t) * 3);
578 handle->
debug_print(
"bmp180: read OUT MSB LSB failed.\n");
584 ut = ut & 0x0000FFFFU;
586 x1 = (((ut - (int32_t)handle->
ac6) * (int32_t)handle->
ac5)) >> 15;
587 x2 =(int32_t)((((int32_t)handle->
mc) << 11) / (x1 + (int32_t)handle->
md));
589 *c = ((uint16_t)((b5 + 8) >> 4)) * 0.1f;
609 uint32_t *pressure_raw, uint32_t *pressure_pa)
614 int32_t ut = 0, up = 0, x1 ,x2, x3, b5, b6, b3, p;
629 handle->
debug_print(
"bmp180: write CTRL_MEAS failed.\n");
638 handle->
debug_print(
"bmp180: read CTRL_MEAS failed.\n");
642 status = status & 0x20;
652 handle->
debug_print(
"bmp180: read temperature failed.\n");
657 memset(buf, 0,
sizeof(uint8_t) * 3);
660 handle->
debug_print(
"bmp180: read OUT MSB LSB failed.\n");
666 ut = ut & 0x0000FFFFU;
667 *temperature_raw = (uint16_t)ut;
670 handle->
debug_print(
"bmp180: write CTRL_MEAS failed.\n");
680 handle->
debug_print(
"bmp180: read CTRL_MEAS failed.\n");
684 status = status & 0x20;
694 handle->
debug_print(
"bmp180: read pressure failed.\n");
699 memset(buf, 0,
sizeof(uint8_t) * 3);
702 handle->
debug_print(
"bmp180: read OUT MSB LSB XLSB failed.\n");
711 up = up >> (8-handle->
oss);
712 if (handle->
oss == 0)
714 up = up & 0x0000FFFFU;
716 else if (handle->
oss == 1)
718 up = up & 0x0001FFFFU;
720 else if (handle->
oss == 2)
722 up= up & 0x0003FFFFU;
724 else if (handle->
oss == 3)
726 up = up & 0x0007FFFFU;
734 x1 = (((ut - (int32_t)handle->
ac6) * (int32_t)handle->
ac5)) >> 15;
735 x2 = (int32_t)((((int32_t)handle->
mc) << 11) / (x1 + (int32_t)handle->
md));
737 *temperature_c = ((uint16_t)((b5 + 8) >> 4)) * 0.1f;
739 x1 = ((int32_t)handle->
b2 * ((b6 * b6) >> 12)) >> 11;
740 x2 = ((int32_t)handle->
ac2 * b6) >> 11;
742 b3 = (((((int32_t)handle->
ac1) * 4 + x3)<<handle->
oss) + 2) >> 2;
743 x1 = ((int32_t)handle->
ac3 * b6) >> 13;
744 x2 = ((int32_t)handle->
b1 * (((b6 * b6)) >> 12)) >> 16;
745 x3 = ((x1 + x2) + 2) >> 2;
746 b4 = (uint32_t)((((uint32_t)handle->
ac4 * (uint32_t)(x3 + 32768))) >> 15);
747 b7 = (uint32_t)((uint32_t)(up - b3) * (50000 >> handle->
oss));
748 if (b7 < 0x80000000U)
750 p = (int32_t)((b7 << 1) / b4);
754 p = (int32_t)((b7 / b4) << 1);
756 x1 = (p >> 8) * (p >> 8);
757 x1 = (x1 * 3038) >> 16;
758 x2 = (-7357 * p) >> 16;
759 *pressure_pa = p + ((x1 + x2 + 3791) >> 4);
#define BMP180_REG_CTRL_MEAS
#define BMP180_REG_AC1_MSB
chip register definition
#define SUPPLY_VOLTAGE_MAX
#define BMP180_REG_OUT_MSB
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define BMP180_ADDRESS
chip address definition
#define CHIP_NAME
chip information definition
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
char manufacturer_name[32]
float supply_voltage_min_v