Utility library for HSP SPo2 HR demo including user interface, board support adn accelerometer.

Embed: (wiki syntax)

« Back to documentation index

BMI160_I2C Class Reference

BMI160_I2C - supports BMI160 object with I2C interface. More...

#include <bmi160.h>

Inherits BMI160.

Public Types

enum  Sensors { MAG = 0, GYRO, ACC }
 

Sensor types.

More...
enum  SensorAxis
 

Sensor Axis.

More...
enum  Registers {
  CHIP_ID = 0x00, ERR_REG = 0x02, PMU_STATUS, DATA_0,
  DATA_1, DATA_2, DATA_3, DATA_4,
  DATA_5, DATA_6, DATA_7, DATA_8,
  DATA_9, DATA_10, DATA_11, DATA_12,
  DATA_13, DATA_14, DATA_15, DATA_16,
  DATA_17, DATA_18, DATA_19, SENSORTIME_0,
  SENSORTIME_1, SENSORTIME_2, STATUS, INT_STATUS_0,
  INT_STATUS_1, INT_STATUS_2, INT_STATUS_3, TEMPERATURE_0,
  TEMPERATURE_1, FIFO_LENGTH_0, FIFO_LENGTH_1, FIFO_DATA,
  ACC_CONF = 0x40, ACC_RANGE, GYR_CONF, GYR_RANGE,
  MAG_CONF, FIFO_DOWNS, FIFO_CONFIG_0, FIFO_CONFIG_1,
  MAG_IF_0 = 0x4B, MAG_IF_1, MAG_IF_2, MAG_IF_3,
  MAG_IF_4, INT_EN_0, INT_EN_1, INT_EN_2,
  INT_OUT_CTRL, INT_LATCH, INT_MAP_0, INT_MAP_1,
  INT_MAP_2, INT_DATA_0, INT_DATA_1, INT_LOWHIGH_0,
  INT_LOWHIGH_1, INT_LOWHIGH_2, INT_LOWHIGH_3, INT_LOWHIGH_4,
  INT_MOTION_0, INT_MOTION_1, INT_MOTION_2, INT_MOTION_3,
  INT_TAP_0, INT_TAP_1, INT_ORIENT_0, INT_ORIENT_1,
  INT_FLAT_0, INT_FLAT_1, FOC_CONF, CONF,
  IF_CONF, PMU_TRIGGER, SELF_TEST, NV_CONF = 0x70,
  OFFSET_0, OFFSET_1, OFFSET_2, OFFSET_3,
  OFFSET_4, OFFSET_5, OFFSET_6, STEP_CNT_0,
  STEP_CNT_1, STEP_CONF_0, STEP_CONF_1, CMD = 0x7E
}
 

BMI160 registers.

More...
enum  PowerModes { SUSPEND = 0, NORMAL, LOW_POWER, FAST_START_UP }
 

Enumerated power modes.

More...
enum  Commands {
  START_FOC = 0x03, ACC_SET_PMU_MODE = 0x10, GYR_SET_PMU_MODE = 0x14, MAG_SET_PMU_MODE = 0x18,
  PROG_NVM = 0xA0, FIFO_FLUSH = 0xB0, INT_RESET, STEP_CNT_CLR,
  SOFT_RESET = 0xB6
}
 

Enumerated commands used with CMD register.

More...

Public Member Functions

 BMI160_I2C (I2C *i2cBus, uint8_t i2cAdrs)
 BMI160_I2C Constructor.
 BMI160_I2C (I2C *i2cBus, uint8_t i2cAdrs, InterruptIn *int_pin)
 BMI160_I2C Constructor.
virtual int32_t readRegister (Registers reg, uint8_t *data)
 Reads a single register.
virtual int32_t writeRegister (Registers reg, const uint8_t data)
 Writes a single register.
virtual int32_t readBlock (Registers startReg, Registers stopReg, uint8_t *data)
 Reads a block of registers.
