upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Types | Public Member Functions | Protected Attributes

API for the BMA220 3-axis Accelerometer. More...

Detailed Description

The BMA220 is a low cost, very small 3-axis accelerometer with 6 bits of resolution. It can also detect orientation and tap events.

The BMA220 has a linear acceleration full scale of 2g/4g/8g/16g.

While not all of the functionality of this device is supported initially, methods and register definitions are provided that should allow an end user to implement whatever features are required.

This driver was developed on a DFRobot BMA (Tiny).

bma220.jpg
// Instantiate an BMA220 using default parameters (bus 0, addr 0x0a)
upm::BMA220 sensor;
// Output data every half second until interrupted
while (shouldRun) {
sensor.update();
float x, y, z;
sensor.getAccelerometer(&x, &y, &z);
cout << "Accelerometer: ";
cout << "AX: " << x << " AY: " << y << " AZ: " << z << endl;
upm_delay_us(500000);
}

Public Types

enum  REG_T {
  REG_CHIPID = 0x00, REG_REVISIONID = 0x02, REG_ACC_X = 0x04, REG_ACC_Y = 0x06,
  REG_ACC_Z = 0x08, REG_H_HYST_DUR = 0x0a, REG_THRESHOLD = 0x0c, REG_L_HYST_DUR = 0x0e,
  REG_TAP_CONFIG = 0x10, REG_SLOPE_CONFIG = 0x12, REG_TAP_CONFIG2 = 0x14, REG_INT_STATUS1 = 0x16,
  REG_INT_STATUS2 = 0x18, REG_ENABLE_CONFIG = 0x1a, REG_ENABLE_CONFIG2 = 0x1c, REG_ENABLE_CONFIG3 = 0x1e,
  REG_FILTER_CONFIG = 0x20, REG_SBIST_FSL_CONFIG = 0x22, REG_I2C_WATCHDOG = 0x2e, REG_SUSPEND = 0x30,
  REG_SOFTRESET = 0x32
}
 
enum  H_HYST_DUR_HIGH_BITS_T {
  H_HYST_DUR_HIGH_DUR0 = 0x01, H_HYST_DUR_HIGH_DUR1 = 0x02, H_HYST_DUR_HIGH_DUR2 = 0x04, H_HYST_DUR_HIGH_DUR3 = 0x08,
  H_HYST_DUR_HIGH_DUR4 = 0x10, H_HYST_DUR_HIGH_DUR5 = 0x20, _H_HYST_DUR_HIGH_DUR_MASK = 63, _H_HYST_DUR_HIGH_DUR_SHIFT = 0,
  H_HYST_DUR_HIGH_HY1 = 0x40, H_HYST_DUR_HIGH_HY2 = 0x80, _H_HYST_DUR_HIGH_HY_MASK = 3, _H_HYST_DUR_HIGH_HY_SHIFT = 6
}
 
enum  THRESHOLD_BITS_T {
  THRESHOLD_HIGH0 = 0x01, THRESHOLD_HIGH1 = 0x02, THRESHOLD_HIGH2 = 0x04, THRESHOLD_HIGH3 = 0x08,
  _THRESHOLD_HIGH_MASK = 15, _THRESHOLD_HIGH_SHIFT = 0, THRESHOLD_LOW0 = 0x10, THRESHOLD_LOW1 = 0x20,
  THRESHOLD_LOW2 = 0x40, THRESHOLD_LOW3 = 0x80, _THRESHOLD_LOW_MASK = 15, _THRESHOLD_LOW_SHIFT = 4
}
 
enum  L_HYST_DUR_LOW_BITS_T {
  L_HYST_DUR_LOW_DUR0 = 0x01, L_HYST_DUR_LOW_DUR1 = 0x02, L_HYST_DUR_LOW_DUR2 = 0x04, L_HYST_DUR_LOW_DUR3 = 0x08,
  L_HYST_DUR_LOW_DUR4 = 0x10, L_HYST_DUR_LOW_DUR5 = 0x20, _L_HYST_DUR_LOW_DUR_MASK = 63, _L_HYST_DUR_LOW_DUR_SHIFT = 0,
  L_HYST_DUR_LOW_HY1 = 0x40, L_HYST_DUR_LOW_HY2 = 0x80, _L_HYST_DUR_LOW_HY_MASK = 3, _L_HYST_DUR_LOW_HY_SHIFT = 6
}
 
