LibDriver BMP388
Loading...
Searching...
No Matches
driver_bmp388_read_test.c
Go to the documentation of this file.
1
37
39
40static bmp388_handle_t gs_handle;
41
52uint8_t bmp388_read_test(bmp388_interface_t interface, bmp388_address_t addr_pin, uint32_t times)
53{
54 uint8_t res;
55 uint32_t i;
56 bmp388_info_t info;
57
58 /* link functions */
71
72 /* bmp388 info */
73 res = bmp388_info(&info);
74 if (res != 0)
75 {
76 bmp388_interface_debug_print("bmp388: get info failed.\n");
77
78 return 1;
79 }
80 else
81 {
82 /* print chip information */
83 bmp388_interface_debug_print("bmp388: chip is %s.\n", info.chip_name);
84 bmp388_interface_debug_print("bmp388: manufacturer is %s.\n", info.manufacturer_name);
85 bmp388_interface_debug_print("bmp388: interface is %s.\n", info.interface);
86 bmp388_interface_debug_print("bmp388: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
87 bmp388_interface_debug_print("bmp388: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
88 bmp388_interface_debug_print("bmp388: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
89 bmp388_interface_debug_print("bmp388: max current is %0.2fmA.\n", info.max_current_ma);
90 bmp388_interface_debug_print("bmp388: max temperature is %0.1fC.\n", info.temperature_max);
91 bmp388_interface_debug_print("bmp388: min temperature is %0.1fC.\n", info.temperature_min);
92 }
93
94 /* start read test */
95 bmp388_interface_debug_print("bmp388: start read test.\n");
96 res = bmp388_set_interface(&gs_handle, interface);
97 if (res != 0)
98 {
99 bmp388_interface_debug_print("bmp388: set interface failed.\n");
100
101 return 1;
102 }
103
104 /* set addr pin */
105 res = bmp388_set_addr_pin(&gs_handle, addr_pin);
106 if (res != 0)
107 {
108 bmp388_interface_debug_print("bmp388: set addr pin failed.\n");
109
110 return 1;
111 }
112
113 /* bmp388 init */
114 res = bmp388_init(&gs_handle);
115 if (res != 0)
116 {
117 bmp388_interface_debug_print("bmp388: init failed.\n");
118
119 return 1;
120 }
121
122 /* set spi wire 4 */
123 res = bmp388_set_spi_wire(&gs_handle, BMP388_SPI_WIRE_4);
124 if (res != 0)
125 {
126 bmp388_interface_debug_print("bmp388: set spi wire failed.\n");
127 (void)bmp388_deinit(&gs_handle);
128
129 return 1;
130 }
131
132 /* enable iic watchdog timer */
134 if (res != 0)
135 {
136 bmp388_interface_debug_print("bmp388: set iic watchdog timer failed.\n");
137 (void)bmp388_deinit(&gs_handle);
138
139 return 1;
140 }
141
142 /* set iic watchdog period 40 ms */
144 if (res != 0)
145 {
146 bmp388_interface_debug_print("bmp388: set iic watchdog period failed.\n");
147 (void)bmp388_deinit(&gs_handle);
148
149 return 1;
150 }
151
152 /* disable fifo */
153 res = bmp388_set_fifo(&gs_handle, BMP388_BOOL_FALSE);
154 if (res != 0)
155 {
156 bmp388_interface_debug_print("bmp388: set fifo failed.\n");
157 (void)bmp388_deinit(&gs_handle);
158
159 return 1;
160 }
161
162 /* disable fifo stop on full */
164 if (res != 0)
165 {
166 bmp388_interface_debug_print("bmp388: set fifo stop on full failed.\n");
167 (void)bmp388_deinit(&gs_handle);
168
169 return 1;
170 }
171
172 /* set fifo watermark 256 */
173 res = bmp388_set_fifo_watermark(&gs_handle, 256);
174 if (res != 0)
175 {
176 bmp388_interface_debug_print("bmp388: set fifo watermark failed.\n");
177 (void)bmp388_deinit(&gs_handle);
178
179 return 1;
180 }
181
182 /* enable fifo sensor time on */
184 if (res != 0)
185 {
186 bmp388_interface_debug_print("bmp388: set fifo sensor time on failed.\n");
187 (void)bmp388_deinit(&gs_handle);
188
189 return 1;
190 }
191
192 /* enable fifo pressure on */
194 if (res != 0)
195 {
196 bmp388_interface_debug_print("bmp388: set fifo sensor time on failed.\n");
197 (void)bmp388_deinit(&gs_handle);
198
199 return 1;
200 }
201
202 /* enable fifo temperature on */
204 if (res != 0)
205 {
206 bmp388_interface_debug_print("bmp388: set fifo temperature on failed.\n");
207 (void)bmp388_deinit(&gs_handle);
208
209 return 1;
210 }
211
212 /* set fifo subsampling 0 */
213 res = bmp388_set_fifo_subsampling(&gs_handle, 0);
214 if (res != 0)
215 {
216 bmp388_interface_debug_print("bmp388: set fifo subsampling failed.\n");
217 (void)bmp388_deinit(&gs_handle);
218
219 return 1;
220 }
221
222 /* set fifo data source filtered */
224 if (res != 0)
225 {
226 bmp388_interface_debug_print("bmp388: set fifo data source failed.\n");
227 (void)bmp388_deinit(&gs_handle);
228
229 return 1;
230 }
231
232 /* set interrupt pin type push-pull */
234 if (res != 0)
235 {
236 bmp388_interface_debug_print("bmp388: set interrupt pin type failed.\n");
237 (void)bmp388_deinit(&gs_handle);
238
239 return 1;
240 }
241
242 /* set interrupt active level higher */
244 if (res != 0)
245 {
246 bmp388_interface_debug_print("bmp388: set interrupt active level failed.\n");
247 (void)bmp388_deinit(&gs_handle);
248
249 return 1;
250 }
251
252 /* enable latch interrupt pin and interrupt status */
254 if (res != 0)
255 {
256 bmp388_interface_debug_print("bmp388: set set latch interrupt pin and interrupt status failed.\n");
257 (void)bmp388_deinit(&gs_handle);
258
259 return 1;
260 }
261
262 /* enable interrupt fifo watermark */
264 if (res != 0)
265 {
266 bmp388_interface_debug_print("bmp388: set interrupt fifo watermark failed.\n");
267 (void)bmp388_deinit(&gs_handle);
268
269 return 1;
270 }
271
272 /* enable interrupt fifo full */
274 if (res != 0)
275 {
276 bmp388_interface_debug_print("bmp388: set interrupt fifo full failed.\n");
277 (void)bmp388_deinit(&gs_handle);
278
279 return 1;
280 }
281
282 /* disable interrupt data ready */
284 if (res != 0)
285 {
286 bmp388_interface_debug_print("bmp388: set interrupt data ready failed.\n");
287 (void)bmp388_deinit(&gs_handle);
288
289 return 1;
290 }
291
292 /* enable pressure */
293 res = bmp388_set_pressure(&gs_handle, BMP388_BOOL_TRUE);
294 if (res != 0)
295 {
296 bmp388_interface_debug_print("bmp388: set pressure failed.\n");
297 (void)bmp388_deinit(&gs_handle);
298
299 return 1;
300 }
301
302 /* enable temperature */
303 res = bmp388_set_temperature(&gs_handle, BMP388_BOOL_TRUE);
304 if (res != 0)
305 {
306 bmp388_interface_debug_print("bmp388: set temperature failed.\n");
307 (void)bmp388_deinit(&gs_handle);
308
309 return 1;
310 }
311
312 /* set pressure oversampling x32 */
314 if (res != 0)
315 {
316 bmp388_interface_debug_print("bmp388: set pressure oversampling failed.\n");
317 (void)bmp388_deinit(&gs_handle);
318
319 return 1;
320 }
321
322 /* set temperature oversampling x2 */
324 if (res != 0)
325 {
326 bmp388_interface_debug_print("bmp388: set temperature oversampling failed.\n");
327 (void)bmp388_deinit(&gs_handle);
328
329 return 1;
330 }
331
332 /* set odr 12.5Hz */
333 res = bmp388_set_odr(&gs_handle, BMP388_ODR_12P5_HZ);
334 if (res != 0)
335 {
336 bmp388_interface_debug_print("bmp388: set odr failed.\n");
337 (void)bmp388_deinit(&gs_handle);
338
339 return 1;
340 }
341
342 /* set filter coefficient 15 */
344 if (res != 0)
345 {
346 bmp388_interface_debug_print("bmp388: set filter coefficient failed.\n");
347 (void)bmp388_deinit(&gs_handle);
348
349 return 1;
350 }
351
352 /* start forced mode read test */
353 bmp388_interface_debug_print("bmp388: forced mode read test.\n");
354
355 /* set forced mode */
356 res = bmp388_set_mode(&gs_handle, BMP388_MODE_FORCED_MODE);
357 if (res != 0)
358 {
359 bmp388_interface_debug_print("bmp388: set mode failed.\n");
360 (void)bmp388_deinit(&gs_handle);
361
362 return 1;
363 }
365 for (i = 0; i < times; i++)
366 {
367 uint32_t temperature_raw;
368 uint32_t pressure_raw;
369 float temperature_c;
370 float pressure_pa;
371
372 /* read temperature pressure */
373 if (bmp388_read_temperature_pressure(&gs_handle, (uint32_t *)&temperature_raw, (float *)&temperature_c,
374 (uint32_t *)&pressure_raw, (float *)&pressure_pa) != 0)
375 {
376 bmp388_interface_debug_print("bmp388: read temperature and pressure failed.\n");
377 (void)bmp388_deinit(&gs_handle);
378
379 return 1;
380 }
381 bmp388_interface_debug_print("bmp388: temperature is %0.2fC.\n", temperature_c);
382 bmp388_interface_debug_print("bmp388: pressure is %0.2fPa.\n", pressure_pa);
384 }
385
386 /* start normal mode read */
387 bmp388_interface_debug_print("bmp388: normal mode read test.\n");
388 res = bmp388_set_mode(&gs_handle, BMP388_MODE_SLEEP_MODE);
389 if (res != 0)
390 {
391 bmp388_interface_debug_print("bmp388: set mode failed.\n");
392 (void)bmp388_deinit(&gs_handle);
393
394 return 1;
395 }
397
398 /* set normal mode */
399 res = bmp388_set_mode(&gs_handle, BMP388_MODE_NORMAL_MODE);
400 if (res != 0)
401 {
402 bmp388_interface_debug_print("bmp388: set mode failed.\n");
403 (void)bmp388_deinit(&gs_handle);
404
405 return 1;
406 }
408 for (i = 0; i < times; i++)
409 {
410 uint32_t temperature_raw;
411 uint32_t pressure_raw;
412 float temperature_c;
413 float pressure_pa;
414
415 /* read temperature pressure */
416 if (bmp388_read_temperature_pressure(&gs_handle, (uint32_t *)&temperature_raw, (float *)&temperature_c,
417 (uint32_t *)&pressure_raw, (float *)&pressure_pa) != 0)
418 {
419 bmp388_interface_debug_print("bmp388: read temperature and pressure failed.\n");
420 (void)bmp388_deinit(&gs_handle);
421
422 return 1;
423 }
424 bmp388_interface_debug_print("bmp388: temperature is %0.2fC.\n", temperature_c);
425 bmp388_interface_debug_print("bmp388: pressure is %0.2fPa.\n", pressure_pa);
427 }
428
429 /* finish read test */
430 bmp388_interface_debug_print("bmp388: finish read test.\n");
431 (void)bmp388_deinit(&gs_handle);
432
433 return 0;
434}
driver bmp388 read test header file
uint8_t bmp388_set_odr(bmp388_handle_t *handle, bmp388_odr_t odr)
set the output data rate
uint8_t bmp388_set_pressure(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the pressure
bmp388_interface_t
bmp388 interface enumeration definition
uint8_t bmp388_init(bmp388_handle_t *handle)
initialize the chip
uint8_t bmp388_set_spi_wire(bmp388_handle_t *handle, bmp388_spi_wire_t wire)
set the spi wire
uint8_t bmp388_set_iic_watchdog_timer(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the iic watchdog timer
struct bmp388_handle_s bmp388_handle_t
bmp388 handle structure definition
uint8_t bmp388_set_pressure_oversampling(bmp388_handle_t *handle, bmp388_oversampling_t oversampling)
set the pressure oversampling
uint8_t bmp388_set_temperature(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the temperature
uint8_t bmp388_set_filter_coefficient(bmp388_handle_t *handle, bmp388_filter_coefficient_t coefficient)
set the filter coefficient
uint8_t bmp388_deinit(bmp388_handle_t *handle)
close the chip
uint8_t bmp388_set_interface(bmp388_handle_t *handle, bmp388_interface_t interface)
set the interface
uint8_t bmp388_set_iic_watchdog_period(bmp388_handle_t *handle, bmp388_iic_watchdog_period_t period)
set the iic watchdog period
uint8_t bmp388_read_temperature_pressure(bmp388_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa)
read the temperature and pressure
uint8_t bmp388_set_mode(bmp388_handle_t *handle, bmp388_mode_t mode)
set the chip mode
uint8_t bmp388_set_temperature_oversampling(bmp388_handle_t *handle, bmp388_oversampling_t oversampling)
set the temperature oversampling
uint8_t bmp388_set_addr_pin(bmp388_handle_t *handle, bmp388_address_t addr_pin)
set the iic address pin
struct bmp388_info_s bmp388_info_t
bmp388 information structure definition
uint8_t bmp388_info(bmp388_info_t *info)
get chip's information
bmp388_address_t
bmp388 address enumeration definition
@ BMP388_OVERSAMPLING_x32
@ BMP388_OVERSAMPLING_x2
@ BMP388_SPI_WIRE_4
@ BMP388_FILTER_COEFFICIENT_15
@ BMP388_ODR_12P5_HZ
@ BMP388_INTERRUPT_ACTIVE_LEVEL_HIGHER
@ BMP388_BOOL_TRUE
@ BMP388_BOOL_FALSE
@ BMP388_FIFO_DATA_SOURCE_FILTERED
@ BMP388_MODE_SLEEP_MODE
@ BMP388_MODE_NORMAL_MODE
@ BMP388_MODE_FORCED_MODE
@ BMP388_INTERRUPT_PIN_TYPE_PUSH_PULL
@ BMP388_IIC_WATCHDOG_PERIOD_40_MS
uint8_t bmp388_set_fifo_temperature_on(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo temperature on
uint8_t bmp388_set_fifo_watermark(bmp388_handle_t *handle, uint16_t watermark)
set the fifo watermark
uint8_t bmp388_set_fifo_subsampling(bmp388_handle_t *handle, uint8_t subsample)
set the fifo subsampling
uint8_t bmp388_set_fifo_data_source(bmp388_handle_t *handle, bmp388_fifo_data_source_t source)
set the fifo data source
uint8_t bmp388_set_fifo_stop_on_full(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo stopping on full
uint8_t bmp388_set_fifo_sensortime_on(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo sensor time on
uint8_t bmp388_set_fifo_pressure_on(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo pressure on
uint8_t bmp388_set_fifo(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo
uint8_t bmp388_interface_spi_init(void)
interface spi bus init
void bmp388_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t bmp388_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void bmp388_interface_receive_callback(uint8_t type)
interface receive callback
uint8_t bmp388_interface_iic_deinit(void)
interface iic bus deinit
uint8_t bmp388_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t bmp388_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void bmp388_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t bmp388_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t bmp388_interface_spi_deinit(void)
interface spi bus deinit
uint8_t bmp388_interface_iic_init(void)
interface iic bus init
uint8_t bmp388_set_interrupt_fifo_full(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo full interrupt
uint8_t bmp388_set_interrupt_fifo_watermark(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo watermark interrupt
uint8_t bmp388_set_interrupt_data_ready(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the data ready interrupt
uint8_t bmp388_set_interrupt_active_level(bmp388_handle_t *handle, bmp388_interrupt_active_level_t level)
set the interrupt active level
uint8_t bmp388_set_interrupt_pin_type(bmp388_handle_t *handle, bmp388_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t bmp388_set_latch_interrupt_pin_and_interrupt_status(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable latching interrupt pin and interrupt status
uint8_t bmp388_read_test(bmp388_interface_t interface, bmp388_address_t addr_pin, uint32_t times)
read test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]