virtual int32_t writeBlock (Registers startReg, Registers stopReg, const uint8_t *data)
 Writes a block of registers.
int32_t setSensorPowerMode (Sensors sensor, PowerModes pwrMode)
 Sets sensors power mode through CMD register.
int32_t setSensorConfig (const AccConfig &config)
 Configure sensor.
int32_t getSensorConfig (AccConfig &config)
 Get sensor configuration.
int32_t getSensorAxis (SensorAxis axis, AxisData &data, AccRange range)
 Get sensor axis.
int32_t getSensorXYZ (SensorData &data, AccRange range)
 Get sensor xyz axis.
int32_t getSensorXYZandSensorTime (SensorData &data, SensorTime &sensorTime, AccRange range)
 Get sensor xyz axis and sensor time.
int32_t getGyroAccXYZandSensorTime (SensorData &accData, SensorData &gyroData, SensorTime &sensorTime, AccRange accRange, GyroRange gyroRange)
 Get Gyroscope/Accelerometer data and sensor time.
int32_t getSensorTime (SensorTime &sensorTime)
 Get sensor time.
int32_t getTemperature (float *temp)
 Get die temperature.
int32_t setSampleRate (int sample_rate)
int32_t reset ()
 Soft reset.

Static Public Attributes

static const uint8_t I2C_ADRS_SDO_LO = 0x68
 BMI160 default I2C address.
static const uint8_t I2C_ADRS_SDO_HI = 0x69
 BMI160 optional I2C address.
static const uint8_t RTN_NO_ERROR = 0
 Return value on success.
static const float SENSOR_TIME_LSB = 39e-6
 Period of internal counter.

ERR_REG(0x02)

Error register data


static const uint8_t FATAL_ERR_MASK = 0x01
static const uint8_t FATAL_ERR_POS = 0x00
static const uint8_t ERR_CODE_MASK = 0x1E
static const uint8_t ERR_CODE_POS = 0x01
static const uint8_t I2C_FAIL_ERR_MASK = 0x20
static const uint8_t I2C_FAIL_ERR_POS = 0x05
static const uint8_t DROP_CMD_ERR_MASK = 0x40
static const uint8_t DROP_CMD_ERR_POS = 0x06
static const uint8_t MAG_DRDY_ERR_MASK = 0x80
static const uint8_t MAG_DRDY_ERR_POS = 0x08
enum  ErrorCodes {
  NO_ERROR = 0, ERROR_1, ERROR_2, LPM_INT_PFD,
  ODR_MISMATCH = 0x06, PFD_USED_LPM
}
 

Enumerated error codes.

More...

ACC_CONF(0x40) and ACC_RANGE(0x41)

Data for configuring accelerometer


static const uint8_t ACC_ODR_MASK = 0x0F
static const uint8_t ACC_ODR_POS = 0x00
static const uint8_t ACC_BWP_MASK = 0x70
static const uint8_t ACC_BWP_POS = 0x04
static const uint8_t ACC_US_MASK = 0x80
static const uint8_t ACC_US_POS = 0x07
static const uint8_t ACC_RANGE_MASK = 0x0F
static const uint8_t ACC_RANGE_POS = 0x00
static const float SENS_2G_LSB_PER_G = 16384.0F
static const float SENS_4G_LSB_PER_G = 8192.0F
static const float SENS_8G_LSB_PER_G = 4096.0F
static const float SENS_16G_LSB_PER_G = 2048.0F
static const AccConfig DEFAULT_ACC_CONFIG
 Accelerometer default configuration.
enum  AccOutputDataRate {
  ACC_ODR_1 = 1, ACC_ODR_2, ACC_ODR_3, ACC_ODR_4,
  ACC_ODR_5, ACC_ODR_6, ACC_ODR_7, ACC_ODR_8,
  ACC_ODR_9, ACC_ODR_10, ACC_ODR_11, ACC_ODR_12
}
 

Accelerometer output data rates.

