Giter VIP home page Giter VIP logo

bmp388's Introduction

English | 简体中文 | 繁體中文 | 日本語 | Deutsch | 한국어

LibDriver BMP388

MISRA API License

The BMP388 is a digital sensor with pressure and temperature measurement based on proven sensing principles.The sensor module is housed in an extremely compact 10-pin metal-lid LGA package with a footprint only 2.0 x 2.0 mm2 and max 0.8 mm package height. Its small dimensions and its low power consumption of 3.4 uA@1Hz allow the implementation in battery driven devices such as mobile phones ,GPS modules or watches.

LibDriver BMP388 is a full function driver of BMP388 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

/src includes LibDriver BMP388 source files.

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

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

/example includes LibDriver BMP388 sample code.

/doc includes LibDriver BMP388 offline document.

/datasheet includes BMP388 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

#include "driver_bmp388_basic.h"

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

res = bmp388_basic_init(BMP388_INTERFACE_IIC, BMP388_ADDRESS_ADO_LOW);
if (res != 0)
{
    return 1;
}

...

for (i = 0; i < 3; i++)
{
    bmp388_interface_delay_ms(1000);
    res = bmp388_basic_read((float *)&temperature_c, (float *)&pressure_pa);
    if (res != 0)
    {
        (void)bmp388_basic_deinit();

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

    ...
        
}

...

(void)bmp388_basic_deinit();

return 0;

example shot

#include "driver_bmp388_shot.h"

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

res = bmp388_shot_init(BMP388_INTERFACE_IIC, BMP388_ADDRESS_ADO_LOW);
if (res != 0)
{
    return 1;
}

...

for (i = 0; i < 3; i++)
{
    bmp388_interface_delay_ms(1000);
    res = bmp388_shot_read((float *)&temperature_c, (float *)&pressure_pa);
    if (res != 0)
    {
        (void)bmp388_shot_deinit();

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

...

(void)bmp388_shot_deinit();

return 0;

example interrupt

#include "driver_bmp388_interrupt.h"

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

void bmp388_interrupt_receive_callback(uint8_t type)
{
    switch (type)
    {
        case BMP388_INTERRUPT_STATUS_FIFO_WATERMARK :
        {
            break;
        }
        case BMP388_INTERRUPT_STATUS_FIFO_FULL :
        {
            break;
        }
        case BMP388_INTERRUPT_STATUS_DATA_READY :
        {
            /* read temperature pressure */
            if (bmp388_interrupt_read((float *)&gs_temperature_c, (float *)&gs_pressure_pa) != 0)
            {
                bmp388_interface_debug_print("bmp388: 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 = bmp388_interrupt_init(BMP388_INTERFACE_IIC, BMP388_ADDRESS_ADO_LOW, bmp388_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)
    {
        bmp388_interface_delay_ms(100);
        timeout--;
        if (gs_data_ready_flag != 0)
        {
            break;
        }
        if (timeout == 0)
        {
            (void)gpio_interrupt_deinit();
            (void)bmp388_interrupt_deinit();

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

...

(void)gpio_interrupt_deinit();
(void)bmp388_interrupt_deinit();

return 0;

example fifo

#include "driver_bmp388_fifo.h"

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

void bmp388_fifo_receive_callback(uint8_t type)
{
    switch (type)
    {
        case BMP388_INTERRUPT_STATUS_FIFO_WATERMARK :
        {
            uint8_t res;
            uint16_t len;
            uint16_t i, frame_len;
            
            len = 512;
            frame_len = 256;
            res = bmp388_fifo_read(gs_buf, len, (bmp388_frame_t *)gs_frame, (uint16_t *)&frame_len);
            if (res != 0)
            {
                bmp388_interface_debug_print("bmp388: fifo read failed.\n");
                
                return;
            }
            for (i = 0; i < frame_len; i++)
            {
                if (gs_frame[i].type == BMP388_FRAME_TYPE_TEMPERATURE)
                {
                    bmp388_interface_debug_print("bmp388: fifo %d/%d.\n", i+1, frame_len);
                    bmp388_interface_debug_print("bmp388: temperature is %0.2fC.\n", gs_frame[i].data);
                }
                else if (gs_frame[i].type == BMP388_FRAME_TYPE_PRESSURE)
                {
                    bmp388_interface_debug_print("bmp388: fifo %d/%d.\n", i+1, frame_len);
                    bmp388_interface_debug_print("bmp388: pressure is %0.2fPa.\n", gs_frame[i].data);
                }
                else if (gs_frame[i].type == BMP388_FRAME_TYPE_SENSORTIME)
                {
                    bmp388_interface_debug_print("bmp388: fifo %d/%d.\n", i+1, frame_len);
                    bmp388_interface_debug_print("bmp388: sensortime is %d.\n", gs_frame[i].raw);
                }
                else
                {
                    bmp388_interface_debug_print("bmp388: fifo %d/%d.\n", i+1, frame_len);
                    bmp388_interface_debug_print("bmp388: unknow type.\n");
                }
            }
            gs_fifo_watermark_flag = 1;
            
            break;
        }
        case BMP388_INTERRUPT_STATUS_FIFO_FULL :
        {
            uint8_t res;
            uint16_t len;
            uint16_t i, frame_len;
            
            len = 512;
            frame_len = 256;
            res = bmp388_fifo_read(gs_buf, len, (bmp388_frame_t *)gs_frame, (uint16_t *)&frame_len);
            if (res != 0)
            {
                bmp388_interface_debug_print("bmp388: fifo read failed.\n");
                
                return;
            }
            for (i = 0; i < frame_len; i++)
            {
                if (gs_frame[i].type == BMP388_FRAME_TYPE_TEMPERATURE)
                {
                    bmp388_interface_debug_print("bmp388: fifo %d/%d.\n", i+1, frame_len);
                    bmp388_interface_debug_print("bmp388: temperature is %0.2fC.\n", gs_frame[i].data);
                }
                else if (gs_frame[i].type == BMP388_FRAME_TYPE_PRESSURE)
                {
                    bmp388_interface_debug_print("bmp388: fifo %d/%d.\n", i+1, frame_len);
                    bmp388_interface_debug_print("bmp388: pressure is %0.2fPa.\n", gs_frame[i].data);
                }
                else if (gs_frame[i].type == BMP388_FRAME_TYPE_SENSORTIME)
                {
                    bmp388_interface_debug_print("bmp388: fifo %d/%d.\n", i+1, frame_len);
                    bmp388_interface_debug_print("bmp388: sensortime is %d.\n", gs_frame[i].raw);
                }
                else
                {
                    bmp388_interface_debug_print("bmp388: fifo %d/%d.\n", i+1, frame_len);
                    bmp388_interface_debug_print("bmp388: unknow type.\n");
                }
            }
            gs_fifo_full_flag = 1;
            
            break;
        }
        case BMP388_INTERRUPT_STATUS_DATA_READY :
        {
            break;
        }
        default :
        {
            break;
        }
    }
}

res = gpio_interrupt_init();
if (res != 0)
{
    return 1;
}
res = bmp388_fifo_init(BMP388_INTERFACE_IIC, BMP388_ADDRESS_ADO_LOW, bmp388_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)
    {
        bmp388_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)bmp388_fifo_deinit();

            return 1;
        }
    }
    gs_fifo_watermark_flag = 0;
    gs_fifo_full_flag = 0;
    timeout = 5000;
    
    ...
    
}
(void)gpio_interrupt_deinit();
(void)bmp388_fifo_deinit();

...

return 0;

Document

Online documents: https://www.libdriver.com/docs/bmp388/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 sent an e-mail to [email protected].

bmp388's People

Contributors

libdriver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bmp388's Issues

iic test errors

Hello,

I am trying to use this library with raspberry 4 and a bmp390. The addresses of bmp388 and bmp390 are the same (with some exception that I've already fixed). When I send this command:
./bmp388 -t reg -iic -a 1
we can see in the log, some values are correct but others print an error.
Do you know what the problem might be?

bmp388: chip is Bosch BMP388.
bmp388: manufacturer is Bosch.
bmp388: interface is IIC SPI.
bmp388: driver version is 2.0.
bmp388: min supply voltage is 1.6V.
bmp388: max supply voltage is 3.6V.
bmp388: max current is 0.80mA.
bmp388: max temperature is 85.0C.
bmp388: min temperature is -40.0C.
bmp388: start register test.
bmp388: bmp388_set_interface/bmp388_get_interface test.
bmp388: set interface iic.
bmp388: check interface ok.
bmp388: set interface spi.
bmp388: check interface ok.
bmp388: bmp388_set_addr_pin/bmp388_get_addr_pin test.
bmp388: set addr pin low.
bmp388: check addr pin ok.
bmp388: set addr pin high.
bmp388: check addr pin ok.
bmp388: bmp388_set_fifo_watermark/bmp388_get_fifo_watermark test.
bmp388: set fifo watermark 359.
bmp388: check fifo watermark error.
bmp388: bmp388_set_fifo/bmp388_get_fifo test.
bmp388: set fifo enable.
bmp388: check fifo error.
bmp388: set fifo disable.
bmp388: check fifo ok.
bmp388: bmp388_set_fifo_stop_on_full/bmp388_get_fifo_stop_on_full test.
bmp388: set fifo stop on full enable.
bmp388: check fifo stop on full error.
bmp388: set fifo stop on full disable.
bmp388: check fifo stop on full ok.
bmp388: bmp388_set_fifo_sensortime_on/bmp388_get_fifo_sensortime_on test.
bmp388: set fifo sensortime on enable.
bmp388: check fifo sensortime on error.
bmp388: set fifo sensortime on disable.
bmp388: check fifo sensortime on ok.
bmp388: bmp388_set_fifo_pressure_on/bmp388_get_fifo_pressure_on test.
bmp388: set fifo pressure on enable.
bmp388: check fifo pressure on error.
bmp388: set fifo pressure on disable.
bmp388: check fifo pressure on ok.
bmp388: bmp388_set_fifo_temperature_on/bmp388_get_fifo_temperature_on test.
bmp388: set fifo temperature on enable.
bmp388: check fifo temperature on error.
bmp388: set fifo temperature on disable.
bmp388: check fifo temperature on ok.
bmp388: bmp388_set_fifo_subsampling/bmp388_get_fifo_subsampling test.
bmp388: set fifo subsampling 4.
bmp388: check fifo subsampling on error.
bmp388: bmp388_set_fifo_data_source/bmp388_get_fifo_data_source test.
bmp388: set fifo data source unfiltered.
bmp388: check fifo data source ok.
bmp388: set fifo data source filtered.
bmp388: check fifo data source error.
bmp388: bmp388_set_interrupt_pin_type/bmp388_get_interrupt_pin_type test.
bmp388: set interrupt pin type push pull.
bmp388: check interrupt pin type ok.
bmp388: set interrupt pin type open drain.
bmp388: check interrupt pin type error.
bmp388: bmp388_set_interrupt_active_level/bmp388_get_interrupt_active_level test.
bmp388: set interrupt active level lower.
bmp388: check interrupt active level ok.
bmp388: set interrupt active level higher.
bmp388: check interrupt active level error.
bmp388: bmp388_set_latch_interrupt_pin_and_interrupt_status/bmp388_get_latch_interrupt_pin_and_interrupt_status test.
bmp388: set latch interrupt pin and interrupt status enable.
bmp388: check latch interrupt pin and interrupt status error.
bmp388: set latch interrupt pin and interrupt status disable.
bmp388: check latch interrupt pin and interrupt status ok.
bmp388: bmp388_set_interrupt_fifo_watermark/bmp388_get_interrupt_fifo_watermark test.
bmp388: set interrupt fifo watermark enable.
bmp388: check interrupt fifo watermark error.
bmp388: set interrupt fifo watermark disable.
bmp388: check interrupt fifo watermark ok.
bmp388: bmp388_set_interrupt_fifo_full/bmp388_get_interrupt_fifo_full test.
bmp388: set interrupt fifo full enable.
bmp388: check interrupt fifo full error.
bmp388: set interrupt fifo full disable.
bmp388: check interrupt fifo full ok.
bmp388: bmp388_set_interrupt_data_ready/bmp388_get_interrupt_fifo_data_ready test.
bmp388: set interrupt data ready enable.
bmp388: check interrupt data ready error.
bmp388: set interrupt data ready disable.
bmp388: check interrupt data ready ok.
bmp388: bmp388_set_spi_wire/bmp388_get_spi_wire test.
bmp388: set spi 4 wire.
bmp388: check spi wire ok.
bmp388: set spi 3 wire.
bmp388: check spi wire error.
bmp388: bmp388_set_iic_watchdog_timer/bmp388_get_iic_watchdog_timer test.
bmp388: set iic watchdog timer enable.
bmp388: check iic watchdog timer error.
bmp388: set iic watchdog timer disable.
bmp388: check iic watchdog timer ok.
bmp388: bmp388_set_iic_watchdog_period/bmp388_get_iic_watchdog_period test.
bmp388: set iic watchdog period 1.25ms.
bmp388: check iic watchdog period ok.
bmp388: set iic watchdog period 40ms.
bmp388: check iic watchdog period error.
bmp388: bmp388_set_pressure/bmp388_get_pressure test.
bmp388: set pressure disable.
bmp388: check pressure ok.
bmp388: set pressure enable.
bmp388: check pressure error.
bmp388: bmp388_set_temperature/bmp388_get_temperature test.
bmp388: set temperature disable.
bmp388: check temperature ok.
bmp388: set temperature enable.
bmp388: check temperature error.
bmp388: bmp388_set_mode/bmp388_get_mode test.
bmp388: set mode sleep.
bmp388: check mode ok.
bmp388: set mode normal mode.
bmp388: check mode error.
bmp388: set mode forced mode.
bmp388: check mode error.
bmp388: bmp388_set_pressure_oversampling/bmp388_get_pressure_oversampling test.
bmp388: set pressure oversampling x1.
bmp388: check pressure oversampling ok.
bmp388: set pressure oversampling x2.
bmp388: check pressure oversampling error.
bmp388: set pressure oversampling x4.
bmp388: check pressure oversampling error.
bmp388: set pressure oversampling x8.
bmp388: check pressure oversampling error.
bmp388: set pressure oversampling x16.
bmp388: check pressure oversampling error.
bmp388: set pressure oversampling x32.
bmp388: check pressure oversampling error.
bmp388: bmp388_set_temperature_oversampling/bmp388_get_temperature_oversampling test.
bmp388: set temperature oversampling x1.
bmp388: check temperature oversampling ok.
bmp388: set temperature oversampling x2.
bmp388: check temperature oversampling error.
bmp388: set temperature oversampling x4.
bmp388: check temperature oversampling error.
bmp388: set temperature oversampling x8.
bmp388: check temperature oversampling error.
bmp388: set temperature oversampling x16.
bmp388: check temperature oversampling error.
bmp388: set temperature oversampling x32.
bmp388: check temperature oversampling error.
bmp388: bmp388_set_odr/bmp388_get_odr test.
bmp388: set odr 200Hz.
bmp388: check odr ok.
bmp388: set odr 100Hz.
bmp388: check odr error.
bmp388: set odr 50Hz.
bmp388: check odr error.
bmp388: set odr 25Hz.
bmp388: check odr error.
bmp388: set odr 12.5Hz.
bmp388: check odr error.
bmp388: set odr 6.25Hz.
bmp388: check odr error.
bmp388: set odr 3.1Hz.
bmp388: check odr error.
bmp388: set odr 1.5Hz.
bmp388: check odr error.
bmp388: set odr 0.78Hz.
bmp388: check odr error.
bmp388: set odr 0.39Hz.
bmp388: check odr error.
bmp388: set odr 0.2Hz.
bmp388: check odr error.
bmp388: set odr 0.1Hz.
bmp388: check odr error.
bmp388: set odr 0.05Hz.
bmp388: check odr error.
bmp388: set odr 0.02Hz.
bmp388: check odr error.
bmp388: set odr 0.01Hz.
bmp388: check odr error.
bmp388: set odr 0.006Hz.
bmp388: check odr error.
bmp388: set odr 0.003Hz.
bmp388: check odr error.
bmp388: set odr 0.0015Hz.
bmp388: check odr error.
bmp388: bmp388_set_filter_coefficient/bmp388_get_filter_coefficient test.
bmp388: set filter coefficient 0.
bmp388: check filter coefficient ok.
bmp388: set filter coefficient 1.
bmp388: check filter coefficient error.
bmp388: set filter coefficient 3.
bmp388: check filter coefficient error.
bmp388: set filter coefficient 7.
bmp388: check filter coefficient error.
bmp388: set filter coefficient 15.
bmp388: check filter coefficient error.
bmp388: set filter coefficient 31.
bmp388: check filter coefficient error.
bmp388: set filter coefficient 63.
bmp388: check filter coefficient error.
bmp388: set filter coefficient 127.
bmp388: check filter coefficient error.
bmp388: bmp388_get_error.
bmp388: err is 0x00.
bmp388: bmp388_get_status.
bmp388: status is 0x00.
bmp388: bmp388_get_sensortime.
bmp388: sensortime is 0x000000.
bmp388: bmp388_get_event.
bmp388: event is none.
bmp388: bmp388_get_interrupt_status.
bmp388: interrupt status is 0x00.
bmp388: bmp388_get_fifo_length.
bmp388: get fifo length is 0x0000.
bmp388: bmp388_get_fifo_data.
bmp388: get fifo data is 0x0000.
bmp388: bmp388_flush_fifo.
bmp388: flush fifo ok.
bmp388: bmp388_extmode_en_middle.
bmp388: extmode en middle ok.
bmp388: bmp388_softreset.
bmp388: softreset ok.
bmp388: finish register test.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.