MMA8x5x Accelerometer

Driver for the Freescale MMA8x5x 3-Axis accelerometer. More...

Detailed Description

The driver will initialize the accelerometer for best resolution. After the initialization the accelerometer will make measurements at periodic times. The measurements period and scale range can be determined by accelerometer initialization. This driver only implements basic functionality (i.e. no support for external interrupt pins).

Files

file  mma8x5x.h
 Interface definition for the MMA8x5x accelerometer driver.
 

Data Structures

struct  mma8x5x_params_t
 Configuration parameters. More...
 
struct  mma8x5x_t
 Device descriptor for MMA8x5x accelerometers. More...
 
struct  mma8x5x_data_t
 Data type for the result data. More...
 

Macros

#define MMA8X5X_I2C_ADDRESS   0x1D
 Accelerometer Default Address.
 

Enumerations

enum  {
  MMA8X5X_TYPE_MMA8652 = 0x4a, MMA8X5X_TYPE_MMA8653 = 0x5a, MMA8X5X_TYPE_MMA8451 = 0x1a, MMA8X5X_TYPE_MMA8452 = 0x2a,
  MMA8X5X_TYPE_MMA8453 = 0x3a
}
 Devices supported by this driver. More...
 
enum  {
  MMA8X5X_RATE_800HZ = (0 << 3), MMA8X5X_RATE_400HZ = (1 << 3), MMA8X5X_RATE_200HZ = (2 << 3), MMA8X5X_RATE_100HZ = (3 << 3),
  MMA8X5X_RATE_50HZ = (4 << 3), MMA8X5X_RATE_1HZ25 = (5 << 3), MMA8X5X_RATE_6HZ25 = (6 << 3), MMA8X5X_RATE_1HZ56 = (7 << 3)
}
 Available sampling rates. More...
 
enum  { MMA8X5X_RANGE_2G = 0, MMA8X5X_RANGE_4G = 1, MMA8X5X_RANGE_8G = 2 }
 Available range options. More...
 
enum  {
  MMA8X5X_OK = 0, MMA8X5X_DATA_READY = 1, MMA8X5X_NOI2C = -1, MMA8X5X_NODEV = -2,
  MMA8X5X_NODATA = -3
}
 Named return values. More...
 

Functions

int mma8x5x_init (mma8x5x_t *dev, const mma8x5x_params_t *params)
 Initialize the MMA8x5x accelerometer driver. More...
 
void mma8x5x_set_user_offset (mma8x5x_t *dev, int8_t x, int8_t y, int8_t z)
 Set user offset correction. More...
 
void mma8x5x_set_active (mma8x5x_t *dev)
 Set active mode, this enables periodic measurements. More...
 
void mma8x5x_set_standby (mma8x5x_t *dev)
 Set standby mode. More...
 
int mma8x5x_is_ready (mma8x5x_t *dev)
 Check for new set of measurement data. More...
 
void mma8x5x_read (mma8x5x_t *dev, mma8x5x_data_t *data)
 Read accelerometer's data. More...
 

Enumeration Type Documentation

anonymous enum
Enumerator
MMA8X5X_TYPE_MMA8652 

MMA8652.

MMA8X5X_TYPE_MMA8653 

MMA8653.

MMA8X5X_TYPE_MMA8451 

MMA8451.

MMA8X5X_TYPE_MMA8452 

MMA8452.

MMA8X5X_TYPE_MMA8453 

MMA8453.

Definition at line 47 of file mma8x5x.h.

anonymous enum
Enumerator
MMA8X5X_RATE_800HZ 

800 Hz Ouput Data Rate in WAKE mode

MMA8X5X_RATE_400HZ 

400 Hz Ouput Data Rate in WAKE mode

MMA8X5X_RATE_200HZ 

200 Hz Ouput Data Rate in WAKE mode

MMA8X5X_RATE_100HZ 

100 Hz Ouput Data Rate in WAKE mode

MMA8X5X_RATE_50HZ 

50 Hz Ouput Data Rate in WAKE mode

MMA8X5X_RATE_1HZ25 

12.5 Hz Ouput Data Rate in WAKE mode

MMA8X5X_RATE_6HZ25 

6.25 Hz Ouput Data Rate in WAKE mode

MMA8X5X_RATE_1HZ56 

1.56 Hz Ouput Data Rate in WAKE mode

Definition at line 58 of file mma8x5x.h.

anonymous enum
Enumerator
MMA8X5X_RANGE_2G 

+/- 2 g Full Scale Range

MMA8X5X_RANGE_4G 

+/- 4 g Full Scale Range

MMA8X5X_RANGE_8G 

+/- 8 g Full Scale Range

Definition at line 72 of file mma8x5x.h.

anonymous enum
Enumerator
MMA8X5X_OK 

everything was fine

MMA8X5X_DATA_READY 

new data ready to be read

MMA8X5X_NOI2C 

I2C communication failed.

MMA8X5X_NODEV 

no MMA8X5X device found on the bus

MMA8X5X_NODATA 

no data available

Definition at line 81 of file mma8x5x.h.

Function Documentation

int mma8x5x_init ( mma8x5x_t dev,
const mma8x5x_params_t params 
)
Parameters
[out]devdevice descriptor of accelerometer to initialize
[in]paramsconfiguration parameters
Returns
MMA8X5X_OK on success
MMA8X5X_NOI2C if initialization of I2C bus failed
MMA8X5X_NODEV if accelerometer test failed
int mma8x5x_is_ready ( mma8x5x_t dev)
Parameters
[in]devdevice descriptor of accelerometer
Returns
MMA8X5X_DATA_READY if new sample is ready
MMA8X5X_NODATA if nothing is available
void mma8x5x_read ( mma8x5x_t dev,
mma8x5x_data_t data 
)

Acceleration will be calculated as:
$ a = \frac{value \cdot 1000}{1024} \cdot mg $ if full scale is set to 2g
$ a = \frac{value \cdot 1000}{512} \cdot mg $ if full scale is set to 4g
$ a = \frac{value \cdot 1000}{256} \cdot mg $ if full scale is set to 8g

Parameters
[in]devdevice descriptor of accelerometer
[out]datathe current acceleration data [in mg]
void mma8x5x_set_active ( mma8x5x_t dev)
Parameters
[out]devdevice descriptor of accelerometer to reset
void mma8x5x_set_standby ( mma8x5x_t dev)
Parameters
[in]devdevice descriptor of accelerometer
void mma8x5x_set_user_offset ( mma8x5x_t dev,
int8_t  x,
int8_t  y,
int8_t  z 
)

Offset correction registers will be erased after accelerometer reset.

Parameters
[out]devdevice descriptor of accelerometer to initialize
[in]xoffset correction value for x-axis
[in]yoffset correction value for y-axis
[in]zoffset correction value for z-axis