enum  TAP_CONFIG_BITS_T {
  TAP_CONFIG_DUR0 = 0x01, TAP_CONFIG_DUR1 = 0x02, TAP_CONFIG_DUR2 = 0x04, _TAP_CONFIG_DUR_MASK = 7,
  _TAP_CONFIG_DUR_SHIFT = 0, TAP_CONFIG_THRESH0 = 0x08, TAP_CONFIG_THRESH1 = 0x10, TAP_CONFIG_THRESH2 = 0x20,
  TAP_CONFIG_THRESH3 = 0x40, _TAP_CONFIG_THRESH_MASK = 15, _TAP_CONFIG_THRESH_SHIFT = 3, TAP_CONFIG_FILTER = 0x80
}
 
enum  SLOPE_CONFIG_BITS_T {
  SLOPE_CONFIG_DUR0 = 0x01, SLOPE_CONFIG_DUR1 = 0x02, _SLOPE_CONFIG_DUR_MASK = 3, _SLOPE_CONFIG_DUR_SHIFT = 0,
  SLOPE_CONFIG_THRESH0 = 0x04, SLOPE_CONFIG_THRESH1 = 0x08, SLOPE_CONFIG_THRESH2 = 0x10, SLOPE_CONFIG_THRESH3 = 0x20,
  _SLOPE_CONFIG_THRESH_MASK = 15, _SLOPE_CONFIG_THRESH_SHIFT = 2, SLOPE_CONFIG_FILTER = 0x40, SLOPE_CONFIG_ORIENT_EX = 0x80
}
 
enum  TAP_CONFIG2_BITS_T {
  TAP_CONFIG2_SAMP0 = 0x01, TAP_CONFIG2_SAMP1 = 0x02, _TAP_CONFIG2_SAMP_MASK = 3, _TAP_CONFIG2_SAMP_SHIFT = 0,
  TAP_CONFIG2_ORIENT_BLOCK0 = 0x04, TAP_CONFIG2_ORIENT_BLOCK1 = 0x08, _TAP_CONFIG2_ORIENT_BLOCK_MASK = 3, _TAP_CONFIG2_ORIENT_BLOCK_SHIFT = 2,
  TAP_CONFIG2_TIP_EN = 0x10
}
 
enum  TAP_SAMP_T { TAP_SAMP_2 = 0, TAP_SAMP_4 = 1, TAP_SAMP_8 = 2, TAP_SAMP_16 = 3 }
 
enum  TAP_ORIENT_BLOCK_T { TAP_ORIENT_BLOCK_0 = 0, TAP_ORIENT_BLOCK_2 = 1, TAP_ORIENT_BLOCK_3 = 2, TAP_ORIENT_BLOCK_4 = 3 }
 
enum  INT_STATUS1_BITS_T {
  INT_STATUS1_SIGN = 0x01, INT_STATUS1_FIRST_Z = 0x02, INT_STATUS1_FIRST_Y = 0x04, INT_STATUS1_FIRST_X = 0x08,
  INT_STATUS1_ORIENT0 = 0x10, INT_STATUS1_ORIENT1 = 0x20, INT_STATUS1_ORIENT2 = 0x40, _INT_STATUS1_ORIENT_MASK = 7,
  _INT_STATUS1_ORIENT_SHIFT = 4, INT_STATUS1_ORIENT_INT = 0x80
}
 
enum  CONFIG_ORIENT_T {
  CONFIG_ORI_UP_PORT_UPRIGHT = 0, CONFIG_ORI_UP_PORT_UPSIDE_DOWN = 1, CONFIG_ORI_UP_LAND_LEFT = 2, CONFIG_ORI_UP_LAND_RIGHT = 3,
  CONFIG_ORI_DN_PORT_UPRIGHT = 4, CONFIG_ORI_DN_PORT_UPSIDE_DOWN = 5, CONFIG_ORI_DN_LAND_LEFT = 6, CONFIG_ORI_DN_LAND_RIGHT = 7
}
 
