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

Detailed Description

Driver for the Freescale MMA8x5x 3-Axis accelerometer.

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).

This driver provides [S]ensor [A]ctuator [U]ber [L]ayer capabilities.

Modules

 MMA8x5x Accelerometer driver compile configuration
 

Files

file  mma8x5x.h
 Interface definition for the MMA8x5x accelerometer driver.
 
file  mma8x5x_params.h
 Default configuration for MMA8x5x devices.
 
file  mma8x5x_regs.h
 Register 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...
 

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 (const mma8x5x_t *dev, int8_t x, int8_t y, int8_t z)
 Set user offset correction. More...
 
void mma8x5x_set_active (const mma8x5x_t *dev)
 Set active mode, this enables periodic measurements. More...
 
void mma8x5x_set_standby (const mma8x5x_t *dev)
 Set standby mode. More...
 
int mma8x5x_is_ready (const mma8x5x_t *dev)
 Check for new set of measurement data. More...
 
void mma8x5x_read (const mma8x5x_t *dev, mma8x5x_data_t *data)
 Read accelerometer's data. More...
 
void mma8x5x_set_motiondetect (const mma8x5x_t *dev, uint8_t int_pin, uint8_t threshold)
 Configure motion detection interrupt. More...
 
void mma8x5x_ack_int (const mma8x5x_t *dev)
 Acknowledge motion detection interrupt. More...
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Devices supported by this driver.

Enumerator
MMA8X5X_TYPE_MMA8652 

MMA8652.

MMA8X5X_TYPE_MMA8653 

MMA8653.

MMA8X5X_TYPE_MMA8451 

MMA8451.

MMA8X5X_TYPE_MMA8452 

MMA8452.

MMA8X5X_TYPE_MMA8453 

MMA8453.

Definition at line 62 of file mma8x5x.h.

◆ anonymous enum

anonymous enum

Available sampling rates.

Enumerator
MMA8X5X_RATE_800HZ 

800 Hz Output Data Rate in WAKE mode

MMA8X5X_RATE_400HZ 

400 Hz Output Data Rate in WAKE mode

MMA8X5X_RATE_200HZ 

200 Hz Output Data Rate in WAKE mode

MMA8X5X_RATE_100HZ 

100 Hz Output Data Rate in WAKE mode

MMA8X5X_RATE_50HZ 

50 Hz Output Data Rate in WAKE mode

MMA8X5X_RATE_1HZ25 

12.5 Hz Output Data Rate in WAKE mode

MMA8X5X_RATE_6HZ25 

6.25 Hz Output Data Rate in WAKE mode

MMA8X5X_RATE_1HZ56 

1.56 Hz Output Data Rate in WAKE mode

Definition at line 73 of file mma8x5x.h.

◆ anonymous enum

anonymous enum

Available range options.

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 87 of file mma8x5x.h.

◆ anonymous enum

anonymous enum

Named return values.

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 96 of file mma8x5x.h.

Function Documentation

◆ mma8x5x_ack_int()

void mma8x5x_ack_int ( const mma8x5x_t dev)

Acknowledge motion detection interrupt.

Acknowledges (clears) a motion detection interrupt. See mma8x5x_set_motiondetect().

Warning
: this does incur an I2C write, thus should not be done from within the ISR.
Parameters
[in]devdevice descriptor of accelerometer

◆ mma8x5x_init()

int mma8x5x_init ( mma8x5x_t dev,
const mma8x5x_params_t params 
)

Initialize the MMA8x5x accelerometer driver.

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

◆ mma8x5x_is_ready()

int mma8x5x_is_ready ( const mma8x5x_t dev)

Check for new set of measurement data.

Parameters
[in]devdevice descriptor of accelerometer
Returns
MMA8X5X_DATA_READY if new sample is ready
MMA8X5X_NODATA if nothing is available

◆ mma8x5x_read()

void mma8x5x_read ( const mma8x5x_t dev,
mma8x5x_data_t data 
)

Read accelerometer's 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]

◆ mma8x5x_set_active()

void mma8x5x_set_active ( const mma8x5x_t dev)

Set active mode, this enables periodic measurements.

Parameters
[out]devdevice descriptor of accelerometer to reset

◆ mma8x5x_set_motiondetect()

void mma8x5x_set_motiondetect ( const mma8x5x_t dev,
uint8_t  int_pin,
uint8_t  threshold 
)

Configure motion detection interrupt.

User needs to configure MCU side of the selected int pin. mma8x5x will set the pin to low on interrupt. Before another interrupt can occur, the current interrupt must be acknowledged using mma8x5x_ack_int().

Parameters
[in]devdevice descriptor of accelerometer
[in]int_pinselect mma8x5x int pin (1 or 2)
[in]thresholdmotion detection threshold (see datasheet)

◆ mma8x5x_set_standby()

void mma8x5x_set_standby ( const mma8x5x_t dev)

Set standby mode.

Parameters
[in]devdevice descriptor of accelerometer

◆ mma8x5x_set_user_offset()

void mma8x5x_set_user_offset ( const mma8x5x_t dev,
int8_t  x,
int8_t  y,
int8_t  z 
)

Set user offset correction.

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