Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/libdriver/bmp384

BMP384 full function driver library for general MCU and Linux.
https://github.com/libdriver/bmp384

barometer bmp384 c full-function-driver iic linux mcu spi

Last synced: 17 days ago
JSON representation

BMP384 full function driver library for general MCU and Linux.

Awesome Lists containing this project

README

        

[English](/README.md) | [ 简体中文](/README_zh-Hans.md) | [繁體中文](/README_zh-Hant.md) | [日本語](/README_ja.md) | [Deutsch](/README_de.md) | [한국어](/README_ko.md)



## LibDriver BMP384

[![MISRA](https://img.shields.io/badge/misra-compliant-brightgreen.svg)](/misra/README.md) [![API](https://img.shields.io/badge/api-reference-blue.svg)](https://www.libdriver.com/docs/bmp384/index.html) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](/LICENSE)

BMP384 has a gel-filled cavity that allows higher robustness against water, liquids and other chemicals if the applicable integration concept is used. The BMP384 is perfectly suitable for applications of water-level and clog detection. It is compatible for use with other Bosch Sensortec sensors, including the BMI088 for better performance, robustness and stability. The BMP384 with its small footprint offers outstanding design flexibility, providing a single package solution that is easy to integrate into other existing and upcoming devices for smart homes, industrial products and wearables.

LibDriver BMP384 is a full function driver of BMP384 launched by LibDriver.It provides continuous reading of pressure and temperature, single reading of pressure and temperature, interrupt reading, FIFO acquisition and other functions. LibDriver is MISRA compliant.

### Table of Contents

- [Instruction](#Instruction)
- [Install](#Install)
- [Usage](#Usage)
- [example basic](#example-basic)
- [example shot](#example-shot)
- [example interrupt](#example-interrupt)
- [example fifo](#example-fifo)
- [Document](#Document)
- [Contributing](#Contributing)
- [License](#License)
- [Contact Us](#Contact-Us)

### Instruction

/src includes LibDriver BMP384 source files.

/interface includes LibDriver BMP384 IIC, SPI platform independent template.

/test includes LibDriver BMP384 driver test code and this code can test the chip necessary function simply.

/example includes LibDriver BMP384 sample code.

/doc includes LibDriver BMP384 offline document.

/datasheet includes BMP384 datasheet.

/project includes the common Linux and MCU development board sample code. All projects use the shell script to debug the driver and the detail instruction can be found in each project's README.md.

/misra includes the LibDriver MISRA code scanning results.

### Install

Reference /interface IIC, SPI platform independent template and finish your platform IIC, SPI driver.

Add the /src directory, the interface driver for your platform, and your own drivers to your project, if you want to use the default example drivers, add the /example directory to your project.

### Usage

You can refer to the examples in the /example directory to complete your own driver. If you want to use the default programming examples, here's how to use them.

#### example basic

```C
#include "driver_bmp384_basic.h"

uint8_t res;
uint8_t i;
float temperature_c;
float pressure_pa;

res = bmp384_basic_init(BMP384_INTERFACE_IIC, BMP384_ADDRESS_ADO_LOW);
if (res != 0)
{
return 1;
}

...

for (i = 0; i < 3; i++)
{
bmp384_interface_delay_ms(1000);
res = bmp384_basic_read((float *)&temperature_c, (float *)&pressure_pa);
if (res != 0)
{
(void)bmp384_basic_deinit();

return 1;
}
bmp384_interface_debug_print("bmp384: temperature is %0.2fC.\n", temperature_c);
bmp384_interface_debug_print("bmp384: pressure is %0.2fPa.\n", pressure_pa);

...

}

...

(void)bmp384_basic_deinit();

return 0;
```

#### example shot

```C
#include "driver_bmp384_shot.h"

uint8_t res;
uint8_t i;
float temperature_c;
float pressure_pa;

res = bmp384_shot_init(BMP384_INTERFACE_IIC, BMP384_ADDRESS_ADO_LOW);
if (res != 0)
{
return 1;
}

...

for (i = 0; i < 3; i++)
{
bmp384_interface_delay_ms(1000);
res = bmp384_shot_read((float *)&temperature_c, (float *)&pressure_pa);
if (res != 0)
{
(void)bmp384_shot_deinit();

return 1;
}
bmp384_interface_debug_print("bmp384: temperature is %0.2fC.\n", temperature_c);
bmp384_interface_debug_print("bmp384: pressure is %0.2fPa.\n", pressure_pa);

...

}

...

(void)bmp384_shot_deinit();

return 0;
```

#### example interrupt

```C
#include "driver_bmp384_interrupt.h"

uint8_t res;
uint16_t i, timeout;
uint8_t gs_data_ready_flag;
float gs_temperature_c;
float gs_pressure_pa;

void bmp384_interrupt_receive_callback(uint8_t type)
{
switch (type)
{
case BMP384_INTERRUPT_STATUS_FIFO_WATERMARK :
{
break;
}
case BMP384_INTERRUPT_STATUS_FIFO_FULL :
{
break;
}
case BMP384_INTERRUPT_STATUS_DATA_READY :
{
/* read temperature pressure */
if (bmp384_interrupt_read((float *)&gs_temperature_c, (float *)&gs_pressure_pa) != 0)
{
bmp384_interface_debug_print("bmp384: read temperature and pressure failed.\n");

return;
}
gs_data_ready_flag = 1;

break;
}
default :
{
break;
}
}
}

res = gpio_interrupt_init();
if (res != 0)
{
return 1;
}
res = bmp384_interrupt_init(BMP384_INTERFACE_IIC, BMP384_ADDRESS_ADO_LOW, bmp384_interrupt_receive_callback);
if (res != 0)
{
(void)gpio_interrupt_deinit();

return 1;
}

...

gs_data_ready_flag = 0;
timeout = 5000;
for (i = 0; i < 3; i++)
{
while (timeout != 0)
{
bmp384_interface_delay_ms(100);
timeout--;
if (gs_data_ready_flag != 0)
{
break;
}
if (timeout == 0)
{
(void)gpio_interrupt_deinit();
(void)bmp384_interrupt_deinit();

return 1;
}
}
gs_data_ready_flag = 0;
timeout = 5000;
bmp384_interface_debug_print("bmp384: temperature is %0.2fC.\n", gs_temperature_c);
bmp384_interface_debug_print("bmp384: pressure is %0.2fPa.\n", gs_pressure_pa);

...

}

...

(void)gpio_interrupt_deinit();
(void)bmp384_interrupt_deinit();

return 0;
```

#### example fifo

```C
#include "driver_bmp384_fifo.h"

uint8_t gs_fifo_full_flag;
uint8_t gs_fifo_watermark_flag;
uint16_t i, timeout;
uint8_t gs_buf[512];
bmp384_frame_t gs_frame[256];

void bmp384_fifo_receive_callback(uint8_t type)
{
switch (type)
{
case BMP384_INTERRUPT_STATUS_FIFO_WATERMARK :
{
uint8_t res;
uint16_t len;
uint16_t i, frame_len;

len = 512;
frame_len = 256;
res = bmp384_fifo_read(gs_buf, len, (bmp384_frame_t *)gs_frame, (uint16_t *)&frame_len);
if (res != 0)
{
bmp384_interface_debug_print("bmp384: fifo read failed.\n");

return;
}
for (i = 0; i < frame_len; i++)
{
if (gs_frame[i].type == BMP384_FRAME_TYPE_TEMPERATURE)
{
bmp384_interface_debug_print("bmp384: fifo %d/%d.\n", i+1, frame_len);
bmp384_interface_debug_print("bmp384: temperature is %0.2fC.\n", gs_frame[i].data);
}
else if (gs_frame[i].type == BMP384_FRAME_TYPE_PRESSURE)
{
bmp384_interface_debug_print("bmp384: fifo %d/%d.\n", i+1, frame_len);
bmp384_interface_debug_print("bmp384: pressure is %0.2fPa.\n", gs_frame[i].data);
}
else if (gs_frame[i].type == BMP384_FRAME_TYPE_SENSORTIME)
{
bmp384_interface_debug_print("bmp384: fifo %d/%d.\n", i+1, frame_len);
bmp384_interface_debug_print("bmp384: sensortime is %d.\n", gs_frame[i].raw);
}
else
{
bmp384_interface_debug_print("bmp384: fifo %d/%d.\n", i+1, frame_len);
bmp384_interface_debug_print("bmp384: unknow type.\n");
}
}
gs_fifo_watermark_flag = 1;

break;
}
case BMP384_INTERRUPT_STATUS_FIFO_FULL :
{
uint8_t res;
uint16_t len;
uint16_t i, frame_len;

len = 512;
frame_len = 256;
res = bmp384_fifo_read(gs_buf, len, (bmp384_frame_t *)gs_frame, (uint16_t *)&frame_len);
if (res != 0)
{
bmp384_interface_debug_print("bmp384: fifo read failed.\n");

return;
}
for (i = 0; i < frame_len; i++)
{
if (gs_frame[i].type == BMP384_FRAME_TYPE_TEMPERATURE)
{
bmp384_interface_debug_print("bmp384: fifo %d/%d.\n", i+1, frame_len);
bmp384_interface_debug_print("bmp384: temperature is %0.2fC.\n", gs_frame[i].data);
}
else if (gs_frame[i].type == BMP384_FRAME_TYPE_PRESSURE)
{
bmp384_interface_debug_print("bmp384: fifo %d/%d.\n", i+1, frame_len);
bmp384_interface_debug_print("bmp384: pressure is %0.2fPa.\n", gs_frame[i].data);
}
else if (gs_frame[i].type == BMP384_FRAME_TYPE_SENSORTIME)
{
bmp384_interface_debug_print("bmp384: fifo %d/%d.\n", i+1, frame_len);
bmp384_interface_debug_print("bmp384: sensortime is %d.\n", gs_frame[i].raw);
}
else
{
bmp384_interface_debug_print("bmp384: fifo %d/%d.\n", i+1, frame_len);
bmp384_interface_debug_print("bmp384: unknow type.\n");
}
}
gs_fifo_full_flag = 1;

break;
}
case BMP384_INTERRUPT_STATUS_DATA_READY :
{
break;
}
default :
{
break;
}
}
}

res = gpio_interrupt_init();
if (res != 0)
{
return 1;
}
res = bmp384_fifo_init(BMP384_INTERFACE_IIC, BMP384_ADDRESS_ADO_LOW, bmp384_fifo_receive_callback);
if (res != 0)
{
(void)gpio_interrupt_deinit();

return 1;
}

...

gs_fifo_watermark_flag = 0;
gs_fifo_full_flag = 0;
timeout = 5000;
for (i = 0; i < 3; i++)
{
while (timeout != 0)
{
bmp384_interface_delay_ms(100);
timeout--;
if ((gs_fifo_watermark_flag != 0) || (gs_fifo_full_flag != 0))
{
break;
}
if (timeout == 0)
{
(void)gpio_interrupt_deinit();
(void)bmp384_fifo_deinit();

return 1;
}
}
gs_fifo_watermark_flag = 0;
gs_fifo_full_flag = 0;
timeout = 5000;

...

}
(void)gpio_interrupt_deinit();
(void)bmp384_fifo_deinit();

...

return 0;
```

### Document

Online documents: [https://www.libdriver.com/docs/bmp384/index.html](https://www.libdriver.com/docs/bmp384/index.html).

Offline documents: /doc/html/index.html.

### Contributing

Please refer to CONTRIBUTING.md.

### License

Copyright (c) 2015 - present LibDriver All rights reserved

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy

of this software and associated documentation files (the "Software"), to deal

in the Software without restriction, including without limitation the rights

to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

copies of the Software, and to permit persons to whom the Software is

furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all

copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

SOFTWARE.

### Contact Us

Please send an e-mail to [email protected].