enum  INT_STATUS2_BITS_T {
  INT_STATUS2_SLOPE = 0x01, INT_STATUS2_DATA = 0x02, INT_STATUS2_HIGH = 0x04, INT_STATUS2_LOW = 0x08,
  INT_STATUS2_TAP = 0x10
}
 
enum  ENABLE_CONFIG_BITS_T {
  ENABLE_CONFIG_TT_Z = 0x01, ENABLE_CONFIG_TT_Y = 0x02, ENABLE_CONFIG_TT_X = 0x04, ENABLE_CONFIG_SLOPE_Z = 0x08,
  ENABLE_CONFIG_SLOPE_Y = 0x10, ENABLE_CONFIG_SLOPE_X = 0x20, ENABLE_CONFIG_ORIENT = 0x40, ENABLE_CONFIG_DATA = 0x80
}
 
enum  ENABLE_CONFIG2_BITS_T {
  ENABLE_CONFIG2_HIGH_Z = 0x01, ENABLE_CONFIG2_HIGH_Y = 0x02, ENABLE_CONFIG2_HIGH_X = 0x04, ENABLE_CONFIG2_LOW = 0x08,
  ENABLE_CONFIG2_LAT_INT0 = 0x10, ENABLE_CONFIG2_LAT_INT1 = 0x20, ENABLE_CONFIG2_LAT_INT2 = 0x40, _ENABLE_CONFIG2_LAT_INT_MASK = 7,
  _ENABLE_CONFIG2_LAT_INT_SHIFT = 4, ENABLE_CONFIG2_RESET_INT = 0x80
}
 
enum  CONFIG2_LAT_T {
  CONFIG2_LAT_UNLATCH = 0, CONFIG2_LAT_0_25 = 1, CONFIG2_LAT_0_5 = 2, CONFIG2_LAT_1 = 3,
  CONFIG2_LAT_2 = 4, CONFIG2_LAT_4 = 5, CONFIG2_LAT_8 = 6, CONFIG2_LAT_PERM = 7
}
 
enum  ENABLE_CONFIG3_BITS_T {
  ENABLE_CONFIG3_Z_CHAN = 0x01, ENABLE_CONFIG3_Y_CHAN = 0x02, ENABLE_CONFIG3_X_CHAN = 0x04, ENABLE_CONFIG3_SLEEP_DUR0 = 0x08,
  ENABLE_CONFIG3_SLEEP_DUR1 = 0x10, ENABLE_CONFIG3_SLEEP_DUR2 = 0x20, _ENABLE_CONFIG3_SLEEP_DUR_MASK = 7, _ENABLE_CONFIG3_SLEEP_DUR_SHIFT = 3,
  ENABLE_CONFIG3_SLEEP_EN = 0x40
}
 
enum  SLEEP_DUR_T {
  SLEEP_DUR_2MS = 0, SLEEP_DUR_10MS = 1, SLEEP_DUR_25MS = 2, SLEEP_DUR_50MS = 3,
  SLEEP_DUR_100MS = 4, SLEEP_DUR_500MS = 5, SLEEP_DUR_1S = 6, SLEEP_DUR_2S = 7
}
 
enum  FILTER_CONFIG_BITS_T {
  FILTER_CONFIG_FILTER0 = 0x01, FILTER_CONFIG_FILTER1 = 0x02, FILTER_CONFIG_FILTER2 = 0x04, FILTER_CONFIG_FILTER3 = 0x08,
  _FILTER_CONFIG_FILTER_MASK = 15, _FILTER_CONFIG_FILTER_SHIFT = 0, FILTER_CONFIG_SERIAL_HIGH_BW = 0x80
}
 
enum  FILTER_CONFIG_T {
  FILTER_CONFIG_1KHZ = 0, FILTER_CONFIG_500HZ = 1, FILTER_CONFIG_250HZ = 2, FILTER_CONFIG_125HZ = 3,
  FILTER_CONFIG_64HZ = 4, FILTER_CONFIG_32HZ = 5
}
 
enum  SBIST_FSL_CONFIG_BITS_T {
  REG_SBIST_FSL_RANGE0 = 0x01, REG_SBIST_FSL_RANGE1 = 0x02, _REG_SBIST_FSL_RANGE_MASK = 3, _REG_SBIST_FSL_RANGE_SHIFT = 0,
  REG_SBIST_FSL_SBIST0 = 0x04, REG_SBIST_FSL_SBIST1 = 0x08, _REG_SBIST_FSL_SBIST_MASK = 3, _REG_SBIST_FSL_SBIST_SHIFT = 2,
  REG_SBIST_FSL_SBIST_SIGN = 0x10
}
 
