LibDriver BMP384
Loading...
Searching...
No Matches
driver_bmp384_read_test.c
Go to the documentation of this file.
1
36
38
39static bmp384_handle_t gs_handle;
40
51uint8_t bmp384_read_test(bmp384_interface_t interface, bmp384_address_t addr_pin, uint32_t times)
52{
53 uint8_t res;
54 uint32_t i;
55 bmp384_info_t info;
56
57 /* link functions */
70
71 /* bmp384 info */
72 res = bmp384_info(&info);
73 if (res != 0)
74 {
75 bmp384_interface_debug_print("bmp384: get info failed.\n");
76
77 return 1;
78 }
79 else
80 {
81 /* print chip information */
82 bmp384_interface_debug_print("bmp384: chip is %s.\n", info.chip_name);
83 bmp384_interface_debug_print("bmp384: manufacturer is %s.\n", info.manufacturer_name);
84 bmp384_interface_debug_print("bmp384: interface is %s.\n", info.interface);
85 bmp384_interface_debug_print("bmp384: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
86 bmp384_interface_debug_print("bmp384: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
87 bmp384_interface_debug_print("bmp384: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
88 bmp384_interface_debug_print("bmp384: max current is %0.2fmA.\n", info.max_current_ma);
89 bmp384_interface_debug_print("bmp384: max temperature is %0.1fC.\n", info.temperature_max);
90 bmp384_interface_debug_print("bmp384: min temperature is %0.1fC.\n", info.temperature_min);
91 }
92
93 /* start read test */
94 bmp384_interface_debug_print("bmp384: start read test.\n");
95 res = bmp384_set_interface(&gs_handle, interface);
96 if (res != 0)
97 {
98 bmp384_interface_debug_print("bmp384: set interface failed.\n");
99
100 return 1;
101 }
102
103 /* set addr pin */
104 res = bmp384_set_addr_pin(&gs_handle, addr_pin);
105 if (res != 0)
106 {
107 bmp384_interface_debug_print("bmp384: set addr pin failed.\n");
108
109 return 1;
110 }
111
112 /* bmp384 init */
113 res = bmp384_init(&gs_handle);
114 if (res != 0)
115 {
116 bmp384_interface_debug_print("bmp384: init failed.\n");
117
118 return 1;
119 }
120
121 /* set spi wire 4 */
122 res = bmp384_set_spi_wire(&gs_handle, BMP384_SPI_WIRE_4);
123 if (res != 0)
124 {
125 bmp384_interface_debug_print("bmp384: set spi wire failed.\n");
126 (void)bmp384_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 /* enable iic watchdog timer */
133 if (res != 0)
134 {
135 bmp384_interface_debug_print("bmp384: set iic watchdog timer failed.\n");
136 (void)bmp384_deinit(&gs_handle);
137
138 return 1;
139 }
140
141 /* set iic watchdog period 40 ms */
143 if (res != 0)
144 {
145 bmp384_interface_debug_print("bmp384: set iic watchdog period failed.\n");
146 (void)bmp384_deinit(&gs_handle);
147
148 return 1;
149 }
150
151 /* disable fifo */
152 res = bmp384_set_fifo(&gs_handle, BMP384_BOOL_FALSE);
153 if (res != 0)
154 {
155 bmp384_interface_debug_print("bmp384: set fifo failed.\n");
156 (void)bmp384_deinit(&gs_handle);
157
158 return 1;
159 }
160
161 /* disable fifo stop on full */
163 if (res != 0)
164 {
165 bmp384_interface_debug_print("bmp384: set fifo stop on full failed.\n");
166 (void)bmp384_deinit(&gs_handle);
167
168 return 1;
169 }
170
171 /* set fifo watermark 256 */
172 res = bmp384_set_fifo_watermark(&gs_handle, 256);
173 if (res != 0)
174 {
175 bmp384_interface_debug_print("bmp384: set fifo watermark failed.\n");
176 (void)bmp384_deinit(&gs_handle);
177
178 return 1;
179 }
180
181 /* enable fifo sensor time on */
183 if (res != 0)
184 {
185 bmp384_interface_debug_print("bmp384: set fifo sensor time on failed.\n");
186 (void)bmp384_deinit(&gs_handle);
187
188 return 1;
189 }
190
191 /* enable fifo pressure on */
193 if (res != 0)
194 {
195 bmp384_interface_debug_print("bmp384: set fifo sensor time on failed.\n");
196 (void)bmp384_deinit(&gs_handle);
197
198 return 1;
199 }
200
201 /* enable fifo temperature on */
203 if (res != 0)
204 {
205 bmp384_interface_debug_print("bmp384: set fifo temperature on failed.\n");
206 (void)bmp384_deinit(&gs_handle);
207
208 return 1;
209 }
210
211 /* set fifo subsampling 0 */
212 res = bmp384_set_fifo_subsampling(&gs_handle, 0);
213 if (res != 0)
214 {
215 bmp384_interface_debug_print("bmp384: set fifo subsampling failed.\n");
216 (void)bmp384_deinit(&gs_handle);
217
218 return 1;
219 }
220
221 /* set fifo data source filtered */
223 if (res != 0)
224 {
225 bmp384_interface_debug_print("bmp384: set fifo data source failed.\n");
226 (void)bmp384_deinit(&gs_handle);
227
228 return 1;
229 }
230
231 /* set interrupt pin type push-pull */
233 if (res != 0)
234 {
235 bmp384_interface_debug_print("bmp384: set interrupt pin type failed.\n");
236 (void)bmp384_deinit(&gs_handle);
237
238 return 1;
239 }
240
241 /* set interrupt active level higher */
243 if (res != 0)
244 {
245 bmp384_interface_debug_print("bmp384: set interrupt active level failed.\n");
246 (void)bmp384_deinit(&gs_handle);
247
248 return 1;
249 }
250
251 /* enable latch interrupt pin and interrupt status */
253 if (res != 0)
254 {
255 bmp384_interface_debug_print("bmp384: set set latch interrupt pin and interrupt status failed.\n");
256 (void)bmp384_deinit(&gs_handle);
257
258 return 1;
259 }
260
261 /* enable interrupt fifo watermark */
263 if (res != 0)
264 {
265 bmp384_interface_debug_print("bmp384: set interrupt fifo watermark failed.\n");
266 (void)bmp384_deinit(&gs_handle);
267
268 return 1;
269 }
270
271 /* enable interrupt fifo full */
273 if (res != 0)
274 {
275 bmp384_interface_debug_print("bmp384: set interrupt fifo full failed.\n");
276 (void)bmp384_deinit(&gs_handle);
277
278 return 1;
279 }
280
281 /* disable interrupt data ready */
283 if (res != 0)
284 {
285 bmp384_interface_debug_print("bmp384: set interrupt data ready failed.\n");
286 (void)bmp384_deinit(&gs_handle);
287
288 return 1;
289 }
290
291 /* enable pressure */
292 res = bmp384_set_pressure(&gs_handle, BMP384_BOOL_TRUE);
293 if (res != 0)
294 {
295 bmp384_interface_debug_print("bmp384: set pressure failed.\n");
296 (void)bmp384_deinit(&gs_handle);
297
298 return 1;
299 }
300
301 /* enable temperature */
302 res = bmp384_set_temperature(&gs_handle, BMP384_BOOL_TRUE);
303 if (res != 0)
304 {
305 bmp384_interface_debug_print("bmp384: set temperature failed.\n");
306 (void)bmp384_deinit(&gs_handle);
307
308 return 1;
309 }
310
311 /* set pressure oversampling x32 */
313 if (res != 0)
314 {
315 bmp384_interface_debug_print("bmp384: set pressure oversampling failed.\n");
316 (void)bmp384_deinit(&gs_handle);
317
318 return 1;
319 }
320
321 /* set temperature oversampling x2 */
323 if (res != 0)
324 {
325 bmp384_interface_debug_print("bmp384: set temperature oversampling failed.\n");
326 (void)bmp384_deinit(&gs_handle);
327
328 return 1;
329 }
330
331 /* set odr 12.5Hz */
332 res = bmp384_set_odr(&gs_handle, BMP384_ODR_12P5_HZ);
333 if (res != 0)
334 {
335 bmp384_interface_debug_print("bmp384: set odr failed.\n");
336 (void)bmp384_deinit(&gs_handle);
337
338 return 1;
339 }
340
341 /* set filter coefficient 15 */
343 if (res != 0)
344 {
345 bmp384_interface_debug_print("bmp384: set filter coefficient failed.\n");
346 (void)bmp384_deinit(&gs_handle);
347
348 return 1;
349 }
350
351 /* start forced mode read test */
352 bmp384_interface_debug_print("bmp384: forced mode read test.\n");
353
354 /* set forced mode */
355 res = bmp384_set_mode(&gs_handle, BMP384_MODE_FORCED_MODE);
356 if (res != 0)
357 {
358 bmp384_interface_debug_print("bmp384: set mode failed.\n");
359 (void)bmp384_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 (bmp384_read_temperature_pressure(&gs_handle, (uint32_t *)&temperature_raw, (float *)&temperature_c,
373 (uint32_t *)&pressure_raw, (float *)&pressure_pa) != 0)
374 {
375 bmp384_interface_debug_print("bmp384: read temperature and pressure failed.\n");
376 (void)bmp384_deinit(&gs_handle);
377
378 return 1;
379 }
380 bmp384_interface_debug_print("bmp384: temperature is %0.2fC.\n", temperature_c);
381 bmp384_interface_debug_print("bmp384: pressure is %0.2fPa.\n", pressure_pa);
383 }
384
385 /* start normal mode read */
386 bmp384_interface_debug_print("bmp384: normal mode read test.\n");
387 res = bmp384_set_mode(&gs_handle, BMP384_MODE_SLEEP_MODE);
388 if (res != 0)
389 {
390 bmp384_interface_debug_print("bmp384: set mode failed.\n");
391 (void)bmp384_deinit(&gs_handle);
392
393 return 1;
394 }
396
397 /* set normal mode */
398 res = bmp384_set_mode(&gs_handle, BMP384_MODE_NORMAL_MODE);
399 if (res != 0)
400 {
401 bmp384_interface_debug_print("bmp384: set mode failed.\n");
402 (void)bmp384_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 (bmp384_read_temperature_pressure(&gs_handle, (uint32_t *)&temperature_raw, (float *)&temperature_c,
416 (uint32_t *)&pressure_raw, (float *)&pressure_pa) != 0)
417 {
418 bmp384_interface_debug_print("bmp384: read temperature and pressure failed.\n");
419 (void)bmp384_deinit(&gs_handle);
420
421 return 1;
422 }
423 bmp384_interface_debug_print("bmp384: temperature is %0.2fC.\n", temperature_c);
424 bmp384_interface_debug_print("bmp384: pressure is %0.2fPa.\n", pressure_pa);
426 }
427
428 /* finish read test */
429 bmp384_interface_debug_print("bmp384: finish read test.\n");
430 (void)bmp384_deinit(&gs_handle);
431
432 return 0;
433}
driver bmp384 read 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_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_FORCED_MODE
@ BMP384_MODE_NORMAL_MODE
@ BMP384_MODE_SLEEP_MODE
@ BMP384_FIFO_DATA_SOURCE_FILTERED
@ BMP384_SPI_WIRE_4
@ BMP384_BOOL_TRUE
@ BMP384_BOOL_FALSE
@ 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
void bmp384_interface_receive_callback(uint8_t type)
interface receive callback
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_read_test(bmp384_interface_t interface, bmp384_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]