More...
enum  AccBandWidthParam {
  ACC_BWP_0 = 0, ACC_BWP_1, ACC_BWP_2, ACC_BWP_3,
  ACC_BWP_4, ACC_BWP_5, ACC_BWP_6, ACC_BWP_7
}
 

Accelerometer bandwidth parameters.

More...
enum  AccUnderSampling
 

Accelerometer undersampling.

More...
enum  AccRange { SENS_2G = 0x03, SENS_4G = 0x05, SENS_8G = 0x08, SENS_16G = 0x0C }
 

Accelerometer ranges.

More...

GYR_CONF(0x42) and GYR_RANGE(0x43)

Data for configuring gyroscope


static const uint8_t GYRO_ODR_MASK = 0x0F
static const uint8_t GYRO_ODR_POS = 0x00
static const uint8_t GYRO_BWP_MASK = 0x30
static const uint8_t GYRO_BWP_POS = 0x04
static const uint8_t GYRO_RANGE_MASK = 0x07
static const uint8_t GYRO_RANGE_POS = 0x00
static const float SENS_2000_DPS_LSB_PER_DPS = 16.4F
static const float SENS_1000_DPS_LSB_PER_DPS = 32.8F
static const float SENS_500_DPS_LSB_PER_DPS = 65.6F
static const float SENS_250_DPS_LSB_PER_DPS = 131.2F
static const float SENS_125_DPS_LSB_PER_DPS = 262.4F
static const GyroConfig DEFAULT_GYRO_CONFIG
 Gyroscope default configuration.
enum  GyroOutputDataRate {
  GYRO_ODR_6 = 0x06, GYRO_ODR_7 = 0x07, GYRO_ODR_8 = 0x08, GYRO_ODR_9 = 0x09,
  GYRO_ODR_10 = 0x0A, GYRO_ODR_11 = 0x0B, GYRO_ODR_12 = 0x0C, GYRO_ODR_13 = 0x0D
}
 

Gyroscope output data rates.

More...
enum  GyroBandWidthParam { GYRO_BWP_0 = 0, GYRO_BWP_1, GYRO_BWP_2 }
 

Gyroscope bandwidth paramaters.

More...
enum  GyroRange {
  DPS_2000 = 0, DPS_1000, DPS_500, DPS_250,
  DPS_125
}
 

Gyroscope ranges.

More...

Detailed Description

BMI160_I2C - supports BMI160 object with I2C interface.

Definition at line 649 of file bmi160.h.


Member Enumeration Documentation

enum AccBandWidthParam [inherited]

Accelerometer bandwidth parameters.

Definition at line 276 of file bmi160.h.

enum AccOutputDataRate [inherited]

Accelerometer output data rates.

Definition at line 259 of file bmi160.h.

enum AccRange [inherited]

Accelerometer ranges.

Definition at line 296 of file bmi160.h.

enum AccUnderSampling [inherited]

Accelerometer undersampling.

Definition at line 289 of file bmi160.h.

enum Commands [inherited]

Enumerated commands used with CMD register.

Definition at line 395 of file bmi160.h.

enum ErrorCodes [inherited]

Enumerated error codes.

Definition at line 231 of file bmi160.h.

enum GyroBandWidthParam [inherited]

Gyroscope bandwidth paramaters.

Definition at line 348 of file bmi160.h.

enum GyroOutputDataRate [inherited]

Gyroscope output data rates.

Definition at line 335 of file bmi160.h.

enum GyroRange [inherited]

Gyroscope ranges.

Definition at line 356 of file bmi160.h.

enum PowerModes [inherited]

Enumerated power modes.

Definition at line 385 of file bmi160.h.

enum Registers [inherited]

BMI160 registers.

Definition at line 102 of file bmi160.h.

enum SensorAxis [inherited]

Sensor Axis.

Definition at line 68 of file bmi160.h.

enum Sensors [inherited]

Sensor types.

Definition at line 60 of file bmi160.h.


Constructor & Destructor Documentation