enum  FSL_RANGE_T { FSL_RANGE_2G = 0, FSL_RANGE_4G = 1, FSL_RANGE_8G = 2, FSL_RANGE_16G = 3 }
 
enum  SBIST_T { SBIST_OFF = 0, SBIST_X = 1, SBIST_Y = 2, SBIST_Z = 3 }
 
enum  I2C_WATCHDOG_BITS_T { I2C_WATCHDOG_SPI3 = 0x01, I2C_WATCHDOG_TO_SEL = 0x02, I2C_WATCHDOG_TO_EN = 0x04 }
 

Public Member Functions

 BMA220 (int bus=BMA220_I2C_BUS, uint8_t addr=BMA220_DEFAULT_ADDR)
 
 ~BMA220 ()
 
void update ()
 
uint8_t readReg (uint8_t reg)
 
bool writeReg (uint8_t reg, uint8_t val)
 
uint8_t getChipID ()
 
uint8_t getChipRevision ()
 
bool setAccelerometerScale (FSL_RANGE_T scale)
 
void getAccelerometer (float *x, float *y, float *z)
 
std::vector< float > getAccelerometer ()
 
bool setFilterConfig (FILTER_CONFIG_T filter)
 
bool setSerialHighBW (bool high)
 
bool enableAxes (bool xEn, bool yEn, bool zEn)
 
uint8_t suspend ()
 
uint8_t softReset ()
 
bool sleep (bool enable)
 
bool setSleepDuration (SLEEP_DUR_T dur)
 
bool setLowGThreshold (uint8_t thresh)
 
bool setHighGThreshold (uint8_t thresh)
 
bool setLowGHysteresis (uint8_t hyst)
 
bool setLowGDuration (uint8_t dur)
 
bool setHighGHysteresis (uint8_t hyst)
 
bool setHighGDuration (uint8_t dur)
 
bool setTapDuration (uint8_t dur)
 
bool setTapThreshold (uint8_t thresh)
 
bool enableTapFilter (bool filt)
 
bool setSlopeDuration (uint8_t dur)
 
bool setSlopeThreshold (uint8_t thresh)
 
bool enableSlopeFilter (bool filt)
 
uint8_t getInterruptStatus1 ()
 
CONFIG_ORIENT_T getOrient ()
 
uint8_t getInterruptStatus2 ()
 
bool setInterruptEnables1 (uint8_t bits)
 
uint8_t getInterruptEnables1 ()
 
bool setInterruptEnables2 (uint8_t bits)
 
uint8_t getInterruptEnables2 ()
 
bool setInterruptLatch (CONFIG2_LAT_T lat)
 
bool resetInterrupts ()
 
