Mateusz Grzywacz / MMA845x

Fork of MMA845x by Multi-Hackers

Embed: (wiki syntax)

« Back to documentation index

MMA845x Class Reference

MMA845x Class Reference

API abstraction for the MMA845x 3-axis accelerometer IC initial version will be polling only. More...

#include <MMA845x.h>

Public Types

enum  SA0 { SA0_VSS = 0, SA0_VDD }
 

Possible terminations for the ADDR pin.

More...
enum  WHO_AM_I_VAL { MMA8451 = 0x1A, MMA8452 = 0x2A, MMA8453 = 0x3A }
 

Device ID's that this class is compatible with.

More...
enum  SYS_MODE
 

operating mode of MMA845x

More...
enum  STATUS
 

flags for data overwrite and data ready

More...
enum  RANGE
 

values for measurement range positive and negative

More...
enum  RESOLUTION
 

selections for resolution of data, 8 bit or maximum

More...
enum  LOW_NOISE
 

Low Noise mode Note: 4g max reading when on.

More...
enum  HPF_MODE
 

High Pass Filter mode.

More...
enum  DATA_RATE
 

values for normal output data rate in Hz

More...
enum  ASLP_DATA_RATE
 

values for auto_sleep mode data rate in HZ

More...
enum  OVERSAMPLE_MODE
 

sets the oversample mode, Normal, Low power and noise, High resolution, or low power

More...
enum  INTERRUPT_PIN
 

chooses interrupt pin used to signal interrupt condition

More...
enum  REGISTER
 

The device register map.

More...

Public Member Functions

 MMA845x (I2C &i2c, SA0 const i2c_addr=SA0_VSS, InterruptIn *int1=NULL, InterruptIn *int2=NULL)
 Create the MMA845x object.
int16_t getX (void)
 Get the X data.
int16_t getY (void)
 Get the Y data.
int16_t getZ (void)
 Get the Z data.
MMA845x_DATA getXYZ (void)
 Get the XYZ data structure.
char getWhoAmI (void) const
 Get the XYZ data structure.
uint8_t setCommonParameters (RANGE range, RESOLUTION resolution, LOW_NOISE lo_noise, DATA_RATE data_rate, OVERSAMPLE_MODE os_mode, HPF_MODE hpf_mode) const
 Setup the MMA845x for standard accelerometer read mode - set the measurement range using RANGE enum - set the ADC resolution using the RESOLUTION enum - Set the Low-Noise mode using the LOW_NOISE enum - set the aquisition rate using the DATA_RATE enum - Set the Over sample mode suing the OVERSAMPLE_MODE enum - Set the Hi pass filter mode using the HPF_MOSE enum.
uint8_t enableMotionDetect (void) const
 Ebnable Motion detect mode and interrupt handler.
uint8_t enablePulseDetect (char x_threshold, char y_threshold, char z_threshold, char window, char latency, INTERRUPT_PIN pin) const
 Enable Pulse Detect mode and interrupt handler x_threshold - tap/double tap detection threshold for x axis.
uint8_t enableOrientationDetect (uint8_t debounce_steps, INTERRUPT_PIN pin=INT_NONE) const
 Enable Orientation mode and interrupt handler - how long a state has to last to trigger orientation change.
uint8_t enableTransientDetect (void) const
 Enable Transient detect mode and interrupt handler.
uint8_t enableAutoSleep (void) const
 Enable Autosleep function and interrupt handler.
uint8_t enableFIFO (void) const
 Enbale FIFO function and interrupt handler.
uint8_t standbyMode (void) const
 Put the MMA845x in the Standby mode.
uint8_t activeMode (void) const
 Put the MMA845x in the active mode.
uint8_t getStatus (void) const
 Check the MMA845x status register.
uint8_t writeRegister (uint8_t const reg, uint8_t const data) const
 Write to a register (exposed for debugging reasons) Note: most writes are only valid in stop mode.
uint8_t readRegister (uint8_t const reg, uint8_t count, char *data) const
 Read from a register (exposed for debugging reasons)
