Skip to content
Sensor API for controlling the BMI08x range of IMUs from Bosch Sensortec. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community
C
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
DataSync.md Update DataSync.md Oct 9, 2018
LICENSE
README.md Updated license and formatting Jan 14, 2020
bmi085.c Updated license and formatting Jan 14, 2020
bmi085.h Updated license and formatting Jan 14, 2020
bmi088.c Updated license and formatting Jan 14, 2020
bmi088.h Updated license and formatting Jan 14, 2020
bmi08a.c Updated license and formatting Jan 14, 2020
bmi08g.c Updated license and formatting Jan 14, 2020
bmi08x.h
bmi08x_defs.h Updated license and formatting Jan 14, 2020

README.md

BMI08X Sensor API

Table of Contents

Introduction

This package contains Bosch Sensortec's BMI08X Sensor API.

Version and date

Driver files Version Date
bmi085.c 1.4.4 10 Jan, 2019
bmi085.h 1.4.4 10 Jan, 2019
bmi088.c 1.4.4 10 Jan, 2019
bmi088.h 1.4.4 10 Jan, 2019
bmi08a.c 1.4.4 10 Jan, 2019
bmi08g.c 1.4.4 10 Jan, 2019
bmi08x_defs.h 1.4.4 10 Jan, 2019
bmi08x.h 1.4.4 10 Jan, 2019

Integration details

  • Integrate bmi085.c,bmi085.h,bmi088.c,bmi088.h, bmi08a.c, bmi08g.c,bmi08x_defs.h and bmi08x.h in your project.

Enable the below macro in bmi08x_defs.h to use the BMI085 sensor feature /** \name enable bmi085 sensor */

 #ifndef BMI08X_ENABLE_BMI085
 #define BMI08X_ENABLE_BMI085       1
 #endif

Enable the below macro in bmi08x_defs.h to use the BMI088 sensor feature /** \name enable bmi088 sensor */

 #ifndef BMI08X_ENABLE_BMI088
 #define BMI08X_ENABLE_BMI088       1
 #endif
  • User has to include bmi08x.h and bmi085.h/bmi088.h in the code to call sensor APIs as shown below :
#include "bmi08x.h"

include the variant specific headers bmi085.h/bmi088.h

Driver files information

  • bmi085.c
    • This file has function definitions of bmi085 API interfaces.
  • bmi085.h
    • This header file has necessary include files,bmi085 function declarations, required to make API calls.
  • bmi088.c
    • This file has function definitions of bmi088 API interfaces.
  • bmi088.h
    • This header file has necessary include files,bmi088 function declarations, required to make API calls.
  • bmi08a.c
    • This file has function definitions of bmi08x accel generic API interfaces.
  • bmi08g.c
    • This file has function definitions of bmi08x gyro generic API interfaces.
  • bmi08x.h
    • This header file has necessary include files,bmi08x function declarations, required to make API calls.
  • bmi08x_defs.h
    • This header file has necessary include files, macro definitions, typedefs and data structure definitions.

Sensor interfaces

  • I2C interface
  • SPI interface
    Note: By default, the interface is I2C.

Integration examples

Initializing BMI085 sensors

/* below code shows bmi085 integration steps */ #include "bmi085.h" To initialize BMI085 sensors, an instance of the bmi08x structure should be created. The following parameters are required to be updated in the structure, by the user, to initialize bmi085 sensors.

Parameters Details
accel_id Accel device address of I2C interface
gyro_id Gyro device address of I2C interface
intf I2C or SPI
read read through I2C/SPI interface
write write through I2C/SPI interface
delay_ms delay
Initialize through SPI interface
int8_t rslt;

struct bmi08x_dev dev = {
        .accel_id = 0,
        .gyro_id = 0,
        .intf = BMI08X_SPI_INTF,  
        .read = user_spi_read,  
        .write = user_spi_write,  
        .delay_ms = user_delay_milli_sec
};

/* Initialize the SPI */

/* Initializing the bmi085 sensors the below function will Initialize both accel and gyro sensors */
rslt = bmi085_init(&dev);
Initialize through I2C interface
/* I2C slave address depends on the hardware configuration for details please refer Data sheet */

int8_t rslt;

struct bmi08x_dev dev = {
        .accel_id = BMI08X_ACCEL_I2C_ADDR_PRIMARY, /* User has define this macro depends on the I2C slave address */
        .gyro_id  = BMI08X_GYRO_I2C_ADDR_PRIMARY, /* User has define this macro depends on the I2C slave address */
        .intf = BMI08X_I2C_INTF,  
        .read = user_i2c_read,  
        .write = user_i2c_write,  
        .delay_ms = user_delay_milli_sec
};

/* Initialize the I2C */

/* Initializing the bmi085 sensors the below function will Initialize both accel and gyro sensors */
rslt = bmi085_init(&dev);
	

Read Chip ID from the accel

int8_t rslt;
uint8_t data = 0;

/* Initialize the device instance as per the initialization example */