BMI160_I2C ( I2C *  i2cBus,
uint8_t  i2cAdrs 
)

BMI160_I2C Constructor.


On Entry:

Parameters:
[in]i2cBus- reference to I2C bus for this device
[in]i2cAdrs- 7-bit I2C address

On Exit:

Parameters:
[out]none
Returns:
none

Definition at line 38 of file bmi160_i2c.cpp.

BMI160_I2C ( I2C *  i2cBus,
uint8_t  i2cAdrs,
InterruptIn *  int_pin 
)

BMI160_I2C Constructor.


On Entry:

Parameters:
[in]i2cBus- reference to I2C bus for this device
[in]i2cAdrs- 7-bit I2C address
[in]int_pin- Interrupt pin

On Exit:

Parameters:
[out]none
Returns:
none

Definition at line 44 of file bmi160_i2c.cpp.


Member Function Documentation

int32_t getGyroAccXYZandSensorTime ( SensorData accData,
SensorData gyroData,
SensorTime sensorTime,
AccRange  accRange,
GyroRange  gyroRange 
) [inherited]

Get Gyroscope/Accelerometer data and sensor time.


On Entry:

Parameters:
[in]accData- Sensor data structure for accelerometer
[in]gyroData- Sensor data structure for gyroscope
[in]sensorTime- SensorTime data structure
[in]accRange- Accelerometer range
[in]gyroRange- Gyroscope range

On Exit:

Parameters:
[out]accData- Synchronized accelerometer data
[out]gyroData- Synchronized gyroscope data
[out]sensorTime- Synchronized sensor time
Returns:
0 on success, non 0 on failure

Definition at line 453 of file bmi160.cpp.

int32_t getSensorAxis ( SensorAxis  axis,
AxisData data,
AccRange  range 
) [inherited]

Get sensor axis.


On Entry:

Parameters:
[in]axis- Sensor axis
[in]data- AxisData structure
[in]range- Sensor range

On Exit:

Parameters:
[out]data- Structure holds raw and scaled axis data
Returns:
0 on success, non 0 on failure

Definition at line 143 of file bmi160.cpp.

int32_t getSensorConfig ( AccConfig config ) [inherited]

Get sensor configuration.


On Entry:

Parameters:
[in]config- Sensor configuration data structure

On Exit:

Parameters:
[out]config- on success, holds sensor's current configuration
Returns:
0 on success, non 0 on failure

Definition at line 101 of file bmi160.cpp.

int32_t getSensorTime ( SensorTime sensorTime ) [inherited]

Get sensor time.


On Entry:

Parameters:
[in]sensorTime- SensorTime structure for data

On Exit:

Parameters:
[out]sensorTime- Holds sensor time on success
Returns:
returns 0 on success, non 0 on failure

Definition at line 575 of file bmi160.cpp.

int32_t getSensorXYZ ( SensorData data,
AccRange  range 
) [inherited]

Get sensor xyz axis.


On Entry:

Parameters:
[in]data- SensorData structure
[in]range- Sensor range

On Exit:

Parameters:
[out]data- Structure holds raw and scaled data for all three axis
Returns:
0 on success, non 0 on failure

Definition at line 251 of file bmi160.cpp.

int32_t getSensorXYZandSensorTime ( SensorData data,
SensorTime sensorTime,
AccRange  range 
) [inherited]

Get sensor xyz axis and sensor time.


On Entry:

Parameters:
[in]data- SensorData structure
[in]sensorTime- SensorTime structure for data
[in]range- Sensor range

On Exit:

Parameters:
[out]data- Structure holds raw and scaled data for all three axis
[out]sensorTime- Holds sensor time on success
Returns:
0 on success, non 0 on failure

Definition at line 349 of file bmi160.cpp.

int32_t getTemperature ( float *  temp ) [inherited]

Get die temperature.


On Entry:

Parameters:
[in]temp- pointer to float for temperature

On Exit:

Parameters:
[out]temp- on success, holds the die temperature
Returns:
0 on success, non 0 on failure

