LibDriver BMP384
Loading...
Searching...
No Matches
driver_bmp384_interrupt_test.c
Go to the documentation of this file.
1
36
38
39static bmp384_handle_t gs_handle;
40static volatile uint8_t gs_data_ready_flag;
41static float gs_temperature_c;
42static float gs_pressure_pa;
43
52{
53 /* run irq handler */
54 if (bmp384_irq_handler(&gs_handle) != 0)
55 {
56 return 1;
57 }
58 else
59 {
60 return 0;
61 }
62}
63
69static void a_bmp384_interface_test_receive_callback(uint8_t type)
70{
71 switch (type)
72 {
74 {
75 break;
76 }
78 {
79 break;
80 }
82 {
83 uint32_t temperature_raw;
84 uint32_t pressure_raw;
85
86 /* read temperature pressure */
87 if (bmp384_read_temperature_pressure(&gs_handle, (uint32_t *)&temperature_raw, (float *)&gs_temperature_c,
88 (uint32_t *)&pressure_raw, (float *)&gs_pressure_pa) != 0)
89 {
90 bmp384_interface_debug_print("bmp384: read temperature and pressure failed.\n");
91
92 return;
93 }
94 gs_data_ready_flag = 1;
95
96 break;
97 }
98 default :
99 {
100 break;
101 }
102 }
103}
104
115uint8_t bmp384_interrupt_test(bmp384_interface_t interface, bmp384_address_t addr_pin, uint32_t times)
116{
117 uint8_t res;
118 uint32_t i;
119 bmp384_info_t info;
120
121 /* link functions */
133 DRIVER_BMP384_LINK_RECEIVE_CALLBACK(&gs_handle, a_bmp384_interface_test_receive_callback);
134
135 /* bmp384 info */
136 res = bmp384_info(&info);
137 if (res != 0)
138 {
139 bmp384_interface_debug_print("bmp384: get info failed.\n");
140
141 return 1;
142 }
143 else
144 {
145 /* print chip information */
146 bmp384_interface_debug_print("bmp384: chip is %s.\n", info.chip_name);
147 bmp384_interface_debug_print("bmp384: manufacturer is %s.\n", info.manufacturer_name);
148 bmp384_interface_debug_print("bmp384: interface is %s.\n", info.interface);
149 bmp384_interface_debug_print("bmp384: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
150 bmp384_interface_debug_print("bmp384: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
151 bmp384_interface_debug_print("bmp384: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
152 bmp384_interface_debug_print("bmp384: max current is %0.2fmA.\n", info.max_current_ma);
153 bmp384_interface_debug_print("bmp384: max temperature is %0.1fC.\n", info.temperature_max);
154 bmp384_interface_debug_print("bmp384: min temperature is %0.1fC.\n", info.temperature_min);
155 }
156
157 /* start interrupt test */
158 bmp384_interface_debug_print("bmp384: start interrupt test.\n");
159
160 /* set interface */
161 res = bmp384_set_interface(&gs_handle, interface);
162 if (res != 0)
163 {
164 bmp384_interface_debug_print("bmp384: set interface failed.\n");
165
166 return 1;
167 }
168
169 /* set addr pin */
170 res = bmp384_set_addr_pin(&gs_handle, addr_pin);
171 if (res != 0)
172 {
173 bmp384_interface_debug_print("bmp384: set addr pin failed.\n");
174
175 return 1;
176 }
177
178 /* bmp384 init */
179 res = bmp384_init(&gs_handle);
180 if (res != 0)
181 {
182 bmp384_interface_debug_print("bmp384: init failed.\n");
183
184 return 1;
185 }
186
187 /* set spi wire 4 */
188 res = bmp384_set_spi_wire(&gs_handle, BMP384_SPI_WIRE_4);
189 if (res != 0)
190 {
191 bmp384_interface_debug_print("bmp384: set spi wire failed.\n");
192 (void)bmp384_deinit(&gs_handle);
193
194 return 1;
195 }
196
197 /* enable iic watchdog timer */
199 if (res != 0)
200 {
201 bmp384_interface_debug_print("bmp384: set iic watchdog timer failed.\n");
202 (void)bmp384_deinit(&gs_handle);
203
204 return 1;
205 }
206
207 /* set iic watchdog period */
209 if (res != 0)
210 {
211 bmp384_interface_debug_print("bmp384: set iic watchdog period failed.\n");
212 (void)bmp384_deinit(&gs_handle);
213
214 return 1;
215 }
216
217 /* disable fifo */
218 res = bmp384_set_fifo(&gs_handle, BMP384_BOOL_FALSE);
219 if (res != 0)
220 {
221 bmp384_interface_debug_print("bmp384: set fifo failed.\n");
222 (void)bmp384_deinit(&gs_handle);
223
224 return 1;
225 }
226
227 /* disable fifo stop on full */
229 if (res != 0)
230 {
231 bmp384_interface_debug_print("bmp384: set fifo stop on full failed.\n");
232 (void)bmp384_deinit(&gs_handle);
233
234 return 1;
235 }
236
237 /* set fifo watermark 256 */
238 res = bmp384_set_fifo_watermark(&gs_handle, 256);
239 if (res != 0)
240 {
241 bmp384_interface_debug_print("bmp384: set fifo watermark failed.\n");
242 (void)bmp384_deinit(&gs_handle);
243
244 return 1;
245 }
246
247 /* enable fifo sensor time on */
249 if (res != 0)
250 {
251 bmp384_interface_debug_print("bmp384: set fifo sensor time on failed.\n");
252 (void)bmp384_deinit(&gs_handle);
253
254 return 1;
255 }
256
257 /* enable fifo sensor time on */
259 if (res != 0)
260 {
261 bmp384_interface_debug_print("bmp384: set fifo sensor time on failed.\n");
262 (void)bmp384_deinit(&gs_handle);
263
264 return 1;
265 }
266
267 /* set fifo temperature on */
269 if (res != 0)
270 {
271 bmp384_interface_debug_print("bmp384: set fifo temperature on failed.\n");
272 (void)bmp384_deinit(&gs_handle);
273
274 return 1;
275 }
276
277 /* set fifo subsampling 0 */
278 res = bmp384_set_fifo_subsampling(&gs_handle, 0);
279 if (res != 0)
280 {
281 bmp384_interface_debug_print("bmp384: set fifo subsampling failed.\n");
282 (void)bmp384_deinit(&gs_handle);
283
284 return 1;
285 }
286
287 /* set fifo data source filtered */
289 if (res != 0)
290 {
291 bmp384_interface_debug_print("bmp384: set fifo data source failed.\n");
292 (void)bmp384_deinit(&gs_handle);
293
294 return 1;
295 }
296
297 /* set interrupt pin type push pull */
299 if (res != 0)
300 {
301 bmp384_interface_debug_print("bmp384: set interrupt pin type failed.\n");
302 (void)bmp384_deinit(&gs_handle);
303
304 return 1;
305 }
306
307 /* set interrupt active level higher */
309 if (res != 0)
310 {
311 bmp384_interface_debug_print("bmp384: set interrupt active level failed.\n");
312 (void)bmp384_deinit(&gs_handle);
313
314 return 1;
315 }
316
317 /* disable latch interrupt pin and interrupt status */
319 if (res != 0)
320 {
321 bmp384_interface_debug_print("bmp384: set set latch interrupt pin and interrupt status failed.\n");
322 (void)bmp384_deinit(&gs_handle);
323
324 return 1;
325 }
326
327 /* enable interrupt fifo watermark */
329 if (res != 0)
330 {
331 bmp384_interface_debug_print("bmp384: set interrupt fifo watermark failed.\n");
332 (void)bmp384_deinit(&gs_handle);
333
334 return 1;
335 }
336
337 /* enable interrupt fifo full */
339 if (res != 0)
340 {
341 bmp384_interface_debug_print("bmp384: set interrupt fifo full failed.\n");
342 (void)bmp384_deinit(&gs_handle);
343
344 return 1;
345 }
346
347 /* enable interrupt data ready */
349 if (res != 0)
350 {
351 bmp384_interface_debug_print("bmp384: set interrupt data ready failed.\n");
352 (void)bmp384_deinit(&gs_handle);
353
354 return 1;
355 }
356
357 /* enable pressure */
358 res = bmp384_set_pressure(&gs_handle, BMP384_BOOL_TRUE);
359 if (res != 0)
360 {
361 bmp384_interface_debug_print("bmp384: set pressure failed.\n");
362 (void)bmp384_deinit(&gs_handle);
363
364 return 1;
365 }
366
367 /* enable temperature */
368 res = bmp384_set_temperature(&gs_handle, BMP384_BOOL_TRUE);
369 if (res != 0)
370 {
371 bmp384_interface_debug_print("bmp384: set temperature failed.\n");
372 (void)bmp384_deinit(&gs_handle);
373
374 return 1;
375 }
376
377 /* set pressure oversampling x32 */
379 if (res != 0)
380 {
381 bmp384_interface_debug_print("bmp384: set pressure oversampling failed.\n");
382 (void)bmp384_deinit(&gs_handle);
383
384 return 1;
385 }
386
387 /* set temperature oversampling x2 */
389 if (res != 0)
390 {
391 bmp384_interface_debug_print("bmp384: set temperature oversampling failed.\n");
392 (void)bmp384_deinit(&gs_handle);
393
394 return 1;
395 }
396
397 /* set odr 12.5Hz */
398 res = bmp384_set_odr(&gs_handle, BMP384_ODR_12P5_HZ);
399 if (res != 0)
400 {
401 bmp384_interface_debug_print("bmp384: set odr failed.\n");
402 (void)bmp384_deinit(&gs_handle);
403
404 return 1;
405 }
406
407 /* set filter coefficient 15 */
409 if (res != 0)
410 {
411 bmp384_interface_debug_print("bmp384: set filter coefficient failed.\n");
412 (void)bmp384_deinit(&gs_handle);
413
414 return 1;
415 }
416
417 /* set normal mode */
418 res = bmp384_set_mode(&gs_handle, BMP384_MODE_NORMAL_MODE);
419 if (res != 0)
420 {
421 bmp384_interface_debug_print("bmp384: set mode failed.\n");
422 (void)bmp384_deinit(&gs_handle);
423
424 return 1;
425 }
426 for (i = 0; i < times; i++)
427 {
428 gs_data_ready_flag = 0;
430 bmp384_interface_debug_print("bmp384: temperature is %0.2fC.\n", gs_temperature_c);
431 bmp384_interface_debug_print("bmp384: pressure is %0.2fPa.\n", gs_pressure_pa);
432
433 /* check data ready flag */
434 if (gs_data_ready_flag == 0)
435 {
436 bmp384_interface_debug_print("bmp384: interrupt failed.\n");
437 (void)bmp384_deinit(&gs_handle);
438
439 return 1;
440 }
442 }
443
444 /* finish interrupt test */
445 bmp384_interface_debug_print("bmp384: finish interrupt test.\n");
446 (void)bmp384_deinit(&gs_handle);
447
448 return 0;
449}
driver bmp384 interrupt test 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_deinit(bmp384_handle_t *handle)
close the chip
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_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
uint8_t bmp384_set_pressure_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t oversampling)
set the pressure oversampling
uint8_t bmp384_set_iic_watchdog_timer(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the iic watchdog timer
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
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
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_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
@ BMP384_MODE_NORMAL_MODE
@ BMP384_FIFO_DATA_SOURCE_FILTERED
@ BMP384_SPI_WIRE_4
@ BMP384_BOOL_TRUE
@ BMP384_BOOL_FALSE
@ BMP384_INTERRUPT_STATUS_FIFO_WATERMARK
@ BMP384_INTERRUPT_STATUS_FIFO_FULL
@ BMP384_INTERRUPT_STATUS_DATA_READY
@ BMP384_INTERRUPT_PIN_TYPE_PUSH_PULL
@ BMP384_ODR_12P5_HZ
@ BMP384_FILTER_COEFFICIENT_15
@ BMP384_IIC_WATCHDOG_PERIOD_40_MS
@ BMP384_OVERSAMPLING_x32
@ BMP384_OVERSAMPLING_x2
@ BMP384_INTERRUPT_ACTIVE_LEVEL_HIGHER
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_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_set_fifo(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable 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_set_fifo_watermark(bmp384_handle_t *handle, uint16_t watermark)
set the fifo watermark
uint8_t bmp384_set_fifo_subsampling(bmp384_handle_t *handle, uint8_t subsample)
set the fifo subsampling
uint8_t bmp384_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void bmp384_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t bmp384_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
void bmp384_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t bmp384_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t bmp384_interface_iic_init(void)
interface iic bus init
uint8_t bmp384_interface_spi_init(void)
interface spi bus init
uint8_t bmp384_interface_spi_deinit(void)
interface spi bus deinit
uint8_t bmp384_interface_iic_deinit(void)
interface iic bus deinit
uint8_t bmp384_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
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_set_interrupt_active_level(bmp384_handle_t *handle, bmp384_interrupt_active_level_t level)
set the interrupt active level
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_set_interrupt_fifo_full(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo full interrupt
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_interrupt_test(bmp384_interface_t interface, bmp384_address_t addr_pin, uint32_t times)
interrupt test
uint8_t bmp384_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]