if(rslt == BMI08X_OK) 
{
    /* Read accel chip id */
    rslt = bmi08a_get_regs(BMI08X_ACCEL_CHIP_ID_REG, &data, 1, &dev);
}
			

Get the accel power mode

int8_t rslt;

/* Initialize the device instance as per the initialization example */

/* Read the accel power mode */
rslt = bmi08a_get_power_mode(&dev)	
/* Power mode will be updated in the dev.accel_cfg.power */
	

Get the accelerometer configurations

int8_t rslt;

/* Initialize the device instance as per the initialization example */

/* Read the accel sensor config parameters (odr,bw,range) */
rslt = bmi08a_get_meas_conf(&dev)
/* Config parameters will be updated in the dev.accel_cfg.odr,dev.accel_cfg.bw and dev.accel_cfg.range */
	

Configuring the accelerometer

int8_t rslt;

/* Initialize the device instance as per the initialization example */

/* Assign the desired configurations */
dev.accel_cfg.bw = BMI08X_ACCEL_BW_NORMAL;
dev.accel_cfg.odr = BMI08X_ACCEL_ODR_100_HZ;
dev.accel_cfg.range = BMI085_ACCEL_RANGE_4G;
dev.accel_cfg.power = BMI08X_ACCEL_PM_ACTIVE;

rslt = bmi08a_set_power_mode(&dev);
/* Wait for 10ms to switch between the power modes - delay taken care inside the function */

rslt = bmi08a_set_meas_conf(&dev);
	

Get accelerometer data

int8_t rslt;
struct bmi08x_sensor_data user_accel_bmi085;

/* Initialize the device instance as per the initialization example */

/* Read the sensor data into the sensor data instance */
rslt = bmi08a_get_data(&user_accel_bmi085, &dev);

Interrupt Configuring for accel data ready interrupt

/* Mapping data ready interrupt to interrupt channel */

int8_t rslt;
struct bmi08x_accel_int_channel_cfg int_config;

/* Initialize the device instance as per the initialization example */

/* Interrupt configurations */
int_config.int_channel = BMI08X_INT_CHANNEL_1;
int_config.int_type = BMI08X_ACCEL_DATA_RDY_INT;
int_config.int_pin_cfg.lvl = BMI08X_INT_ACTIVE_HIGH;
int_config.int_pin_cfg.output_mode = BMI08X_INT_MODE_PUSH_PULL;
int_config.int_pin_cfg.enable_int_pin = BMI08X_ENABLE;

/* Configure the controller port pin for the interrupt and assign the ISR */
	
/* Setting the interrupt configuration */
rslt = bmi08a_set_int_config(&int_config, &dev);


	
void interrupt_handler(void)
{
	/* ISR functionality */
}

/* Unmapping data ready interrupt to interrupt channel */

int8_t rslt;
struct bmi08x_accel_int_channel_cfg int_config;

/* Initialize the device instance as per the initialization example */

/* Interrupt configurations */
int_config.int_channel = BMI08X_INT_CHANNEL_1;
int_config.int_type = BMI08X_ACCEL_DATA_RDY_INT;
int_config.int_pin_cfg.lvl = BMI08X_INT_ACTIVE_HIGH;
int_config.int_pin_cfg.output_mode = BMI08X_INT_MODE_PUSH_PULL;
int_config.int_pin_cfg.enable_int_pin = BMI08X_DISABLE;

/* Setting the interrupt configuration */
rslt = bmi08a_set_int_config(&int_config, &dev);

/* Configure the controller port pin for disabling the interrupt */

	
void interrupt_handler(void)
{
	/* ISR functionality */
}

Interrupt Configuring for accel Anymotion interrupt

/* Initialize the device instance as per the initialization example */

/* Declare the anymotion configuration structure */

struct bmi08x_anymotion_cfg anymotion_cfg;

struct bmi08x_accel_int_channel_cfg int_config;
uint8_t rslt;

/*! Max read/write length (maximum supported length is 32).
To be set by the user */
dev.read_write_len = 8;
/* Enabling Accel Anymotion interrupt */	
rslt = bmi085_apply_config_file(&dev);
	
/* Configure the any motion parameters */

anymotion_cfg.threshold = 0x44;
anymotion_cfg.nomotion_sel = 0x00;
anymotion_cfg.duration = 0x01;
anymotion_cfg.x_en = 0x01;
anymotion_cfg.y_en = 0x01;
anymotion_cfg.z_en = 0x01;
	
rslt=bmi085_configure_anymotion(anymotion_cfg, &dev);
	
/* Interrupt configurations */

int_config.int_channel = BMI08X_INT_CHANNEL_1;
int_config.int_type = BMI08X_ACCEL_DATA_RDY_INT;
int_config.int_pin_cfg.lvl = BMI08X_INT_ACTIVE_HIGH;
int_config.int_pin_cfg.output_mode = BMI08X_INT_MODE_PUSH_PULL;
int_config.int_pin_cfg.enable_int_pin = BMI08X_ENABLE;

/* Configure the controller port pin for the interrupt and assign the ISR */
	
/* Setting the interrupt configuration */

rslt = bmi08a_set_int_config(&int_config, &dev);