Definition at line 592 of file bmi160.cpp.

int32_t readBlock ( Registers  startReg,
Registers  stopReg,
uint8_t *  data 
) [virtual]

Reads a block of registers.


User must ensure that all registers between 'startReg' and 'stopReg' exist and are readable. Function reads up to, including, 'stopReg'.

On Entry:

Parameters:
[in]startReg- register to start reading from
[in]stopReg- register to stop reading from
[in]data- pointer to memory for storing read data

On Exit:

Parameters:
[out]data- holds contents of read registers on success
Returns:
0 on success, non 0 on failure

Definition at line 75 of file bmi160_i2c.cpp.

int32_t readRegister ( Registers  reg,
uint8_t *  data 
) [virtual]

Reads a single register.


On Entry:

Parameters:
[in]data- pointer to memory for storing read data

On Exit:

Parameters:
[out]data- holds contents of read register on success
Returns:
0 on success, non 0 on failure

Definition at line 51 of file bmi160_i2c.cpp.

int32_t reset (  ) [inherited]

Soft reset.

Definition at line 717 of file bmi160.cpp.

int32_t setSampleRate ( int  sample_rate ) [inherited]

<25Hz

<50Hz

<100Hz

<200Hz

<400Hz

<800Hz

<1600Hz

<3200Hz

Definition at line 539 of file bmi160.cpp.

int32_t setSensorConfig ( const AccConfig config ) [inherited]

Configure sensor.


On Entry:

Parameters:
[in]config- sSensor configuration data structure

On Exit:

Parameters:
[out]none
Returns:
0 on success, non 0 on failure

Definition at line 76 of file bmi160.cpp.

int32_t setSensorPowerMode ( Sensors  sensor,
PowerModes  pwrMode 
) [inherited]

Sets sensors power mode through CMD register.


Observe command execution times given in datasheet.

On Entry:

Parameters:
[in]sensor- Sensor which power mode we are setting
[in]pwrMode- Desired powermode of the sensor

On Exit:

Parameters:
[out]
Returns:
0 on success, non 0 on failure

Definition at line 48 of file bmi160.cpp.

int32_t writeBlock ( Registers  startReg,
Registers  stopReg,
const uint8_t *  data 
) [virtual]

Writes a block of registers.


User must ensure that all registers between 'startReg' and 'stopReg' exist and are writeable. Function writes up to, including, 'stopReg'.

On Entry:

Parameters:
[in]startReg- register to start writing at
[in]stopReg- register to stop writing at
[in]data- pointer to data to write to registers

On Exit:

Parameters:
[out]none
Returns:
0 on success, non 0 on failure

Definition at line 92 of file bmi160_i2c.cpp.

int32_t writeRegister ( Registers  reg,
const uint8_t  data 
) [virtual]

Writes a single register.


On Entry:

Parameters:
[in]data- data to write to register

On Exit:

Parameters:
[out]none
Returns:
0 on success, non 0 on failure

Definition at line 66 of file bmi160_i2c.cpp.


Field Documentation

const AccConfig DEFAULT_ACC_CONFIG [static, inherited]

Accelerometer default configuration.

Definition at line 319 of file bmi160.h.

const GyroConfig DEFAULT_GYRO_CONFIG [static, inherited]

Gyroscope default configuration.

Definition at line 380 of file bmi160.h.

const uint8_t I2C_ADRS_SDO_HI = 0x69 [static]

BMI160 optional I2C address.

Definition at line 656 of file bmi160.h.

const uint8_t I2C_ADRS_SDO_LO = 0x68 [static]

BMI160 default I2C address.

Definition at line 654 of file bmi160.h.

const uint8_t RTN_NO_ERROR = 0 [static, inherited]

Return value on success.

Definition at line 57 of file bmi160.h.

const float SENSOR_TIME_LSB = 39e-6 [static, inherited]

Period of internal counter.

Definition at line 90 of file bmi160.h.