LibDriver BMP388
Loading...
Searching...
No Matches
driver_bmp388_interrupt_test.c
Go to the documentation of this file.
1
37
39
40static bmp388_handle_t gs_handle;
41static volatile uint8_t gs_data_ready_flag;
42static float gs_temperature_c;
43static float gs_pressure_pa;
44
53{
54 /* run irq handler */
55 if (bmp388_irq_handler(&gs_handle) != 0)
56 {
57 return 1;
58 }
59 else
60 {
61 return 0;
62 }
63}
64
70static void a_bmp388_interface_test_receive_callback(uint8_t type)
71{
72 switch (type)
73 {
75 {
76 break;
77 }
79 {
80 break;
81 }
83 {
84 uint32_t temperature_raw;
85 uint32_t pressure_raw;
86
87 /* read temperature pressure */
88 if (bmp388_read_temperature_pressure(&gs_handle, (uint32_t *)&temperature_raw, (float *)&gs_temperature_c,
89 (uint32_t *)&pressure_raw, (float *)&gs_pressure_pa) != 0)
90 {
91 bmp388_interface_debug_print("bmp388: read temperature and pressure failed.\n");
92
93 return;
94 }
95 gs_data_ready_flag = 1;
96
97 break;
98 }
99 default :
100 {
101 break;
102 }
103 }
104}
105
116uint8_t bmp388_interrupt_test(bmp388_interface_t interface, bmp388_address_t addr_pin, uint32_t times)
117{
118 uint8_t res;
119 uint32_t i;
120 bmp388_info_t info;
121
122 /* link functions */
134 DRIVER_BMP388_LINK_RECEIVE_CALLBACK(&gs_handle, a_bmp388_interface_test_receive_callback);
135
136 /* bmp388 info */
137 res = bmp388_info(&info);
138 if (res != 0)
139 {
140 bmp388_interface_debug_print("bmp388: get info failed.\n");
141
142 return 1;
143 }
144 else
145 {
146 /* print chip information */
147 bmp388_interface_debug_print("bmp388: chip is %s.\n", info.chip_name);
148 bmp388_interface_debug_print("bmp388: manufacturer is %s.\n", info.manufacturer_name);
149 bmp388_interface_debug_print("bmp388: interface is %s.\n", info.interface);
150 bmp388_interface_debug_print("bmp388: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
151 bmp388_interface_debug_print("bmp388: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
152 bmp388_interface_debug_print("bmp388: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
153 bmp388_interface_debug_print("bmp388: max current is %0.2fmA.\n", info.max_current_ma);
154 bmp388_interface_debug_print("bmp388: max temperature is %0.1fC.\n", info.temperature_max);
155 bmp388_interface_debug_print("bmp388: min temperature is %0.1fC.\n", info.temperature_min);
156 }
157
158 /* start interrupt test */
159 bmp388_interface_debug_print("bmp388: start interrupt test.\n");
160
161 /* set interface */
162 res = bmp388_set_interface(&gs_handle, interface);
163 if (res != 0)
164 {
165 bmp388_interface_debug_print("bmp388: set interface failed.\n");
166
167 return 1;
168 }
169
170 /* set addr pin */
171 res = bmp388_set_addr_pin(&gs_handle, addr_pin);
172 if (res != 0)
173 {
174 bmp388_interface_debug_print("bmp388: set addr pin failed.\n");
175
176 return 1;
177 }
178
179 /* bmp388 init */
180 res = bmp388_init(&gs_handle);
181 if (res != 0)
182 {
183 bmp388_interface_debug_print("bmp388: init failed.\n");
184
185 return 1;
186 }
187
188 /* set spi wire 4 */
189 res = bmp388_set_spi_wire(&gs_handle, BMP388_SPI_WIRE_4);
190 if (res != 0)
191 {
192 bmp388_interface_debug_print("bmp388: set spi wire failed.\n");
193 (void)bmp388_deinit(&gs_handle);
194
195 return 1;
196 }
197
198 /* enable iic watchdog timer */
200 if (res != 0)
201 {
202 bmp388_interface_debug_print("bmp388: set iic watchdog timer failed.\n");
203 (void)bmp388_deinit(&gs_handle);
204
205 return 1;
206 }
207
208 /* set iic watchdog period */
210 if (res != 0)
211 {
212 bmp388_interface_debug_print("bmp388: set iic watchdog period failed.\n");
213 (void)bmp388_deinit(&gs_handle);
214
215 return 1;
216 }
217
218 /* disable fifo */
219 res = bmp388_set_fifo(&gs_handle, BMP388_BOOL_FALSE);
220 if (res != 0)
221 {
222 bmp388_interface_debug_print("bmp388: set fifo failed.\n");
223 (void)bmp388_deinit(&gs_handle);
224
225 return 1;
226 }
227
228 /* disable fifo stop on full */
230 if (res != 0)
231 {
232 bmp388_interface_debug_print("bmp388: set fifo stop on full failed.\n");
233 (void)bmp388_deinit(&gs_handle);
234
235 return 1;
236 }
237
238 /* set fifo watermark 256 */
239 res = bmp388_set_fifo_watermark(&gs_handle, 256);
240 if (res != 0)
241 {
242 bmp388_interface_debug_print("bmp388: set fifo watermark failed.\n");
243 (void)bmp388_deinit(&gs_handle);
244
245 return 1;
246 }
247
248 /* enable fifo sensor time on */
250 if (res != 0)
251 {
252 bmp388_interface_debug_print("bmp388: set fifo sensor time on failed.\n");
253 (void)bmp388_deinit(&gs_handle);
254
255 return 1;
256 }
257
258 /* enable fifo sensor time on */
260 if (res != 0)
261 {
262 bmp388_interface_debug_print("bmp388: set fifo sensor time on failed.\n");
263 (void)bmp388_deinit(&gs_handle);
264
265 return 1;
266 }
267
268 /* set fifo temperature on */
270 if (res != 0)
271 {
272 bmp388_interface_debug_print("bmp388: set fifo temperature on failed.\n");
273 (void)bmp388_deinit(&gs_handle);
274
275 return 1;
276 }
277
278 /* set fifo subsampling 0 */
279 res = bmp388_set_fifo_subsampling(&gs_handle, 0);
280 if (res != 0)
281 {
282 bmp388_interface_debug_print("bmp388: set fifo subsampling failed.\n");
283 (void)bmp388_deinit(&gs_handle);
284
285 return 1;
286 }
287
288 /* set fifo data source filtered */
290 if (res != 0)
291 {
292 bmp388_interface_debug_print("bmp388: set fifo data source failed.\n");
293 (void)bmp388_deinit(&gs_handle);
294
295 return 1;
296 }
297
298 /* set interrupt pin type push pull */
300 if (res != 0)
301 {
302 bmp388_interface_debug_print("bmp388: set interrupt pin type failed.\n");
303 (void)bmp388_deinit(&gs_handle);
304
305 return 1;
306 }
307
308 /* set interrupt active level higher */
310 if (res != 0)
311 {
312 bmp388_interface_debug_print("bmp388: set interrupt active level failed.\n");
313 (void)bmp388_deinit(&gs_handle);
314
315 return 1;
316 }
317
318 /* disable latch interrupt pin and interrupt status */
320 if (res != 0)
321 {
322 bmp388_interface_debug_print("bmp388: set set latch interrupt pin and interrupt status failed.\n");
323 (void)bmp388_deinit(&gs_handle);
324
325 return 1;
326 }
327
328 /* enable interrupt fifo watermark */
330 if (res != 0)
331 {
332 bmp388_interface_debug_print("bmp388: set interrupt fifo watermark failed.\n");
333 (void)bmp388_deinit(&gs_handle);
334
335 return 1;
336 }
337
338 /* enable interrupt fifo full */
340 if (res != 0)
341 {
342 bmp388_interface_debug_print("bmp388: set interrupt fifo full failed.\n");
343 (void)bmp388_deinit(&gs_handle);
344
345 return 1;
346 }
347
348 /* enable interrupt data ready */
350 if (res != 0)
351 {
352 bmp388_interface_debug_print("bmp388: set interrupt data ready failed.\n");
353 (void)bmp388_deinit(&gs_handle);
354
355 return 1;
356 }
357
358 /* enable pressure */
359 res = bmp388_set_pressure(&gs_handle, BMP388_BOOL_TRUE);
360 if (res != 0)
361 {
362 bmp388_interface_debug_print("bmp388: set pressure failed.\n");
363 (void)bmp388_deinit(&gs_handle);
364
365 return 1;
366 }
367
368 /* enable temperature */
369 res = bmp388_set_temperature(&gs_handle, BMP388_BOOL_TRUE);
370 if (res != 0)
371 {
372 bmp388_interface_debug_print("bmp388: set temperature failed.\n");
373 (void)bmp388_deinit(&gs_handle);
374
375 return 1;
376 }
377
378 /* set pressure oversampling x32 */
380 if (res != 0)
381 {
382 bmp388_interface_debug_print("bmp388: set pressure oversampling failed.\n");
383 (void)bmp388_deinit(&gs_handle);
384
385 return 1;
386 }
387
388 /* set temperature oversampling x2 */
390 if (res != 0)
391 {
392 bmp388_interface_debug_print("bmp388: set temperature oversampling failed.\n");
393 (void)bmp388_deinit(&gs_handle);
394
395 return 1;
396 }
397
398 /* set odr 12.5Hz */
399 res = bmp388_set_odr(&gs_handle, BMP388_ODR_12P5_HZ);
400 if (res != 0)
401 {
402 bmp388_interface_debug_print("bmp388: set odr failed.\n");
403 (void)bmp388_deinit(&gs_handle);
404
405 return 1;
406 }
407
408 /* set filter coefficient 15 */
410 if (res != 0)
411 {
412 bmp388_interface_debug_print("bmp388: set filter coefficient failed.\n");
413 (void)bmp388_deinit(&gs_handle);
414
415 return 1;
416 }
417
418 /* set normal mode */
419 res = bmp388_set_mode(&gs_handle, BMP388_MODE_NORMAL_MODE);
420 if (res != 0)
421 {
422 bmp388_interface_debug_print("bmp388: set mode failed.\n");
423 (void)bmp388_deinit(&gs_handle);
424
425 return 1;
426 }
427 for (i = 0; i < times; i++)
428 {
429 gs_data_ready_flag = 0;
431 bmp388_interface_debug_print("bmp388: temperature is %0.2fC.\n", gs_temperature_c);
432 bmp388_interface_debug_print("bmp388: pressure is %0.2fPa.\n", gs_pressure_pa);
433
434 /* check data ready flag */
435 if (gs_data_ready_flag == 0)
436 {
437 bmp388_interface_debug_print("bmp388: interrupt failed.\n");
438 (void)bmp388_deinit(&gs_handle);
439
440 return 1;
441 }
443 }
444
445 /* finish interrupt test */
446 bmp388_interface_debug_print("bmp388: finish interrupt test.\n");
447 (void)bmp388_deinit(&gs_handle);
448
449 return 0;
450}
driver bmp388 interrupt 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_irq_handler(bmp388_handle_t *handle)
irq handler
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_INTERRUPT_STATUS_FIFO_FULL
@ BMP388_INTERRUPT_STATUS_DATA_READY
@ BMP388_INTERRUPT_STATUS_FIFO_WATERMARK
@ BMP388_FIFO_DATA_SOURCE_FILTERED
@ BMP388_MODE_NORMAL_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
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_interrupt_test(bmp388_interface_t interface, bmp388_address_t addr_pin, uint32_t times)
interrupt test
uint8_t bmp388_interrupt_test_irq_handler(void)
interrupt test irq handler
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]