void interrupt_handler(void)
{
	/* ISR functionality */
}

/* Disbaling Accel Anymotion interrupt */

struct bmi08x_anymotion_cfg anymotion_cfg;

anymotion_cfg.threshold = 0x44;
anymotion_cfg.nomotion_sel = 0x00;
anymotion_cfg.duration = 0x01;
anymotion_cfg.x_en = 0x00;
anymotion_cfg.y_en = 0x00;
anymotion_cfg.z_en = 0x00;

rslt=bmi085_configure_anymotion(anymotion_cfg, &dev);

if(rslt == BMI08X_OK)  {
	/* Interrupt configurations */
	int_config.int_channel = BMI08X_INT_CHANNEL_1;
	int_config.int_type = BMI08X_ACCEL_DATA_RDY_INT;
	int_config.int_pin_cfg.lvl = BMI08X_INT_ACTIVE_HIGH;
	int_config.int_pin_cfg.output_mode = BMI08X_INT_MODE_PUSH_PULL;
	int_config.int_pin_cfg.enable_int_pin = BMI08X_DISABLE;
	
	/* Setting the interrupt configuration */
	rslt = bmi08a_set_int_config(&int_config, &dev);
}

Get the sensor time

int8_t rslt;
uint32_t user_sampling_time;

/* Initialize the device instance as per the initialization example */
	
/* Read the sensor time */
rslt = bmi08a_get_sensor_time(&dev, &user_sampling_time);
	

Read Chip ID from the gyro

int8_t rslt;
uint8_t data = 0;

/* Initialize the device instance as per the initialization example */

if(rslt == BMI08X_OK) 
{
    /* Read gyro chip id */
    rslt = bmi08g_get_regs(BMI08X_GYRO_CHIP_ID_REG, &data, 1, &dev);
}
			

Get the gyro power mode

int8_t rslt;

/* Initialize the device instance as per the initialization example */

/* Read the gyro power mode */
rslt = bmi08g_get_power_mode(&dev)
/* Power mode will be updated in the dev.gyro_cfg.power */
	

Get the gyro sensor config

int8_t rslt;

/* Initialize the device instance as per the initialization example */

/* Read the gyro sensor config parameters (odr,bw,range) */
rslt = bmi08g_get_meas_conf(&dev)
/* Config parameters will be updated in the dev.gyro_cfg.odr,dev.gyro_cfg.bw and dev.gyro_cfg.range */
	

Configuring the gyro

int8_t rslt;

/* Initialize the device instance as per the initialization example */
	
dev.gyro_cfg.power = BMI08X_GYRO_PM_NORMAL;

rslt = bmi08g_set_power_mode(&dev);
/* Wait for 30ms to switch between the power modes - delay taken care inside the function */
	
/* Assign the desired configurations */
dev.gyro_cfg.odr = BMI08X_GYRO_BW_23_ODR_200_HZ;
dev.gyro_cfg.range = BMI08X_GYRO_RANGE_1000_DPS;
dev.gyro_cfg.bw = BMI08X_GYRO_BW_23_ODR_200_HZ;

rslt = bmi08g_set_meas_conf(&dev);
	

Get gyro data

int8_t rslt;
struct bmi08x_sensor_data user_gyro_bmi085;

/* Initialize the device instance as per the initialization example */

/* Read the sensor data into the sensor data instance */
rslt = bmi08g_get_data(&user_gyro_bmi085, &dev);

Interrupt Configuring for gyro data ready interrupt

int8_t rslt;
struct bmi08x_gyro_int_channel_cfg int_config;

/* Initialize the device instance as per the initialization example */

/* Mapping data ready interrupt to interrupt channel */

int_config.int_channel = BMI08X_INT_CHANNEL_3;
int_config.int_type = BMI08X_GYRO_DATA_RDY_INT;
int_config.int_pin_cfg.lvl = BMI08X_INT_ACTIVE_HIGH;
int_config.int_pin_cfg.output_mode = BMI08X_INT_MODE_PUSH_PULL;
int_config.int_pin_cfg.enable_int_pin = BMI08X_ENABLE;

/* Setting the interrupt configuration */
rslt = bmi08g_set_int_config(&int_config, &dev);

/* Configure the controller port pin for the interrupt and assign the ISR */
	
void interrupt_handler(void)
{
	/* ISR functionality */
}

/* Disabling gyro data ready interrupt */

struct bmi08x_gyro_int_channel_cfg int_config;

/* Initialize the device instance as per the initialization example */

int_config.int_channel = BMI08X_INT_CHANNEL_3;
int_config.int_type = BMI08X_GYRO_DATA_RDY_INT;
int_config.int_pin_cfg.lvl = BMI08X_INT_ACTIVE_HIGH;
int_config.int_pin_cfg.output_mode = BMI08X_INT_MODE_PUSH_PULL;
int_config.int_pin_cfg.enable_int_pin = BMI08X_DISABLE;

/* Setting the interrupt configuration */
rslt = bmi08g_set_int_config(&int_config, &dev);
You can’t perform that action at this time.