MMA8x5x Accelerometer¶
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.
-
enum
@134
¶ - MMA8X5X_TYPE_MMA8652
= 0x4a
- MMA8652.
- MMA8X5X_TYPE_MMA8653
= 0x5a
- MMA8653.
- MMA8X5X_TYPE_MMA8451
= 0x1a
- MMA8451.
- MMA8X5X_TYPE_MMA8452
= 0x2a
- MMA8452.
- MMA8X5X_TYPE_MMA8453
= 0x3a
- MMA8453.
- MMA8X5X_TYPE_MMA8652
-
enum
@135
¶ - MMA8X5X_RATE_800HZ
= (0 << 3)
- 800 Hz Ouput Data Rate in WAKE mode
- MMA8X5X_RATE_400HZ
= (1 << 3)
- 400 Hz Ouput Data Rate in WAKE mode
- MMA8X5X_RATE_200HZ
= (2 << 3)
- 200 Hz Ouput Data Rate in WAKE mode
- MMA8X5X_RATE_100HZ
= (3 << 3)
- 100 Hz Ouput Data Rate in WAKE mode
- MMA8X5X_RATE_50HZ
= (4 << 3)
- 50 Hz Ouput Data Rate in WAKE mode
- MMA8X5X_RATE_1HZ25
= (5 << 3)
- 12.5 Hz Ouput Data Rate in WAKE mode
- MMA8X5X_RATE_6HZ25
= (6 << 3)
- 6.25 Hz Ouput Data Rate in WAKE mode
- MMA8X5X_RATE_1HZ56
= (7 << 3)
- 1.56 Hz Ouput Data Rate in WAKE mode
- MMA8X5X_RATE_800HZ
-
enum
@136
¶ - MMA8X5X_RANGE_2G
= 0
- +/- 2 g Full Scale Range
- MMA8X5X_RANGE_4G
= 1
- +/- 4 g Full Scale Range
- MMA8X5X_RANGE_8G
= 2
- +/- 8 g Full Scale Range
- MMA8X5X_RANGE_2G
-
enum
@137
¶ - MMA8X5X_OK
= 0
- everything was fine
- MMA8X5X_DATA_READY
= 1
- new data ready to be read
- MMA8X5X_NOI2C
= -1
- I2C communication failed.
- MMA8X5X_NODEV
= -2
- no MMA8X5X device found on the bus
- MMA8X5X_NODATA
= -3
- no data available
- MMA8X5X_OK
-
int
mma8x5x_init
(mma8x5x_t * dev, const mma8x5x_params_t * params)¶ Initialize the MMA8x5x accelerometer driver.
Parameters
dev: device descriptor of accelerometer to initialize params: configuration parameters Return values
- MMA8X5X_OK on success
- MMA8X5X_NOI2C if initialization of I2C bus failed
- MMA8X5X_NODEV if accelerometer test failed
-
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
dev: device descriptor of accelerometer to initialize x: offset correction value for x-axis y: offset correction value for y-axis z: offset correction value for z-axis
-
void
mma8x5x_set_active
(const mma8x5x_t * dev)¶ Set active mode, this enables periodic measurements.
Parameters
dev: device descriptor of accelerometer to reset
-
void
mma8x5x_set_standby
(const mma8x5x_t * dev)¶ Set standby mode.
Parameters
dev: device descriptor of accelerometer
-
int
mma8x5x_is_ready
(const mma8x5x_t * dev)¶ Check for new set of measurement data.
Parameters
dev: device descriptor of accelerometer Return values
- MMA8X5X_DATA_READY if new sample is ready
- MMA8X5X_NODATA if nothing is available
-
void
mma8x5x_read
(const mma8x5x_t * dev, mma8x5x_data_t * data)¶ Read accelerometer’s data.
Acceleration will be calculated as: if full scale is set to 2g if full scale is set to 4g if full scale is set to 8g
Parameters
dev: device descriptor of accelerometer data: the current acceleration data [in mg]
-
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
dev: device descriptor of accelerometer int_pin: select mma8x5x int pin (1 or 2) threshold: motion detection threshold (see datasheet)
-
void
mma8x5x_ack_int
(const mma8x5x_t * dev)¶ Acknowledge motion detection interrupt.
Acknowledges (clears) a motion detection interrupt. See
mma8x5x.h::mma8x5x_set_motiondetect()
.Parameters
dev: device descriptor of accelerometer
-
MMA8X5X_I2C_ADDRESS
¶ Accelerometer Default Address.
1
0x1D
-
struct
mma8x5x_params_t
¶ Configuration parameters.
-
i2c.h::i2c_t
i2c
¶ I2C bus the device is connected to.
-
uint8_t
addr
¶ I2C bus address of the device.
-
uint8_t
rate
¶ sampling rate to use
-
uint8_t
range
¶ scale range to use
-
uint8_t
offset
()¶ data offset in X, Y, and Z direction
-
-
struct
mma8x5x_t
¶ Device descriptor for MMA8x5x accelerometers.
-
mma8x5x_params_t
params
¶ device configuration parameters
-
mma8x5x_params_t