void installISR (int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
 
void uninstallISR ()
 
mraa::Gpio * get_gpioIntr ()
 

Protected Attributes

mraa::I2c m_i2c
 
mraa::Gpio * m_gpioIntr
 
uint8_t m_addr
 
float m_accelX
 
float m_accelY
 
float m_accelZ
 
float m_accelScale
 

Member Enumeration Documentation

enum REG_T

BMA220 Accelerometer registers

REG_H_HYST_DUR bits

REG_THRESHOLD bits

REG_L_HYST_DUR bits

REG_TAP_CONFIG bits

REG_SLOPE_CONFIG bits

REG_TAP_CONFIG2 bits

enum TAP_SAMP_T

TAP_CONFIG2_SAMP values

TAP_CONFIG2_ORIENT_BLOCK values

REG_INT_STATUS1 bits

INT_STATUS1_ORIENT values

These are values reported by the device if orientation detection is enabled.

REG_INT_STATUS2 bits

REG_ENABLE_CONFIG bits

REG_ENABLE_CONFIG2 bits

ENABLE_CONFIG2_LAT values

These are values that define the interrupt latching behavior

REG_ENABLE_CONFIG3 bits

ENABLE_CONFIG3_SLEEP_DUR values

These are values that define the length of time the device sleeps before sampling when in sleep mode.

REG_FILTER_CONFIG bits

FILTER_CONFIG_FILTER values

These are values that define the digital filtering frequency

REG_SBIST_FSL_CONFIG bits

REG_SBIST_FSL_RANGE values

These are values that define the Full Scale configuration

enum SBIST_T

REG_SBIST_FSL_SBIST values

These are values that enable self test mode

REG_I2C_WATCHDOG bits

Constructor & Destructor Documentation

BMA220 ( int  bus = BMA220_I2C_BUS,
uint8_t  addr = BMA220_DEFAULT_ADDR 
)

BMA220 constructor

Parameters
busi2c bus to use
addrthe address for this device

Here is the call graph for this function:

~BMA220 ( )

BMA220 Destructor

Here is the call graph for this function:

Member Function Documentation

void update ( void  )

update the accelerometer values

Here is the call graph for this function:

uint8_t readReg ( uint8_t  reg)

read a register

Parameters
regthe register to read
Returns
the value of the register

Here is the caller graph for this function:

bool writeReg ( uint8_t  reg,
uint8_t  val 
)

write to a register

Parameters
regthe register to write to
valthe value to write
Returns
true if successful, false otherwise

Here is the caller graph for this function:

uint8_t getChipID ( )

return the chip ID

Returns
the chip ID (usually 0xdd)

Here is the call graph for this function:

uint8_t getChipRevision ( )

return the chip revision

Returns
the chip revision (usually 0x00)

Here is the call graph for this function:

bool setAccelerometerScale ( FSL_RANGE_T  scale)

set the scaling mode of the accelerometer (2g/4g/8g/16g)

Parameters
scaleone of the FSL_RANGE_T values
Returns
true if successful, false otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

void getAccelerometer ( float *  x,
float *  y,
float *  z 
)

get the accelerometer values in gravities

Parameters
xthe returned x value, if arg is non-NULL
ythe returned y value, if arg is non-NULL
zthe returned z value, if arg is non-NULL
std::vector< float > getAccelerometer ( )

get the accelerometer values in gravities

Returns
std::vector containing X, Y, Z acceleration values
bool setFilterConfig ( FILTER_CONFIG_T  filter)

set the filtering configuration

Parameters
filterone of the FILTER_CONFIG_T values
Returns
true if successful

Here is the call graph for this function:

bool setSerialHighBW ( bool  high)

enable or disable high bandwidth serial access (1Khz). This essentially disables filtering and makes the raw unfiltered data available in the axis registers.

Parameters
hightrue to enable high bw access, false otherwise
Returns
true if successful

Here is the call graph for this function:

bool enableAxes ( bool  xEn,
bool  yEn,
bool  zEn 
)

enable or disable axis channels

Parameters
xEntrue to enable the axis, false otherwise
yEntrue to enable the axis, false otherwise
zEntrue to enable the axis, false otherwise
Returns
true if successful

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t suspend ( )

place the device into, or take the device out of suspend mode

Returns
0x00 if the device was in active mode, 0xff if the device was in suspend mode

Here is the call graph for this function:

uint8_t softReset ( )

place the device into, or take the device out of soft reset mode

Returns
0x00 if the device was in active mode, 0xff if the device was in soft reset mode

Here is the call graph for this function:

bool sleep ( bool  enable)

place the device into, or take the device out of low power mode. See the datasheet for information on how low power mode is implemented on this device.

Parameters
enabletrue to set low power mode, false otherwise
Returns
true if successful

Here is the call graph for this function:

bool setSleepDuration ( SLEEP_DUR_T  dur)

when in low power (sleep) mode, specify how often the device wakes up to acquire samples.

Parameters
durone of the SLEEP_DUR_T values
Returns
true if successful

Here is the call graph for this function:

bool setLowGThreshold ( uint8_t  thresh)

specify the threshold for low G detection

Parameters
threshsee the datasheet
Returns
true if successful

Here is the call graph for this function:

bool setHighGThreshold ( uint8_t  thresh)

specify the threshold for high G detection

Parameters
threshsee the datasheet
Returns
true if successful

Here is the call graph for this function:

bool setLowGHysteresis ( uint8_t  hyst)

specify the hysteresis for low G detection

Parameters
hyst2 bit hysteresis value
Returns
true if successful

Here is the call graph for this function:

bool setLowGDuration ( uint8_t  dur)

specify the sample duration for low G detection

Parameters
durthe number of samples (depends on bandwidth)
Returns
true if successful

Here is the call graph for this function:

bool setHighGHysteresis ( uint8_t  hyst)

specify the hysteresis for high G detection

Parameters
hyst2 bit hysteresis value
Returns
true if successful

Here is the call graph for this function:

bool setHighGDuration ( uint8_t  dur)

specify the sample duration for high G detection

Parameters
durthe number of samples (depends on bandwidth)
Returns
true if successful

Here is the call graph for this function:

bool setTapDuration ( uint8_t  dur)

specify the sample duration for tap detection

Parameters
durthe number of samples (depends on bandwidth)
Returns
true if successful

Here is the call graph for this function:

bool setTapThreshold ( uint8_t  thresh)

specify the threshold for tap detection

Parameters
threshsee the datasheet
Returns
true if successful

Here is the call graph for this function:

bool enableTapFilter ( bool  filt)

unable to disable tap filtering

Parameters
filttrue to enable, false otherwise
Returns
true if successful

Here is the call graph for this function:

bool setSlopeDuration ( uint8_t  dur)

specify the sample duration for slope detection

Parameters
durthe number of samples (depends on bandwidth)
Returns
true if successful

Here is the call graph for this function:

bool setSlopeThreshold ( uint8_t  thresh)

specify the threshold for slope detection

Parameters
threshsee the datasheet
Returns
true if successful

Here is the call graph for this function:

bool enableSlopeFilter ( bool  filt)

enable or disable slope filtering

Parameters
filttrue to enable filtering, false otherwise
Returns
true if successful

Here is the call graph for this function:

uint8_t getInterruptStatus1 ( )

return a bitmask of the interrupt status 1 register

Returns
bitmask of INT_STATUS1_BITS_T bits (minus the orient value)

Here is the call graph for this function:

BMA220::CONFIG_ORIENT_T getOrient ( )

return the orient value from the interrupt status 1 register

Returns
one of the CONFIG_ORIENT_T values

Here is the call graph for this function:

uint8_t getInterruptStatus2 ( )

return a bitmask of the interrupt status 2 register

Returns
bitmask of INT_STATUS2_BITS_T bits

Here is the call graph for this function:

bool setInterruptEnables1 ( uint8_t  bits)

enable interrupts for events in interrupt config register 1

Parameters
bitsbitmask of ENABLE_CONFIG_BITS_T values
Returns
true if successful

Here is the call graph for this function:

uint8_t getInterruptEnables1 ( )

return the enabled interrupts for events in interrupt config register 1

Returns
bitmask of ENABLE_CONFIG_BITS_T values

Here is the call graph for this function:

bool setInterruptEnables2 ( uint8_t  bits)

enable interrupts for events in interrupt config register 2

Parameters
bitsbitmask of ENABLE_CONFIG2_BITS_T values
Returns
true if successful

Here is the call graph for this function:

uint8_t getInterruptEnables2 ( )

return the enabled interrupts for events in interrupt config register 2

Returns
bitmask of ENABLE_CONFIG2_BITS_T values

Here is the call graph for this function:

bool setInterruptLatch ( CONFIG2_LAT_T  lat)

configure interrupt latching behavior

Parameters
latone of the CONFIG2_LAT_T values
Returns
true if successful

Here is the call graph for this function:

bool resetInterrupts ( )

reset the interrupt controller. This should be called after any changes are made to interrupt configuration, or to reset interrupts if latched interrupts have been enabled and an interrupt has occurred..

Returns
true if successful

Here is the call graph for this function:

void installISR ( int  gpio,
mraa::Edge  level,
void(*)(void *)  isr,
void *  arg 
)

install an interrupt handler.

Parameters
gpiogpio pin to use as interrupt pin
levelthe interrupt trigger level (one of mraa::Edge values). Make sure that you have configured the interrupt pin properly for whatever level you choose.
isrthe interrupt handler, accepting a void * argument
argthe argument to pass the the interrupt handler

Here is the call graph for this function:

void uninstallISR ( )

uninstall a previously installed interrupt handler

Here is the caller graph for this function:


The documentation for this class was generated from the following files: