Microchip® Advanced Software Framework

bma220.h File Reference

Bosch BMA220 3-axis accelerometer driver.

This file contains functions for initializing and reading data from a Bosch BMA220 3-axis accelerometer.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>

Macros

#define BMA220_DATA_RESOLUTION   (6)
 
#define BMA220_SPI_MODE   (4)
 
#define BMA220_TWI_ADDR   (0x0b)
 
#define BMA220_ZERO_G_OFFSET   (95) /* +/- 95 mg @ 2g FS resolution */
 
#define get_field(reg, mask, offset)   (((reg) & (mask)) >> (offset))
 
#define HYSTERESIS_IN_G(hysteresis, grange)   (((threshold) * 4) / (grange))
 convert real G values into hysteresis register values More...
 
#define set_field(reg, mask, value)   ((reg) & ~(mask)) | ((value) & (mask))
 
#define THRESHOLD_IN_G(threshold, grange)   (((threshold) * 16) / (grange))
 convert real G values into register values More...
 
#define BMA220_ID_VAL   (0xdd) /* BMA220 chip ID (always ddh) */
 BMA220 Register Bit Definitions. More...
 
#define HIGH_DUR_FIELD   (0x3f) /* high-g duration mask */
 
#define HIGH_HY_FIELD   (0xc0) /* high-g hysteresis mask */
 
#define HIGH_TH_FIELD   (0x0f) /* high-g threshold mask */
 
#define LOW_TH_FIELD   (0xf0) /* low-g threshold mask */
 
#define LOW_DUR_FIELD   (0x3f) /* low-g duration mask */
 
#define LOW_HY_FIELD   (0xc0) /* low-g hysteresis mask */
 
#define TT_DUR_FIELD   (0x07) /* tap duration mask */
 
#define TT_DUR_50MS   (0)
 
#define TT_DUR_105MS   (1)
 
#define TT_DUR_150MS   (2)
 
#define TT_DUR_219MS   (3
 
#define TT_DUR_250MS   (4)
 
#define TT_DUR_375MS   (5)
 
#define TT_DUR_500MS   (6)
 
#define TT_DUR_700MS   (7)
 
#define TT_TH_FIELD   (0x78) /* tap threshold mask */
 
#define TT_FILT_FIELD   (0x80) /* tap filter mask */
 
#define SLOPE_DUR_FIELD   (0x03)
 
#define SLOPE_DUR_1   (0)
 
#define SLOPE_DUR_2   (1)
 
#define SLOPE_DUR_3   (2)
 
#define SLOPE_DUR_4   (3)
 
#define SLOPE_TH_FIELD   (0x3c)
 
#define SLOPE_FILT_FIELD   (0x40)
 
#define ORIENT_EX_FIELD   (0x80)
 
#define TT_SAMP_FIELD   (0x03)
 
#define ORIENT_BLOCKING_FIELD   (0x0c)
 
#define TIP_EN_FIELD   (0x10)
 
#define INT_SIGN_FIELD   (0x01)
 
#define INT_FIRST_Z_FIELD   (0x02)
 
#define INT_FIRST_Y_FIELD   (0x04)
 
#define INT_FIRST_X_FIELD   (0x08)
 
#define ORIENT_FIELD   (0x70)
 
#define ORIENT_INT_FIELD   (0x80)
 
#define SLOPE_INT_FIELD   (0x01)
 
#define DATA_INT_FIELD   (0x02)
 
#define HIGH_INT_FIELD   (0x04)
 
#define LOW_INT_FIELD   (0x08)
 
#define TT_INT_FIELD   (0x10)
 
#define EN_TT_Z_FIELD   (0x01)
 
#define EN_TT_Y_FIELD   (0x02)
 
#define EN_TT_X_FIELD   (0x04)
 
#define EN_SLOPE_Z_FIELD   (0x08)
 
#define EN_SLOPE_Y_FIELD   (0x10)
 
#define EN_SLOPE_X_FIELD   (0x20)
 
#define EN_ORIENT_FIELD   (0x40)
 
#define EN_DATA_FIELD   (0x80)
 
#define EN_HIGH_Z_FIELD   (0x01)
 
#define EN_HIGH_Y_FIELD   (0x02)
 
#define EN_HIGH_X_FIELD   (0x04)
 
#define EN_LOW_FIELD   (0x08)
 
#define LATCH_INT_FIELD   (0x70)
 
#define LATCH_INT_OFF   (0) /* unlatched */
 
#define LATCH_INT_250MS   (1) /* 0.25s latch time */
 
#define LATCH_INT_500MS   (2) /* 0.5s latch time */
 
#define LATCH_INT_1000MS   (3) /* 1s latch time */
 
#define LATCH_INT_2000MS   (4) /* 2s latch time */
 
#define LATCH_INT_4000MS   (5) /* 4s latch time */
 
#define LATCH_INT_8000MS   (6) /* 8s latch time */
 
#define LATCH_INT_ON   (7) /* permanent latch */
 
#define RESET_INT   (0x80) /* w/o software reset bit */
 
#define EN_Z_CHANNEL_FIELD   (0x01)
 
#define EN_Y_CHANNEL_FIELD   (0x02)
 
#define EN_X_CHANNEL_FIELD   (0x04)
 
#define SLEEP_DUR_FIELD   (0x38)
 
#define SLEEP_DUR_2MS   (0)
 
#define SLEEP_DUR_10MS   (1)
 
#define SLEEP_DUR_25MS   (2)
 
#define SLEEP_DUR_50MS   (3)
 
#define SLEEP_DUR_100MS   (4)
 
#define SLEEP_DUR_500MS   (5)
 
#define SLEEP_DUR_1000MS   (6)
 
#define SLEEP_DUR_2000MS   (7)
 
#define SLEEP_ENABLE   (0x40)
 
#define FILTER_CONFIG_FIELD   (0x0f)
 
#define BANDWIDTH_1000HZ   (0)
 
#define BANDWIDTH_500HZ   (1)
 
#define BANDWIDTH_250HZ   (2)
 
#define BANDWIDTH_125HZ   (3)
 
#define BANDWIDTH_64HZ   (4)
 
#define BANDWIDTH_32HZ   (5)
 
#define SERIAL_HIGH_BW_FIELD   (0x80)
 
#define RANGE_FIELD   (0x03)
 
#define RANGE_2G   (0)
 
#define RANGE_4G   (1)
 
#define RANGE_8G   (2)
 
#define RANGE_16G   (3)
 
#define SBIST_FIELD   (0x0c)
 
#define SBIST_OFF   (0)
 
#define SBIST_X_AXIS   (1)
 
#define SBIST_Y_AXIS   (2)
 
#define SBIST_Z_AXIS   (3)
 
#define SBIST_SIGN_FIELD   (0x70)
 
#define SBIST_SIGN_POSITIVE   (0)
 
#define SBIST_SIGN_NEGATIVE   (1)
 
#define SPI3_FIELD   (0x01) /* SPI3 ENABLE */
 
#define WDT_TO_SEL_FIELD   (0x02) /* WATCHDOG TIMEOUT SELECT */
 
#define WDT_TO_EN_FIELD   (0x04) /* WATCHDOG TIMEOUT ENABLE */
 

Enumerations

enum  bma220_register_t {
  BMA220_CHIP_ID = 0,
  BMA220_CHIP_VERSION,
  BMA220_X_AXIS_DATA,
  BMA220_Y_AXIS_DATA,
  BMA220_Z_AXIS_DATA,
  BMA220_HG_CONFIG,
  BMA220_HG_LG_THRESHOLD,
  BMA220_LG_CONFIG,
  BMA220_TAP_CONFIG,
  BMA220_SLOPE_CONFIG,
  BMA220_DIRECTION_CONFIG,
  BMA220_DIRECTION_STATUS,
  BMA220_INT_STATUS,
  BMA220_INT_ENABLE1,
  BMA220_INT_ENABLE2,
  BMA220_SLEEP_CONFIG,
  BMA220_BANDWIDTH_CONFIG,
  BMA220_RANGE_SELFTEST,
  BMA220_12_RSVD,
  BMA220_13_RSVD,
  BMA220_14_RSVD,
  BMA220_15_RSVD,
  BMA220_16_RSVD,
  BMA220_SPI_MODE_SELECT,
  BMA220_SUSPEND_MODE,
  BMA220_SOFTRESET
}
 Standard Register Addresses. More...
 

Functions

bool bma220_init (sensor_t *, int)
 Bosch BMA220 accelerometer driver initialization. More...
 

#define BANDWIDTH_1000HZ   (0)
#define BANDWIDTH_125HZ   (3)
#define BANDWIDTH_250HZ   (2)
#define BANDWIDTH_32HZ   (5)
#define BANDWIDTH_500HZ   (1)
#define BANDWIDTH_64HZ   (4)
#define BMA220_DATA_RESOLUTION   (6)

Referenced by bma220_init().

#define BMA220_ID_VAL   (0xdd) /* BMA220 chip ID (always ddh) */

BMA220 Register Bit Definitions.

Referenced by bma220_init().

#define BMA220_SPI_MODE   (4)
#define BMA220_TWI_ADDR   (0x0b)
#define BMA220_ZERO_G_OFFSET   (95) /* +/- 95 mg @ 2g FS resolution */
#define DATA_INT_FIELD   (0x02)
#define EN_DATA_FIELD   (0x80)

Referenced by bma220_event().

#define EN_HIGH_X_FIELD   (0x04)

Referenced by bma220_event().

#define EN_HIGH_Y_FIELD   (0x02)

Referenced by bma220_event().

#define EN_HIGH_Z_FIELD   (0x01)

Referenced by bma220_event().

#define EN_LOW_FIELD   (0x08)

Referenced by bma220_event().

#define EN_ORIENT_FIELD   (0x40)
#define EN_SLOPE_X_FIELD   (0x20)

Referenced by bma220_event().

#define EN_SLOPE_Y_FIELD   (0x10)

Referenced by bma220_event().

#define EN_SLOPE_Z_FIELD   (0x08)

Referenced by bma220_event().

#define EN_TT_X_FIELD   (0x04)

Referenced by bma220_event().

#define EN_TT_Y_FIELD   (0x02)

Referenced by bma220_event().

#define EN_TT_Z_FIELD   (0x01)

Referenced by bma220_event().

#define EN_X_CHANNEL_FIELD   (0x04)
#define EN_Y_CHANNEL_FIELD   (0x02)
#define EN_Z_CHANNEL_FIELD   (0x01)
#define FILTER_CONFIG_FIELD   (0x0f)

Referenced by bma220_set_bandwidth().

#define get_field (   reg,
  mask,
  offset 
)    (((reg) & (mask)) >> (offset))
#define HIGH_DUR_FIELD   (0x3f) /* high-g duration mask */
#define HIGH_HY_FIELD   (0xc0) /* high-g hysteresis mask */
#define HIGH_INT_FIELD   (0x04)
#define HIGH_TH_FIELD   (0x0f) /* high-g threshold mask */

Referenced by bma220_set_threshold().

#define HYSTERESIS_IN_G (   hysteresis,
  grange 
)    (((threshold) * 4) / (grange))

convert real G values into hysteresis register values

Note
no range checking is included
See Also
HIGH_HYS, LOW_HYS, SLOPE_HYS, TT_HYS
#define INT_FIRST_X_FIELD   (0x08)
#define INT_FIRST_Y_FIELD   (0x04)
#define INT_FIRST_Z_FIELD   (0x02)
#define INT_SIGN_FIELD   (0x01)
#define LATCH_INT_1000MS   (3) /* 1s latch time */
#define LATCH_INT_2000MS   (4) /* 2s latch time */
#define LATCH_INT_250MS   (1) /* 0.25s latch time */
#define LATCH_INT_4000MS   (5) /* 4s latch time */
#define LATCH_INT_500MS   (2) /* 0.5s latch time */
#define LATCH_INT_8000MS   (6) /* 8s latch time */
#define LATCH_INT_FIELD   (0x70)

Referenced by bma220_event().

#define LATCH_INT_OFF   (0) /* unlatched */
#define LATCH_INT_ON   (7) /* permanent latch */
#define LOW_DUR_FIELD   (0x3f) /* low-g duration mask */
#define LOW_HY_FIELD   (0xc0) /* low-g hysteresis mask */
#define LOW_INT_FIELD   (0x08)
#define LOW_TH_FIELD   (0xf0) /* low-g threshold mask */

Referenced by bma220_set_threshold().

#define ORIENT_BLOCKING_FIELD   (0x0c)
#define ORIENT_EX_FIELD   (0x80)
#define ORIENT_FIELD   (0x70)
#define ORIENT_INT_FIELD   (0x80)
#define RANGE_16G   (3)
#define RANGE_2G   (0)
#define RANGE_4G   (1)
#define RANGE_8G   (2)
#define RANGE_FIELD   (0x03)