uint8_t configInterrupt (INTERRUPT_CFG_EN_SOURCE function, INTERRUPT_PIN pin) const
 Enable disable interrupt triggering for a given function.

Detailed Description

API abstraction for the MMA845x 3-axis accelerometer IC initial version will be polling only.

Interrupt service and rtos support will be added at a later point

Definition at line 104 of file MMA845x.h.


Member Enumeration Documentation

values for auto_sleep mode data rate in HZ

Definition at line 205 of file MMA845x.h.

enum DATA_RATE

values for normal output data rate in Hz

Definition at line 191 of file MMA845x.h.

enum HPF_MODE

High Pass Filter mode.

Definition at line 182 of file MMA845x.h.

chooses interrupt pin used to signal interrupt condition

Definition at line 240 of file MMA845x.h.

enum LOW_NOISE

Low Noise mode Note: 4g max reading when on.

Definition at line 173 of file MMA845x.h.

sets the oversample mode, Normal, Low power and noise, High resolution, or low power

Definition at line 216 of file MMA845x.h.

enum RANGE

values for measurement range positive and negative

Definition at line 155 of file MMA845x.h.

enum REGISTER

The device register map.

Definition at line 250 of file MMA845x.h.

enum RESOLUTION

selections for resolution of data, 8 bit or maximum

Definition at line 164 of file MMA845x.h.

enum SA0

Possible terminations for the ADDR pin.

Enumerator:
SA0_VSS 

SA0 connected to VSS

SA0_VDD 

SA0 connected to VDD

Definition at line 112 of file MMA845x.h.

enum STATUS

flags for data overwrite and data ready

Definition at line 140 of file MMA845x.h.

enum SYS_MODE

operating mode of MMA845x

Definition at line 131 of file MMA845x.h.

Device ID's that this class is compatible with.

Enumerator:
MMA8451 

MMA8451 WHO_AM_I register content

MMA8452 

MMA8452 WHO_AM_I register content

MMA8453 

MMA8453 WHO_AM_I register content

Definition at line 121 of file MMA845x.h.


Constructor & Destructor Documentation

MMA845x ( I2C &  i2c,
SA0 const   i2c_addr = SA0_VSS,
InterruptIn *  int1 = NULL,
InterruptIn *  int2 = NULL 
)

Create the MMA845x object.

Parameters:
i2c- A defined I2C object
int1- A defined InterruptIn object pointer. Default NULL for polling mode
int2- A defined InterruptIn object pointer. Default NULL for polling mode
i2c_addr- state of pin SA0 TODO - need to add interrupt support

Definition at line 34 of file MMA845x.cpp.


Member Function Documentation

uint8_t activeMode ( void   ) const

Put the MMA845x in the active mode.

Returns:
status of command

Definition at line 221 of file MMA845x.cpp.

uint8_t configInterrupt ( INTERRUPT_CFG_EN_SOURCE  function,
INTERRUPT_PIN  pin 
) const

Enable disable interrupt triggering for a given function.

- a internal funcion capable to trigger an interrupt - which phy pin assign to interrupt condition. If no pin is specified, interrupt is disabled

Returns:

Definition at line 196 of file MMA845x.cpp.

uint8_t enableAutoSleep ( void   ) const

Enable Autosleep function and interrupt handler.

Returns:
status of command TODO - need to implement function

Definition at line 178 of file MMA845x.cpp.

uint8_t enableFIFO ( void   ) const

Enbale FIFO function and interrupt handler.

Returns:
status of command TODO - need to implement function

Definition at line 184 of file MMA845x.cpp.

uint8_t enableMotionDetect ( void   ) const

Ebnable Motion detect mode and interrupt handler.

Returns:
status of command TODO - need to implement function

Definition at line 133 of file MMA845x.cpp.

uint8_t enableOrientationDetect ( uint8_t  debounce_steps,
INTERRUPT_PIN  pin = INT_NONE 
) const

Enable Orientation mode and interrupt handler - how long a state has to last to trigger orientation change.

step varies from 1.25 to 160 ms. - an interrupt has to be attached to some pin, even if this pin is NC

