LibDriver BMP390
Loading...
Searching...
No Matches
driver_bmp390_read_test.c
Go to the documentation of this file.
1
36
38
39static bmp390_handle_t gs_handle;
40
51uint8_t bmp390_read_test(bmp390_interface_t interface, bmp390_address_t addr_pin, uint32_t times)
52{
53 uint8_t res;
54 uint32_t i;
55 bmp390_info_t info;
56
57 /* link functions */
70
71 /* bmp390 info */
72 res = bmp390_info(&info);
73 if (res != 0)
74 {
75 bmp390_interface_debug_print("bmp390: get info failed.\n");
76
77 return 1;
78 }
79 else
80 {
81 /* print chip information */
82 bmp390_interface_debug_print("bmp390: chip is %s.\n", info.chip_name);
83 bmp390_interface_debug_print("bmp390: manufacturer is %s.\n", info.manufacturer_name);
84 bmp390_interface_debug_print("bmp390: interface is %s.\n", info.interface);
85 bmp390_interface_debug_print("bmp390: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
86 bmp390_interface_debug_print("bmp390: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
87 bmp390_interface_debug_print("bmp390: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
88 bmp390_interface_debug_print("bmp390: max current is %0.2fmA.\n", info.max_current_ma);
89 bmp390_interface_debug_print("bmp390: max temperature is %0.1fC.\n", info.temperature_max);
90 bmp390_interface_debug_print("bmp390: min temperature is %0.1fC.\n", info.temperature_min);
91 }
92
93 /* start read test */
94 bmp390_interface_debug_print("bmp390: start read test.\n");
95 res = bmp390_set_interface(&gs_handle, interface);
96 if (res != 0)
97 {
98 bmp390_interface_debug_print("bmp390: set interface failed.\n");
99
100 return 1;
101 }
102
103 /* set addr pin */
104 res = bmp390_set_addr_pin(&gs_handle, addr_pin);
105 if (res != 0)
106 {
107 bmp390_interface_debug_print("bmp390: set addr pin failed.\n");
108
109 return 1;
110 }
111
112 /* bmp390 init */
113 res = bmp390_init(&gs_handle);
114 if (res != 0)
115 {
116 bmp390_interface_debug_print("bmp390: init failed.\n");
117
118 return 1;
119 }
120
121 /* set spi wire 4 */
122 res = bmp390_set_spi_wire(&gs_handle, BMP390_SPI_WIRE_4);
123 if (res != 0)
124 {
125 bmp390_interface_debug_print("bmp390: set spi wire failed.\n");
126 (void)bmp390_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 /* enable iic watchdog timer */
133 if (res != 0)
134 {
135 bmp390_interface_debug_print("bmp390: set iic watchdog timer failed.\n");
136 (void)bmp390_deinit(&gs_handle);
137
138 return 1;
139 }
140
141 /* set iic watchdog period 40 ms */
143 if (res != 0)
144 {
145 bmp390_interface_debug_print("bmp390: set iic watchdog period failed.\n");
146 (void)bmp390_deinit(&gs_handle);
147
148 return 1;
149 }
150
151 /* disable fifo */
152 res = bmp390_set_fifo(&gs_handle, BMP390_BOOL_FALSE);
153 if (res != 0)
154 {
155 bmp390_interface_debug_print("bmp390: set fifo failed.\n");
156 (void)bmp390_deinit(&gs_handle);
157
158 return 1;
159 }
160
161 /* disable fifo stop on full */
163 if (res != 0)
164 {
165 bmp390_interface_debug_print("bmp390: set fifo stop on full failed.\n");
166 (void)bmp390_deinit(&gs_handle);
167
168 return 1;
169 }
170
171 /* set fifo watermark 256 */
172 res = bmp390_set_fifo_watermark(&gs_handle, 256);
173 if (res != 0)
174 {
175 bmp390_interface_debug_print("bmp390: set fifo watermark failed.\n");
176 (void)bmp390_deinit(&gs_handle);
177
178 return 1;
179 }
180
181 /* enable fifo sensor time on */
183 if (res != 0)
184 {
185 bmp390_interface_debug_print("bmp390: set fifo sensor time on failed.\n");
186 (void)bmp390_deinit(&gs_handle);
187
188 return 1;
189 }
190
191 /* enable fifo pressure on */
193 if (res != 0)
194 {
195 bmp390_interface_debug_print("bmp390: set fifo sensor time on failed.\n");
196 (void)bmp390_deinit(&gs_handle);
197
198 return 1;
199 }
200
201 /* enable fifo temperature on */
203 if (res != 0)
204 {
205 bmp390_interface_debug_print("bmp390: set fifo temperature on failed.\n");
206 (void)bmp390_deinit(&gs_handle);
207
208 return 1;
209 }
210
211 /* set fifo subsampling 0 */
212 res = bmp390_set_fifo_subsampling(&gs_handle, 0);
213 if (res != 0)
214 {
215 bmp390_interface_debug_print("bmp390: set fifo subsampling failed.\n");
216 (void)bmp390_deinit(&gs_handle);
217
218 return 1;
219 }
220
221 /* set fifo data source filtered */
223 if (res != 0)
224 {
225 bmp390_interface_debug_print("bmp390: set fifo data source failed.\n");
226 (void)bmp390_deinit(&gs_handle);
227
228 return 1;
229 }
230
231 /* set interrupt pin type push pull */
233 if (res != 0)
234 {
235 bmp390_interface_debug_print("bmp390: set interrupt pin type failed.\n");
236 (void)bmp390_deinit(&gs_handle);
237
238 return 1;
239 }
240
241 /* set interrupt active level higher */
243 if (res != 0)
244 {
245 bmp390_interface_debug_print("bmp390: set interrupt active level failed.\n");
246 (void)bmp390_deinit(&gs_handle);
247
248 return 1;
249 }
250
251 /* enable latch interrupt pin and interrupt status */
253 if (res != 0)
254 {
255 bmp390_interface_debug_print("bmp390: set set latch interrupt pin and interrupt status failed.\n");
256 (void)bmp390_deinit(&gs_handle);
257
258 return 1;
259 }
260
261 /* enable interrupt fifo watermark */
263 if (res != 0)
264 {
265 bmp390_interface_debug_print("bmp390: set interrupt fifo watermark failed.\n");
266 (void)bmp390_deinit(&gs_handle);
267
268 return 1;
269 }
270
271 /* enable interrupt fifo full */
273 if (res != 0)
274 {
275 bmp390_interface_debug_print("bmp390: set interrupt fifo full failed.\n");
276 (void)bmp390_deinit(&gs_handle);
277
278 return 1;
279 }
280
281 /* disable interrupt data ready */
283 if (res != 0)
284 {
285 bmp390_interface_debug_print("bmp390: set interrupt data ready failed.\n");
286 (void)bmp390_deinit(&gs_handle);
287
288 return 1;
289 }
290
291 /* enable pressure */
292 res = bmp390_set_pressure(&gs_handle, BMP390_BOOL_TRUE);
293 if (res != 0)
294 {
295 bmp390_interface_debug_print("bmp390: set pressure failed.\n");
296 (void)bmp390_deinit(&gs_handle);
297
298 return 1;
299 }
300
301 /* enable temperature */
302 res = bmp390_set_temperature(&gs_handle, BMP390_BOOL_TRUE);
303 if (res != 0)
304 {
305 bmp390_interface_debug_print("bmp390: set temperature failed.\n");
306 (void)bmp390_deinit(&gs_handle);
307
308 return 1;
309 }
310
311 /* set pressure oversampling x32 */
313 if (res != 0)
314 {
315 bmp390_interface_debug_print("bmp390: set pressure oversampling failed.\n");
316 (void)bmp390_deinit(&gs_handle);
317
318 return 1;
319 }
320
321 /* set temperature oversampling x2 */
323 if (res != 0)
324 {
325 bmp390_interface_debug_print("bmp390: set temperature oversampling failed.\n");
326 (void)bmp390_deinit(&gs_handle);
327
328 return 1;
329 }
330
331 /* set odr 12.5Hz */
332 res = bmp390_set_odr(&gs_handle, BMP390_ODR_12P5_HZ);
333 if (res != 0)
334 {
335 bmp390_interface_debug_print("bmp390: set odr failed.\n");
336 (void)bmp390_deinit(&gs_handle);
337
338 return 1;
339 }
340
341 /* set filter coefficient 15 */
343 if (res != 0)
344 {
345 bmp390_interface_debug_print("bmp390: set filter coefficient failed.\n");
346 (void)bmp390_deinit(&gs_handle);
347
348 return 1;
349 }
350
351 /* start forced mode read test */
352 bmp390_interface_debug_print("bmp390: forced mode read test.\n");
353
354 /* set forced mode */
355 res = bmp390_set_mode(&gs_handle, BMP390_MODE_FORCED_MODE);
356 if (res != 0)
357 {
358 bmp390_interface_debug_print("bmp390: set mode failed.\n");
359 (void)bmp390_deinit(&gs_handle);
360
361 return 1;
362 }
364 for (i = 0; i < times; i++)
365 {
366 uint32_t temperature_raw;
367 uint32_t pressure_raw;
368 float temperature_c;
369 float pressure_pa;
370
371 /* read temperature pressure */
372 if (bmp390_read_temperature_pressure(&gs_handle, (uint32_t *)&temperature_raw, (float *)&temperature_c,
373 (uint32_t *)&pressure_raw, (float *)&pressure_pa) != 0)
374 {
375 bmp390_interface_debug_print("bmp390: read temperature and pressure failed.\n");
376 (void)bmp390_deinit(&gs_handle);
377
378 return 1;
379 }
380 bmp390_interface_debug_print("bmp390: temperature is %0.2fC.\n", temperature_c);
381 bmp390_interface_debug_print("bmp390: pressure is %0.2fPa.\n", pressure_pa);
383 }
384
385 /* start normal mode read */
386 bmp390_interface_debug_print("bmp390: normal mode read test.\n");
387 res = bmp390_set_mode(&gs_handle, BMP390_MODE_SLEEP_MODE);
388 if (res != 0)
389 {
390 bmp390_interface_debug_print("bmp390: set mode failed.\n");
391 (void)bmp390_deinit(&gs_handle);
392
393 return 1;
394 }
396
397 /* set normal mode */
398 res = bmp390_set_mode(&gs_handle, BMP390_MODE_NORMAL_MODE);
399 if (res != 0)
400 {
401 bmp390_interface_debug_print("bmp390: set mode failed.\n");
402 (void)bmp390_deinit(&gs_handle);
403
404 return 1;
405 }
407 for (i = 0; i < times; i++)
408 {
409 uint32_t temperature_raw;
410 uint32_t pressure_raw;
411 float temperature_c;
412 float pressure_pa;
413
414 /* read temperature pressure */
415 if (bmp390_read_temperature_pressure(&gs_handle, (uint32_t *)&temperature_raw, (float *)&temperature_c,
416 (uint32_t *)&pressure_raw, (float *)&pressure_pa) != 0)
417 {
418 bmp390_interface_debug_print("bmp390: read temperature and pressure failed.\n");
419 (void)bmp390_deinit(&gs_handle);
420
421 return 1;
422 }
423 bmp390_interface_debug_print("bmp390: temperature is %0.2fC.\n", temperature_c);
424 bmp390_interface_debug_print("bmp390: pressure is %0.2fPa.\n", pressure_pa);
426 }
427
428 /* finish read test */
429 bmp390_interface_debug_print("bmp390: finish read test.\n");
430 (void)bmp390_deinit(&gs_handle);
431
432 return 0;
433}
driver bmp390 read test header file
uint8_t bmp390_set_temperature_oversampling(bmp390_handle_t *handle, bmp390_oversampling_t oversampling)
set the temperature oversampling
uint8_t bmp390_set_pressure(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the pressure
uint8_t bmp390_set_mode(bmp390_handle_t *handle, bmp390_mode_t mode)
set the chip mode
bmp390_interface_t
bmp390 interface enumeration definition
uint8_t bmp390_set_temperature(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the temperature
uint8_t bmp390_info(bmp390_info_t *info)
get chip's information
uint8_t bmp390_set_addr_pin(bmp390_handle_t *handle, bmp390_address_t addr_pin)
set the iic address pin
uint8_t bmp390_read_temperature_pressure(bmp390_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa)
read the temperature and pressure
uint8_t bmp390_set_odr(bmp390_handle_t *handle, bmp390_odr_t odr)
set the output data rate
uint8_t bmp390_init(bmp390_handle_t *handle)
initialize the chip
uint8_t bmp390_set_iic_watchdog_timer(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the iic watchdog timer
uint8_t bmp390_set_pressure_oversampling(bmp390_handle_t *handle, bmp390_oversampling_t oversampling)
set the pressure oversampling
uint8_t bmp390_set_iic_watchdog_period(bmp390_handle_t *handle, bmp390_iic_watchdog_period_t period)
set the iic watchdog period
uint8_t bmp390_deinit(bmp390_handle_t *handle)
close the chip
uint8_t bmp390_set_interface(bmp390_handle_t *handle, bmp390_interface_t interface)
set the interface
bmp390_address_t
bmp390 address enumeration definition
uint8_t bmp390_set_spi_wire(bmp390_handle_t *handle, bmp390_spi_wire_t wire)
set the spi wire
uint8_t bmp390_set_filter_coefficient(bmp390_handle_t *handle, bmp390_filter_coefficient_t coefficient)
set the filter coefficient
struct bmp390_info_s bmp390_info_t
bmp390 information structure definition
struct bmp390_handle_s bmp390_handle_t
bmp390 handle structure definition
@ BMP390_INTERRUPT_ACTIVE_LEVEL_HIGHER
@ BMP390_FIFO_DATA_SOURCE_FILTERED
@ BMP390_OVERSAMPLING_x32
@ BMP390_OVERSAMPLING_x2
@ BMP390_INTERRUPT_PIN_TYPE_PUSH_PULL
@ BMP390_BOOL_FALSE
@ BMP390_BOOL_TRUE
@ BMP390_FILTER_COEFFICIENT_15
@ BMP390_ODR_12P5_HZ
@ BMP390_IIC_WATCHDOG_PERIOD_40_MS
@ BMP390_SPI_WIRE_4
@ BMP390_MODE_FORCED_MODE
@ BMP390_MODE_NORMAL_MODE
@ BMP390_MODE_SLEEP_MODE
uint8_t bmp390_set_fifo_data_source(bmp390_handle_t *handle, bmp390_fifo_data_source_t source)
set the fifo data source
uint8_t bmp390_set_fifo_pressure_on(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo pressure on
uint8_t bmp390_set_fifo_temperature_on(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo temperature on
uint8_t bmp390_set_fifo(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo
uint8_t bmp390_set_fifo_sensortime_on(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo sensor time on
uint8_t bmp390_set_fifo_subsampling(bmp390_handle_t *handle, uint8_t subsample)
set the fifo subsampling
uint8_t bmp390_set_fifo_stop_on_full(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo stopping on full
uint8_t bmp390_set_fifo_watermark(bmp390_handle_t *handle, uint16_t watermark)
set the fifo watermark
uint8_t bmp390_interface_spi_init(void)
interface spi bus init
uint8_t bmp390_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
void bmp390_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t bmp390_interface_iic_deinit(void)
interface iic bus deinit
uint8_t bmp390_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t bmp390_interface_iic_init(void)
interface iic bus init
uint8_t bmp390_interface_spi_deinit(void)
interface spi bus deinit
uint8_t bmp390_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t bmp390_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void bmp390_interface_receive_callback(uint8_t type)
interface receive callback
void bmp390_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t bmp390_set_interrupt_fifo_watermark(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo watermark interrupt
uint8_t bmp390_set_interrupt_data_ready(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the data ready interrupt
uint8_t bmp390_set_latch_interrupt_pin_and_interrupt_status(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable latching interrupt pin and interrupt status
uint8_t bmp390_set_interrupt_pin_type(bmp390_handle_t *handle, bmp390_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t bmp390_set_interrupt_fifo_full(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo full interrupt
uint8_t bmp390_set_interrupt_active_level(bmp390_handle_t *handle, bmp390_interrupt_active_level_t level)
set the interrupt active level
uint8_t bmp390_read_test(bmp390_interface_t interface, bmp390_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]