Referenced by bma220_set_range().

#define RESET_INT   (0x80) /* w/o software reset bit */

Referenced by bma220_event().

#define SBIST_FIELD   (0x0c)
#define SBIST_OFF   (0)
#define SBIST_SIGN_FIELD   (0x70)
#define SBIST_SIGN_NEGATIVE   (1)
#define SBIST_SIGN_POSITIVE   (0)
#define SBIST_X_AXIS   (1)
#define SBIST_Y_AXIS   (2)
#define SBIST_Z_AXIS   (3)
#define SERIAL_HIGH_BW_FIELD   (0x80)
#define set_field (   reg,
  mask,
  value 
)    ((reg) & ~(mask)) | ((value) & (mask))
#define SLEEP_DUR_1000MS   (6)
#define SLEEP_DUR_100MS   (4)
#define SLEEP_DUR_10MS   (1)
#define SLEEP_DUR_2000MS   (7)
#define SLEEP_DUR_25MS   (2)
#define SLEEP_DUR_2MS   (0)
#define SLEEP_DUR_500MS   (5)
#define SLEEP_DUR_50MS   (3)
#define SLEEP_DUR_FIELD   (0x38)
#define SLEEP_ENABLE   (0x40)

Referenced by bma220_sleep_en().

#define SLOPE_DUR_1   (0)
#define SLOPE_DUR_2   (1)
#define SLOPE_DUR_3   (2)
#define SLOPE_DUR_4   (3)
#define SLOPE_DUR_FIELD   (0x03)
#define SLOPE_FILT_FIELD   (0x40)
#define SLOPE_INT_FIELD   (0x01)
#define SLOPE_TH_FIELD   (0x3c)

Referenced by bma220_set_threshold().

#define SPI3_FIELD   (0x01) /* SPI3 ENABLE */
#define THRESHOLD_IN_G (   threshold,
  grange 
)    (((threshold) * 16) / (grange))

convert real G values into register values

Note
no range checking is included
See Also
HIGH_TH, LOW_TH, SLOPE_TH, TT_TH

Referenced by bma220_set_threshold().

#define TIP_EN_FIELD   (0x10)
#define TT_DUR_105MS   (1)
#define TT_DUR_150MS   (2)
#define TT_DUR_219MS   (3
#define TT_DUR_250MS   (4)
#define TT_DUR_375MS   (5)
#define TT_DUR_500MS   (6)
#define TT_DUR_50MS   (0)
#define TT_DUR_700MS   (7)
#define TT_DUR_FIELD   (0x07) /* tap duration mask */
#define TT_FILT_FIELD   (0x80) /* tap filter mask */
#define TT_INT_FIELD   (0x10)
#define TT_SAMP_FIELD   (0x03)
#define TT_TH_FIELD   (0x78) /* tap threshold mask */

Referenced by bma220_set_threshold().

#define WDT_TO_EN_FIELD   (0x04) /* WATCHDOG TIMEOUT ENABLE */
#define WDT_TO_SEL_FIELD   (0x02) /* WATCHDOG TIMEOUT SELECT */

Standard Register Addresses.

The TWI/I2C register address for a particular register is derived by shifting the SPI register address to the left by one bit. In other words, from I2C->SPI the burst address increment is 0x2 steps.

Enumerator
BMA220_CHIP_ID 
BMA220_CHIP_VERSION 
BMA220_X_AXIS_DATA 
BMA220_Y_AXIS_DATA 
BMA220_Z_AXIS_DATA 
BMA220_HG_CONFIG 
BMA220_HG_LG_THRESHOLD 
BMA220_LG_CONFIG 
BMA220_TAP_CONFIG 
BMA220_SLOPE_CONFIG 
BMA220_DIRECTION_CONFIG 
BMA220_DIRECTION_STATUS 
BMA220_INT_STATUS 
BMA220_INT_ENABLE1 
BMA220_INT_ENABLE2 
BMA220_SLEEP_CONFIG 
BMA220_BANDWIDTH_CONFIG 
BMA220_RANGE_SELFTEST 
BMA220_12_RSVD 
BMA220_13_RSVD 
BMA220_14_RSVD 
BMA220_15_RSVD 
BMA220_16_RSVD 
BMA220_SPI_MODE_SELECT 
BMA220_SUSPEND_MODE 
BMA220_SOFTRESET