42#define CHIP_NAME "Bosch BMP384"
43#define MANUFACTURER_NAME "Bosch"
44#define SUPPLY_VOLTAGE_MIN 1.65f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 0.8f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
54#define BMP384_REG_CMD 0x7E
55#define BMP384_REG_NVM_PAR_T1_L 0x31
56#define BMP384_REG_NVM_PAR_T1_H 0x32
57#define BMP384_REG_NVM_PAR_T2_L 0x33
58#define BMP384_REG_NVM_PAR_T2_H 0x34
59#define BMP384_REG_NVM_PAR_T3 0x35
60#define BMP384_REG_NVM_PAR_P1_L 0x36
61#define BMP384_REG_NVM_PAR_P1_H 0x37
62#define BMP384_REG_NVM_PAR_P2_L 0x38
63#define BMP384_REG_NVM_PAR_P2_H 0x39
64#define BMP384_REG_NVM_PAR_P3 0x3A
65#define BMP384_REG_NVM_PAR_P4 0x3B
66#define BMP384_REG_NVM_PAR_P5_L 0x3C
67#define BMP384_REG_NVM_PAR_P5_H 0x3D
68#define BMP384_REG_NVM_PAR_P6_L 0x3E
69#define BMP384_REG_NVM_PAR_P6_H 0x3F
70#define BMP384_REG_NVM_PAR_P7 0x40
71#define BMP384_REG_NVM_PAR_P8 0x41
72#define BMP384_REG_NVM_PAR_P9_L 0x42
73#define BMP384_REG_NVM_PAR_P9_H 0x43
74#define BMP384_REG_NVM_PAR_P10 0x44
75#define BMP384_REG_NVM_PAR_P11 0x45
76#define BMP384_REG_CONFIG 0x1F
77#define BMP384_REG_ODR 0x1D
78#define BMP384_REG_OSR 0x1C
79#define BMP384_REG_PWR_CTRL 0x1B
80#define BMP384_REG_IF_CONF 0x1A
81#define BMP384_REG_INT_CTRL 0x19
82#define BMP384_REG_FIFO_CONFIG_2 0x18
83#define BMP384_REG_FIFO_CONFIG_1 0x17
84#define BMP384_REG_FIFO_WTM_1 0x16
85#define BMP384_REG_FIFO_WTM_0 0x15
86#define BMP384_REG_FIFO_DATA 0x14
87#define BMP384_REG_FIFO_LENGTH_1 0x13
88#define BMP384_REG_FIFO_LENGTH_0 0x12
89#define BMP384_REG_INT_STATUS 0x11
90#define BMP384_REG_EVENT 0x10
91#define BMP384_REG_SENSORTIME_2 0x0E
92#define BMP384_REG_SENSORTIME_1 0x0D
93#define BMP384_REG_SENSORTIME_0 0x0C
94#define BMP384_REG_DATA_5 0x09
95#define BMP384_REG_DATA_4 0x08
96#define BMP384_REG_DATA_3 0x07
97#define BMP384_REG_DATA_2 0x06
98#define BMP384_REG_DATA_1 0x05
99#define BMP384_REG_DATA_0 0x04
100#define BMP384_REG_STATUS 0x03
101#define BMP384_REG_ERR_REG 0x02
102#define BMP384_REG_CHIP_ID 0x00
115static uint8_t a_bmp384_iic_spi_read(
bmp384_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
132 len > 512 ? (512 + 1) : (len + 1)) != 0)
136 memcpy(buf, handle->
buf+1, (len > 512) ? 512 : len);
153static uint8_t a_bmp384_iic_spi_write(
bmp384_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
159 for (i = 0; i < len; i++)
162 (uint8_t)(reg + i), buf + i, 1) != 0)
175 for (i = 0; i < len; i++)
177 if (handle->
spi_write((uint8_t)(reg + i), buf + i, 1) != 0)
201 handle->
debug_print(
"bmp384: get calibration data failed.\n");
205 handle->
t1 = (uint16_t)buf[1] << 8 | buf[0];
208 handle->
debug_print(
"bmp384: get calibration data failed.\n");
212 handle->
t2 = (uint16_t)buf[1] << 8 | buf[0];
215 handle->
debug_print(
"bmp384: get calibration data failed.\n");
219 handle->
t3 = (int8_t)(buf[0]);
222 handle->
debug_print(
"bmp384: get calibration data failed.\n");
226 handle->
p1 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);
229 handle->
debug_print(
"bmp384: get calibration data failed.\n");
233 handle->
p2 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);
236 handle->
debug_print(
"bmp384: get calibration data failed.\n");
240 handle->
p3 = (int8_t)(buf[0]);
243 handle->
debug_print(
"bmp384: get calibration data failed.\n");
247 handle->
p4 = (int8_t)(buf[0]);
250 handle->
debug_print(
"bmp384: get calibration data failed.\n");
254 handle->
p5 = (uint16_t)buf[1] << 8 | buf[0];
257 handle->
debug_print(
"bmp384: get calibration data failed.\n");
261 handle->
p6 = (uint16_t)buf[1] << 8 | buf[0];
264 handle->
debug_print(
"bmp384: get calibration data failed.\n");
268 handle->
p7 = (int8_t)(buf[0]);
271 handle->
debug_print(
"bmp384: get calibration data failed.\n");
275 handle->
p8 = (int8_t)(buf[0]);
278 handle->
debug_print(
"bmp384: get calibration data failed.\n");
282 handle->
p9 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);
285 handle->
debug_print(
"bmp384: get calibration data failed.\n");
289 handle->
p10 = (int8_t)(buf[0]);
292 handle->
debug_print(
"bmp384: get calibration data failed.\n");
296 handle->
p11 = (int8_t)(buf[0]);
308static int64_t a_bmp384_compensate_temperature(
bmp384_handle_t *handle, uint32_t data)
310 uint64_t partial_data1;
311 uint64_t partial_data2;
312 uint64_t partial_data3;
313 int64_t partial_data4;
314 int64_t partial_data5;
315 int64_t partial_data6;
319 partial_data1 = (uint64_t)(data - (256 * (uint64_t)(handle->
t1)));
320 partial_data2 = (uint64_t)(handle->
t2 * partial_data1);
321 partial_data3 = (uint64_t)(partial_data1 * partial_data1);
322 partial_data4 = (int64_t)(((int64_t)partial_data3) * ((int64_t)handle->
t3));
323 partial_data5 = ((int64_t)(((int64_t)partial_data2) * 262144) + (int64_t)partial_data4);
324 partial_data6 = (int64_t)(((int64_t)partial_data5) / 4294967296U);
325 handle->
t_fine = partial_data6;
326 comp_temp = (int64_t)((partial_data6 * 25) / 16384);
338static int64_t a_bmp384_compensate_pressure(
bmp384_handle_t *handle, uint32_t data)
340 int64_t partial_data1;
341 int64_t partial_data2;
342 int64_t partial_data3;
343 int64_t partial_data4;
344 int64_t partial_data5;
345 int64_t partial_data6;
352 partial_data2 = partial_data1 / 64;
353 partial_data3 = (partial_data2 * handle->
t_fine) / 256;
354 partial_data4 = (handle->
p8 * partial_data3) / 32;
355 partial_data5 = (handle->
p7 * partial_data1) * 16;
356 partial_data6 = (handle->
p6 * handle->
t_fine) * 4194304;
357 offset = (int64_t)((int64_t)(handle->
p5) * (int64_t)140737488355328U) + partial_data4 + partial_data5 + partial_data6;
358 partial_data2 = (((int64_t)handle->
p4) * partial_data3) / 32;
359 partial_data4 = (handle->
p3 * partial_data1) * 4;
360 partial_data5 = ((int64_t)(handle->
p2) - 16384) * ((int64_t)handle->
t_fine) * 2097152;
361 sensitivity = (((int64_t)(handle->
p1) - 16384) * (int64_t)70368744177664U) + partial_data2 + partial_data4 + partial_data5;
362 partial_data1 = (sensitivity / 16777216) * data;
363 partial_data2 = (int64_t)(handle->
p10) * (int64_t)(handle->
t_fine);
364 partial_data3 = partial_data2 + (65536 * (int64_t)(handle->
p9));
365 partial_data4 = (partial_data3 * data) / 8192;
366 partial_data5 = (partial_data4 * data) / 512;
367 partial_data6 = (int64_t)((uint64_t)data * (uint64_t)data);
368 partial_data2 = ((int64_t)(handle->
p11) * (int64_t)(partial_data6)) / 65536;
369 partial_data3 = (partial_data2 * data) / 128;
370 partial_data4 = (offset / 4) + partial_data1 + partial_data5 + partial_data3;
371 comp_press = (((uint64_t)partial_data4 * 25) / (uint64_t)1099511627776U);
403 handle->
debug_print(
"bmp384: get error register failed.\n");
438 handle->
debug_print(
"bmp384: get status register failed.\n");
474 handle->
debug_print(
"bmp384: get sensor time register failed.\n");
478 *t = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
511 handle->
debug_print(
"bmp384: get event register failed.\n");
547 handle->
debug_print(
"bmp384: get interrupt status register failed.\n");
583 handle->
debug_print(
"bmp384: get fifo length register failed.\n");
587 *length = ((uint16_t)(buf[1] & 0x01) << 8) | buf[0];
620 handle->
debug_print(
"bmp384: get fifo data register failed.\n");
653 buf[0] = watermark & 0xFF;
654 buf[1] = (watermark >> 8) & 0x01;
658 handle->
debug_print(
"bmp384: set fifo watermark register failed.\n");
694 handle->
debug_print(
"bmp384: get fifo watermark register failed.\n");
698 *watermark = ((uint16_t)(buf[1] & 0x01) << 8) | buf[0];
731 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
740 handle->
debug_print(
"bmp384: set fifo config 1 register failed.\n");
776 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
813 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
822 handle->
debug_print(
"bmp384: set fifo config 1 register failed.\n");
858 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
895 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
904 handle->
debug_print(
"bmp384: set fifo config 1 register failed.\n");
940 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
977 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
986 handle->
debug_print(
"bmp384: set fifo config 1 register failed.\n");
1022 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
1059 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
1064 prev |= enable << 4;
1068 handle->
debug_print(
"bmp384: set fifo config 1 register failed.\n");
1104 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
1140 handle->
debug_print(
"bmp384: subsample is invalid.\n");
1147 handle->
debug_print(
"bmp384: get fifo config 2 register failed.\n");
1152 prev |= subsample << 0;
1156 handle->
debug_print(
"bmp384: set fifo config 2 register failed.\n");
1192 handle->
debug_print(
"bmp384: get fifo config 2 register failed.\n");
1229 handle->
debug_print(
"bmp384: get fifo config 2 register failed.\n");
1234 prev |= source << 3;
1238 handle->
debug_print(
"bmp384: set fifo config 2 register failed.\n");
1274 handle->
debug_print(
"bmp384: get fifo config 2 register failed.\n");
1311 handle->
debug_print(
"bmp384: get int ctrl register failed.\n");
1316 prev |= pin_type << 0;
1320 handle->
debug_print(
"bmp384: set int ctrl register failed.\n");
1356 handle->
debug_print(
"bmp384: get int ctrl register failed.\n");
1393 handle->
debug_print(
"bmp384: get int ctrl register failed.\n");
1402 handle->
debug_print(
"bmp384: set int ctrl register failed.\n");
1438 handle->
debug_print(
"bmp384: get int ctrl register failed.\n");
1475 handle->
debug_print(
"bmp384: get int ctrl register failed.\n");
1480 prev |= enable << 2;
1484 handle->
debug_print(
"bmp384: set int ctrl register failed.\n");
1520 handle->
debug_print(
"bmp384: get int ctrl register failed.\n");
1557 handle->
debug_print(
"bmp384: get int ctrl register failed.\n");
1562 prev |= enable << 3;
1566 handle->
debug_print(
"bmp384: set int ctrl register failed.\n");
1602 handle->
debug_print(
"bmp384: get int ctrl register failed.\n");
1639 handle->
debug_print(
"bmp384: get int ctrl register failed.\n");
1644 prev |= enable << 4;
1648 handle->
debug_print(
"bmp384: set int ctrl register failed.\n");
1684 handle->
debug_print(
"bmp384: get int ctrl register failed.\n");
1721 handle->
debug_print(
"bmp384: get int ctrl register failed.\n");
1726 prev |= enable << 6;
1730 handle->
debug_print(
"bmp384: set int ctrl register failed.\n");
1766 handle->
debug_print(
"bmp384: get int ctrl register failed.\n");
1803 handle->
debug_print(
"bmp384: get if conf register failed.\n");
1812 handle->
debug_print(
"bmp384: set if conf register failed.\n");
1848 handle->
debug_print(
"bmp384: get if conf register failed.\n");
1885 handle->
debug_print(
"bmp384: get if conf register failed.\n");
1890 prev |= enable << 1;
1894 handle->
debug_print(
"bmp384: set if conf register failed.\n");
1930 handle->
debug_print(
"bmp384: get if conf register failed.\n");
1967 handle->
debug_print(
"bmp384: get if conf register failed.\n");
1972 prev |= period << 2;
1976 handle->
debug_print(
"bmp384: set if conf register failed.\n");
2012 handle->
debug_print(
"bmp384: get if conf register failed.\n");
2049 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
2054 prev |= enable << 0;
2058 handle->
debug_print(
"bmp384: set pwr ctrl register failed.\n");
2094 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
2131 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
2136 prev |= enable << 1;
2140 handle->
debug_print(
"bmp384: set pwr ctrl register failed.\n");
2176 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
2213 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
2222 handle->
debug_print(
"bmp384: set pwr ctrl register failed.\n");
2258 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
2292 res = a_bmp384_iic_spi_read(handle,
BMP384_REG_OSR, (uint8_t *)&prev, 1);
2295 handle->
debug_print(
"bmp384: get osr register failed.\n");
2300 prev |= oversampling << 0;
2301 res = a_bmp384_iic_spi_write(handle,
BMP384_REG_OSR, (uint8_t *)&prev, 1);
2304 handle->
debug_print(
"bmp384: set osr register failed.\n");
2337 res = a_bmp384_iic_spi_read(handle,
BMP384_REG_OSR, (uint8_t *)&prev, 1);
2340 handle->
debug_print(
"bmp384: get osr register failed.\n");
2374 res = a_bmp384_iic_spi_read(handle,
BMP384_REG_OSR, (uint8_t *)&prev, 1);
2377 handle->
debug_print(
"bmp384: get osr register failed.\n");
2382 prev |= oversampling << 3;
2383 res = a_bmp384_iic_spi_write(handle,
BMP384_REG_OSR, (uint8_t *)&prev, 1);
2386 handle->
debug_print(
"bmp384: set osr register failed.\n");
2419 res = a_bmp384_iic_spi_read(handle,
BMP384_REG_OSR, (uint8_t *)&prev, 1);
2422 handle->
debug_print(
"bmp384: get osr register failed.\n");
2456 res = a_bmp384_iic_spi_read(handle,
BMP384_REG_ODR, (uint8_t *)&prev, 1);
2459 handle->
debug_print(
"bmp384: get odr register failed.\n");
2466 res = a_bmp384_iic_spi_write(handle,
BMP384_REG_ODR, (uint8_t *)&prev, 1);
2469 handle->
debug_print(
"bmp384: set odr register failed.\n");
2502 res = a_bmp384_iic_spi_read(handle,
BMP384_REG_ODR, (uint8_t *)&prev, 1);
2505 handle->
debug_print(
"bmp384: get odr register failed.\n");
2542 handle->
debug_print(
"bmp384: get config register failed.\n");
2547 prev &= ~(0x7 << 1);
2548 prev |= coefficient << 1;
2552 handle->
debug_print(
"bmp384: set config register failed.\n");
2588 handle->
debug_print(
"bmp384: get config register failed.\n");
2622 res = a_bmp384_iic_spi_write(handle,
BMP384_REG_CMD, (uint8_t *)&prev, 1);
2625 handle->
debug_print(
"bmp384: set cmd register failed.\n");
2658 res = a_bmp384_iic_spi_write(handle,
BMP384_REG_CMD, (uint8_t *)&prev, 1);
2661 handle->
debug_print(
"bmp384: set cmd register failed.\n");
2694 res = a_bmp384_iic_spi_write(handle,
BMP384_REG_CMD, (uint8_t *)&prev, 1);
2697 handle->
debug_print(
"bmp384: set cmd register failed.\n");
2721 handle->
debug_print(
"bmp384: iic deinit failed.\n");
2734 handle->
debug_print(
"bmp384: spi deinit failed.\n");
2773 handle->
debug_print(
"bmp384: iic_init is null.\n");
2779 handle->
debug_print(
"bmp384: iic_deinit is null.\n");
2785 handle->
debug_print(
"bmp384: iic_read is null.\n");
2791 handle->
debug_print(
"bmp384: iic_write is null.\n");
2797 handle->
debug_print(
"bmp384: spi_init is null.\n");
2803 handle->
debug_print(
"bmp384: spi_deinit is null.\n");
2809 handle->
debug_print(
"bmp384: spi_read is null.\n");
2815 handle->
debug_print(
"bmp384: spi_write is null.\n");
2821 handle->
debug_print(
"bmp384: delay_ms is null.\n");
2830 handle->
debug_print(
"bmp384: iic init failed.\n");
2839 handle->
debug_print(
"bmp384: spi init failed.\n");
2846 handle->
debug_print(
"bmp384: read chip id failed.\n");
2847 (void)a_bmp384_close(handle);
2854 (void)a_bmp384_close(handle);
2859 if (a_bmp384_iic_spi_write(handle,
BMP384_REG_CMD, (uint8_t *)®, 1) != 0)
2861 handle->
debug_print(
"bmp384: soft rest failed.\n");
2862 (void)a_bmp384_close(handle);
2869 handle->
debug_print(
"bmp384: get err reg failed.\n");
2870 (void)a_bmp384_close(handle);
2874 if ((reg & 0x07) != 0)
2876 handle->
debug_print(
"bmp384: find running error.\n");
2877 (void)a_bmp384_close(handle);
2881 if (a_bmp384_get_calibration_data(handle) != 0)
2883 handle->
debug_print(
"bmp384: get calibration data error.\n");
2884 (void)a_bmp384_close(handle);
2921 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
2930 handle->
debug_print(
"bmp384: set pwr ctrl register failed.\n");
2934 if (a_bmp384_close(handle) != 0)
2976 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
2980 if ((prev & 0x01) != 0)
2982 handle->
debug_print(
"bmp384: fifo mode can't use this function.\n");
2989 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
2993 if (((prev >> 4) & 0x03) == 0x03)
2998 handle->
debug_print(
"bmp384: get status register failed.\n");
3002 if ((prev & (1 << 6)) != 0)
3009 handle->
debug_print(
"bmp384: get data register failed.\n");
3013 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3014 output = a_bmp384_compensate_temperature(handle, *raw);
3015 *c = (float)((
double)output / 100.0);
3022 handle->
debug_print(
"bmp384: temperature data is not ready.\n");
3027 else if (((prev >> 4) & 0x03) == 0x00)
3029 uint16_t cnt = 5000;
3034 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
3038 prev &= ~(0x03 << 4);
3043 handle->
debug_print(
"bmp384: set pwr ctrl register failed.\n");
3053 handle->
debug_print(
"bmp384: get status register failed.\n");
3057 if ((prev & (1 << 6)) != 0)
3064 handle->
debug_print(
"bmp384: get data register failed.\n");
3068 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3069 output = a_bmp384_compensate_temperature(handle, *raw);
3070 *c = (float)((
double)output / 100.0);
3084 handle->
debug_print(
"bmp384: temperature data is not ready.\n");
3092 handle->
debug_print(
"bmp384: mode is invalid.\n");
3115 uint32_t temperature_raw;
3129 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
3133 if ((prev & 0x01) != 0)
3135 handle->
debug_print(
"bmp384: fifo mode can't use this function.\n");
3142 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
3146 if (((prev >> 4) & 0x03) == 0x03)
3151 handle->
debug_print(
"bmp384: get status register failed.\n");
3155 if ((prev & (1 << 6)) != 0)
3160 handle->
debug_print(
"bmp384: get data register failed.\n");
3164 temperature_raw= (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3165 (void)a_bmp384_compensate_temperature(handle, temperature_raw);
3169 handle->
debug_print(
"bmp384: temperature data is not ready.\n");
3173 if ((prev & (1 << 5)) != 0)
3180 handle->
debug_print(
"bmp384: get data register failed.\n");
3184 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3185 output = a_bmp384_compensate_pressure(handle, *raw);
3186 *pa = (float)((
double)output / 100.0);
3192 handle->
debug_print(
"bmp384: pressure data is not ready.\n");
3197 else if (((prev >> 4) & 0x03) == 0x00)
3199 uint16_t cnt = 5000;
3204 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
3208 prev &= ~(0x03 << 4);
3213 handle->
debug_print(
"bmp384: set pwr ctrl register failed.\n");
3223 handle->
debug_print(
"bmp384: get status register failed.\n");
3227 if ((prev & (1 << 6)) != 0)
3232 handle->
debug_print(
"bmp384: get data register failed.\n");
3236 temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3237 (void)a_bmp384_compensate_temperature(handle, temperature_raw);
3250 handle->
debug_print(
"bmp384: temperature data is not ready.\n");
3258 if ((prev & (1 << 5)) != 0)
3265 handle->
debug_print(
"bmp384: get data register failed.\n");
3269 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3270 output = a_bmp384_compensate_pressure(handle, *raw);
3271 *pa = (float)((
double)output / 100.0);
3284 handle->
debug_print(
"bmp384: temperature data is not ready.\n");
3292 handle->
debug_print(
"bmp384: mode is invalid.\n");
3313 uint32_t *pressure_raw,
float *pressure_pa)
3331 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
3335 if ((prev & 0x01) != 0)
3337 handle->
debug_print(
"bmp384: fifo mode can't use this function.\n");
3344 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
3348 if (((prev >> 4) & 0x03) == 0x03)
3353 handle->
debug_print(
"bmp384: get status register failed.\n");
3357 if ((prev & (1 << 6)) != 0)
3364 handle->
debug_print(
"bmp384: get data register failed.\n");
3368 *temperature_raw= (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3369 output = a_bmp384_compensate_temperature(handle, *temperature_raw);
3370 *temperature_c = (float)((
double)output / 100.0);
3374 handle->
debug_print(
"bmp384: temperature data is not ready.\n");
3378 if ((prev & (1 << 5)) != 0)
3385 handle->
debug_print(
"bmp384: get data register failed.\n");
3389 *pressure_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3390 output = a_bmp384_compensate_pressure(handle, *pressure_raw);
3391 *pressure_pa = (float)((
double)output / 100.0);
3397 handle->
debug_print(
"bmp384: pressure data is not ready.\n");
3402 else if (((prev >> 4) & 0x03) == 0x00)
3404 uint16_t cnt = 5000;
3409 handle->
debug_print(
"bmp384: get pwr ctrl register failed.\n");
3413 prev &= ~(0x03 << 4);
3418 handle->
debug_print(
"bmp384: set pwr ctrl register failed.\n");
3428 handle->
debug_print(
"bmp384: get status register failed.\n");
3432 if ((prev & (1 << 6)) != 0)
3439 handle->
debug_print(
"bmp384: get data register failed.\n");
3443 *temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3444 output = a_bmp384_compensate_temperature(handle, *temperature_raw);
3445 *temperature_c = (float)((
double)output / 100.0);
3458 handle->
debug_print(
"bmp384: temperature data is not ready.\n");
3467 if ((prev & (1 << 5)) != 0)
3474 handle->
debug_print(
"bmp384: get data register failed.\n");
3478 *pressure_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3479 output = a_bmp384_compensate_pressure(handle, *pressure_raw);
3480 *pressure_pa = (float)((
double)output / 100.0);
3493 handle->
debug_print(
"bmp384: temperature data is not ready.\n");
3501 handle->
debug_print(
"bmp384: mode is invalid.\n");
3534 handle->
debug_print(
"bmp384: get interrupt status register failed.\n");
3538 if ((status & (1 << 1)) != 0)
3545 if ((status & (1 << 0)) != 0)
3552 if ((status & (1 << 3)) != 0)
3579 handle->
iic_addr = (uint8_t)addr_pin;
3621 handle->
iic_spi = (uint8_t)interface;
3678 handle->
debug_print(
"bmp384: get fifo config 1 register failed.\n");
3682 if ((prev & 0x01) != 0)
3687 handle->
debug_print(
"bmp384: get fifo length register failed.\n");
3691 length = ((uint16_t)(tmp_buf[1] & 0x01) << 8) | tmp_buf[0];
3692 if ((prev & (1 << 2)) != 0)
3696 *len = (*len) < length ? (*len) :length;
3700 handle->
debug_print(
"bmp384: get fifo data failed.\n");
3709 handle->
debug_print(
"bmp384: normal mode or forced mode can't use this function.\n");
3733 uint16_t frame_total;
3746 handle->
debug_print(
"bmp384: buffer length is invalid.\n");
3755 switch ((uint8_t)buf[i])
3759 if (frame_total > ((*frame_len)-1))
3764 frame[frame_total].
raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1];
3765 frame[frame_total].
data = (float)((
double)a_bmp384_compensate_temperature(handle, frame[frame_total].raw) / 100.0);
3773 if ((frame_total) > ((*frame_len)-1))
3778 frame[frame_total].
raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1];
3779 frame[frame_total].
data = (float)((
double)a_bmp384_compensate_temperature(handle, frame[frame_total].raw) / 100.0);
3781 if (frame_total > ((*frame_len)-1))
3786 frame[frame_total].
raw = (uint32_t)buf[i + 5 + 1] << 16 | (uint32_t)buf[i + 4 + 1] << 8 | buf[i + 3 + 1];
3787 frame[frame_total].
data = (float)((
double)a_bmp384_compensate_pressure(handle, frame[frame_total].raw) / 100.0);
3795 if (frame_total > ((*frame_len)-1))
3800 frame[frame_total].
raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1];
3801 frame[frame_total].
data = 0;
3827 handle->
debug_print(
"bmp384: header is invalid.\n");
3838 *frame_len = frame_total;
3866 return a_bmp384_iic_spi_write(handle, reg, &value, 1);
3892 return a_bmp384_iic_spi_read(handle, reg, value, 1);
#define BMP384_REG_NVM_PAR_T3
#define BMP384_REG_NVM_PAR_T1_L
#define BMP384_REG_IF_CONF
#define BMP384_REG_DATA_3
#define BMP384_REG_FIFO_CONFIG_2
#define BMP384_REG_NVM_PAR_P10
#define BMP384_REG_FIFO_WTM_0
#define BMP384_REG_FIFO_CONFIG_1
#define BMP384_REG_NVM_PAR_P3
#define BMP384_REG_NVM_PAR_P7
#define BMP384_REG_NVM_PAR_P11
#define BMP384_REG_FIFO_LENGTH_0
#define BMP384_REG_INT_CTRL
#define BMP384_REG_NVM_PAR_P8
#define SUPPLY_VOLTAGE_MAX
#define BMP384_REG_FIFO_DATA
#define BMP384_REG_CHIP_ID
#define BMP384_REG_NVM_PAR_T2_L
#define BMP384_REG_NVM_PAR_P2_L
#define BMP384_REG_NVM_PAR_P6_L
#define BMP384_REG_ERR_REG
#define BMP384_REG_SENSORTIME_0
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define BMP384_REG_STATUS
#define BMP384_REG_NVM_PAR_P5_L
#define BMP384_REG_NVM_PAR_P4
#define CHIP_NAME
chip information definition
#define BMP384_REG_NVM_PAR_P9_L
#define BMP384_REG_CMD
chip register definition
#define BMP384_REG_DATA_0
#define BMP384_REG_CONFIG
#define BMP384_REG_NVM_PAR_P1_L
#define BMP384_REG_PWR_CTRL
#define BMP384_REG_INT_STATUS
driver bmp384 header file
uint8_t bmp384_read_temperature_pressure(bmp384_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa)
read the temperature and pressure
uint8_t bmp384_get_iic_watchdog_timer(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the iic watchdog timer status
uint8_t bmp384_deinit(bmp384_handle_t *handle)
close the chip
bmp384_event_t
bmp384 event enumeration definition
uint8_t bmp384_get_addr_pin(bmp384_handle_t *handle, bmp384_address_t *addr_pin)
get the iic address pin
uint8_t bmp384_get_spi_wire(bmp384_handle_t *handle, bmp384_spi_wire_t *wire)
get the spi wire
bmp384_mode_t
bmp384 mode enumeration definition
uint8_t bmp384_set_addr_pin(bmp384_handle_t *handle, bmp384_address_t addr_pin)
set the iic address pin
bmp384_interface_t
bmp384 interface enumeration definition
uint8_t bmp384_softreset(bmp384_handle_t *handle)
soft reset
uint8_t bmp384_get_filter_coefficient(bmp384_handle_t *handle, bmp384_filter_coefficient_t *coefficient)
get the filter coefficient
uint8_t bmp384_extmode_en_middle(bmp384_handle_t *handle)
extmode enable middle
uint8_t bmp384_get_pressure_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t *oversampling)
get the pressure oversampling
bmp384_fifo_data_source_t
bmp384 fifo data source enumeration definition
uint8_t bmp384_get_pressure(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the pressure status
uint8_t bmp384_read_pressure(bmp384_handle_t *handle, uint32_t *raw, float *pa)
read the pressure
uint8_t bmp384_get_status(bmp384_handle_t *handle, uint8_t *status)
get the status
uint8_t bmp384_set_interface(bmp384_handle_t *handle, bmp384_interface_t interface)
set the interface
uint8_t bmp384_set_pressure(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the pressure
uint8_t bmp384_set_temperature(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the temperature
bmp384_spi_wire_t
bmp384 spi wire enumeration definition
bmp384_bool_t
bmp384 bool enumeration definition
uint8_t bmp384_get_sensortime(bmp384_handle_t *handle, uint32_t *t)
get the sensor time
struct bmp384_frame_s bmp384_frame_t
bmp384 frame structure definition
uint8_t bmp384_read_temperature(bmp384_handle_t *handle, uint32_t *raw, float *c)
read the temperature
bmp384_interrupt_pin_type_t
bmp384 interrupt pin type enumeration definition
uint8_t bmp384_get_temperature_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t *oversampling)
get the temperature oversampling
uint8_t bmp384_set_pressure_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t oversampling)
set the pressure oversampling
uint8_t bmp384_get_interface(bmp384_handle_t *handle, bmp384_interface_t *interface)
get the interface
uint8_t bmp384_set_iic_watchdog_timer(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the iic watchdog timer
uint8_t bmp384_get_event(bmp384_handle_t *handle, bmp384_event_t *event)
get the event
bmp384_odr_t
bmp384 output data rate enumeration definition
bmp384_address_t
bmp384 address enumeration definition
uint8_t bmp384_set_filter_coefficient(bmp384_handle_t *handle, bmp384_filter_coefficient_t coefficient)
set the filter coefficient
uint8_t bmp384_info(bmp384_info_t *info)
get chip's information
bmp384_filter_coefficient_t
bmp384 filter coefficient enumeration definition
uint8_t bmp384_get_mode(bmp384_handle_t *handle, bmp384_mode_t *mode)
get the chip mode
struct bmp384_info_s bmp384_info_t
bmp384 information structure definition
uint8_t bmp384_set_spi_wire(bmp384_handle_t *handle, bmp384_spi_wire_t wire)
set the spi wire
uint8_t bmp384_set_mode(bmp384_handle_t *handle, bmp384_mode_t mode)
set the chip mode
uint8_t bmp384_init(bmp384_handle_t *handle)
initialize the chip
bmp384_iic_watchdog_period_t
bmp384 iic watchdog period enumeration definition
uint8_t bmp384_set_iic_watchdog_period(bmp384_handle_t *handle, bmp384_iic_watchdog_period_t period)
set the iic watchdog period
uint8_t bmp384_get_iic_watchdog_period(bmp384_handle_t *handle, bmp384_iic_watchdog_period_t *period)
get the iic watchdog period
uint8_t bmp384_get_odr(bmp384_handle_t *handle, bmp384_odr_t *odr)
get the output data rate
bmp384_oversampling_t
bmp384 oversampling enumeration definition
uint8_t bmp384_irq_handler(bmp384_handle_t *handle)
irq handler
uint8_t bmp384_set_temperature_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t oversampling)
set the temperature oversampling
struct bmp384_handle_s bmp384_handle_t
bmp384 handle structure definition
uint8_t bmp384_set_odr(bmp384_handle_t *handle, bmp384_odr_t odr)
set the output data rate
uint8_t bmp384_get_temperature(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the temperature status
uint8_t bmp384_get_error(bmp384_handle_t *handle, uint8_t *err)
get the error
bmp384_interrupt_active_level_t
bmp384 interrupt active level enumeration definition
@ BMP384_FRAME_TYPE_SENSORTIME
@ BMP384_FRAME_TYPE_PRESSURE
@ BMP384_FRAME_TYPE_TEMPERATURE
@ BMP384_INTERRUPT_STATUS_FIFO_WATERMARK
@ BMP384_INTERRUPT_STATUS_FIFO_FULL
@ BMP384_INTERRUPT_STATUS_DATA_READY
uint8_t bmp384_set_reg(bmp384_handle_t *handle, uint8_t reg, uint8_t value)
set the chip register
uint8_t bmp384_get_reg(bmp384_handle_t *handle, uint8_t reg, uint8_t *value)
get the chip register
uint8_t bmp384_fifo_parse(bmp384_handle_t *handle, uint8_t *buf, uint16_t buf_len, bmp384_frame_t *frame, uint16_t *frame_len)
parse the fifo data
uint8_t bmp384_get_fifo_pressure_on(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the fifo pressure on status
uint8_t bmp384_set_fifo_pressure_on(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo pressure on
uint8_t bmp384_set_fifo_data_source(bmp384_handle_t *handle, bmp384_fifo_data_source_t source)
set the fifo data source
uint8_t bmp384_get_fifo_length(bmp384_handle_t *handle, uint16_t *length)
get the fifo length
uint8_t bmp384_set_fifo_stop_on_full(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo stopping on full
uint8_t bmp384_set_fifo_sensortime_on(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo sensor time on
uint8_t bmp384_get_fifo_temperature_on(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the fifo temperature on status
uint8_t bmp384_read_fifo(bmp384_handle_t *handle, uint8_t *buf, uint16_t *len)
read the fifo
uint8_t bmp384_set_fifo(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo
uint8_t bmp384_get_fifo(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the fifo status
uint8_t bmp384_get_fifo_stop_on_full(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the fifo stopping on full status
uint8_t bmp384_get_fifo_sensortime_on(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the fifo sensor time on status
uint8_t bmp384_flush_fifo(bmp384_handle_t *handle)
flush the fifo
uint8_t bmp384_set_fifo_temperature_on(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo temperature on
uint8_t bmp384_get_fifo_data_source(bmp384_handle_t *handle, bmp384_fifo_data_source_t *source)
get the fifo data source
uint8_t bmp384_get_fifo_watermark(bmp384_handle_t *handle, uint16_t *watermark)
get the fifo watermark
uint8_t bmp384_set_fifo_watermark(bmp384_handle_t *handle, uint16_t watermark)
set the fifo watermark
uint8_t bmp384_get_fifo_data(bmp384_handle_t *handle, uint8_t *data, uint16_t length)
get the fifo data
uint8_t bmp384_set_fifo_subsampling(bmp384_handle_t *handle, uint8_t subsample)
set the fifo subsampling
uint8_t bmp384_get_fifo_subsampling(bmp384_handle_t *handle, uint8_t *subsample)
get the fifo subsampling
uint8_t bmp384_set_interrupt_pin_type(bmp384_handle_t *handle, bmp384_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t bmp384_get_interrupt_active_level(bmp384_handle_t *handle, bmp384_interrupt_active_level_t *level)
get the interrupt active level
uint8_t bmp384_set_interrupt_active_level(bmp384_handle_t *handle, bmp384_interrupt_active_level_t level)
set the interrupt active level
uint8_t bmp384_get_interrupt_fifo_full(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the interrupt fifo full
uint8_t bmp384_get_interrupt_status(bmp384_handle_t *handle, uint8_t *status)
get the interrupt status
uint8_t bmp384_set_interrupt_data_ready(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the data ready interrupt
uint8_t bmp384_get_interrupt_pin_type(bmp384_handle_t *handle, bmp384_interrupt_pin_type_t *pin_type)
get the interrupt pin type
uint8_t bmp384_get_interrupt_fifo_watermark(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the interrupt fifo watermark
uint8_t bmp384_set_interrupt_fifo_full(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo full interrupt
uint8_t bmp384_get_latch_interrupt_pin_and_interrupt_status(bmp384_handle_t *handle, bmp384_bool_t *enable)
get latching interrupt pin and interrupt status
uint8_t bmp384_set_interrupt_fifo_watermark(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo watermark interrupt
uint8_t bmp384_set_latch_interrupt_pin_and_interrupt_status(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable latching interrupt pin and interrupt status
uint8_t bmp384_get_interrupt_data_ready(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the interrupt data ready status
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* receive_callback)(uint8_t type)
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
char manufacturer_name[32]
float supply_voltage_min_v