Returns:
status of command TODO - add trip angles change (only when MMA8451), way of fetching orientation events

Definition at line 155 of file MMA845x.cpp.

uint8_t enablePulseDetect ( char  x_threshold,
char  y_threshold,
char  z_threshold,
char  window,
char  latency,
INTERRUPT_PIN  pin 
) const

Enable Pulse Detect mode and interrupt handler x_threshold - tap/double tap detection threshold for x axis.

resolution of 0.063 g/LSB, min value 1, max value 127, use 0 to disable y_threshold - tap/double tap detection threshold for y axis. resolution of 0.063 g/LSB, min value 1, max value 127, use 0 to disable z_threshold - tap/double tap detection threshold for z axis. resolution of 0.063 g/LSB, min value 1, max value 127, use 0 to disable window - pulse must fit within window (raise and fall below threshold) in order "to be considered a valid pulse." latency - period, that starts after a pulse has been detected, during all pulses are ignored. Kind of debouncing - an interrupt has to be attached to some pin, even if this pin is NC

Returns:
status of command TODO - implement conversion from some arbitrary units to ms for window and latency, double tap, way of fetching pulse events

Definition at line 139 of file MMA845x.cpp.

uint8_t enableTransientDetect ( void   ) const

Enable Transient detect mode and interrupt handler.

Returns:
status of command TODO - need to implement function

Definition at line 172 of file MMA845x.cpp.

uint8_t getStatus ( void   ) const

Check the MMA845x status register.

Returns:
status byte

Definition at line 246 of file MMA845x.cpp.

char getWhoAmI ( void   ) const

Get the XYZ data structure.

Returns:
accelerometer ID code. Test versus the WHO_AM_I_VAL enum

Definition at line 317 of file MMA845x.cpp.

int16_t getX ( void   )

Get the X data.

Returns:
The last valid X-axis reading from the accelerometer

Definition at line 262 of file MMA845x.cpp.

MMA845x_DATA getXYZ ( void   )

Get the XYZ data structure.

Returns:
The last valid X, Y, and Z-axis readings from the accelerometer

Definition at line 300 of file MMA845x.cpp.

int16_t getY ( void   )

Get the Y data.

Returns:
The last valid Y-axis reading from the accelerometer

Definition at line 275 of file MMA845x.cpp.

int16_t getZ ( void   )

Get the Z data.

Returns:
The last Z-axis valid reading from the accelerometer

Definition at line 287 of file MMA845x.cpp.

uint8_t readRegister ( uint8_t const   reg,
uint8_t  count,
char *  data 
) const

Read from a register (exposed for debugging reasons)

Parameters:
reg- The register to read from
Returns:
The register contents

Definition at line 339 of file MMA845x.cpp.

uint8_t setCommonParameters ( RANGE  range,
RESOLUTION  resolution,
LOW_NOISE  lo_noise,
DATA_RATE  data_rate,
OVERSAMPLE_MODE  os_mode,
HPF_MODE  hpf_mode 
) const

Setup the MMA845x for standard accelerometer read mode - set the measurement range using RANGE enum - set the ADC resolution using the RESOLUTION enum - Set the Low-Noise mode using the LOW_NOISE enum - set the aquisition rate using the DATA_RATE enum - Set the Over sample mode suing the OVERSAMPLE_MODE enum - Set the Hi pass filter mode using the HPF_MOSE enum.

Returns:
status of command

This sets the resolution, range, data rate, oversample mode, hi and lo pass filter. Also sets the device to active mode, so no further configuration will take an effect. To perform any configuration, switch to standby.

Definition at line 95 of file MMA845x.cpp.

uint8_t standbyMode ( void   ) const

Put the MMA845x in the Standby mode.

Returns:
status of command

Definition at line 233 of file MMA845x.cpp.

uint8_t writeRegister ( uint8_t const   reg,
uint8_t const   data 
) const

Write to a register (exposed for debugging reasons) Note: most writes are only valid in stop mode.

Parameters:
reg- The register to be written
data- The data to be written

Definition at line 322 of file MMA845x.cpp.