Added code to manage Orientation, FreeFall and Motion Detection. Data is also available via IRQ.
Dependents: Test_FRDM_MMA8451Q AccelTest FRDM-KL46-Template KL25Z_Demo ... more
Fork of MMA8451Q by
Revision 10:fa532bf396fb, committed 2013-08-22
- Comitter:
- clemente
- Date:
- Thu Aug 22 15:21:47 2013 +0000
- Parent:
- 9:2aa9b1668d14
- Child:
- 11:13e2af71e2cf
- Commit message:
- Added function to return raw data.
Changed in this revision
MMA8451Q.cpp | Show annotated file Show diff for this revision Revisions of this file |
MMA8451Q.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MMA8451Q.cpp Tue May 28 20:19:38 2013 +0000 +++ b/MMA8451Q.cpp Thu Aug 22 15:21:47 2013 +0000 @@ -18,6 +18,7 @@ #include "MMA8451Q.h" +#define REG_STATUS 0x00 #define REG_WHO_AM_I 0x0D #define REG_CTRL_REG_1 0x2A #define REG_CTRL_REG_2 0x2B @@ -41,6 +42,12 @@ #define UINT14_MAX 16383 +// +#define ZYXDR 0x08 +#define ZDR 0x04 +#define YDR 0x02 +#define XDR 0x01 + /** Interrupt schema * * :: The FreeFall and Motion detection share the same IRQ2. @@ -471,6 +478,58 @@ return acc; } +unsigned int MMA8451Q::getAccRawAllAxis( int16_t * res) +{ + if ( isDataAvailable() & ZYXDR) + { + getAccRawX( &res[0]); + getAccRawY( &res[1]); + getAccRawZ( &res[2]); + return 1; + } else + return 0; +} + +int16_t MMA8451Q::getAccRawX( int16_t * res) +{ + if ( isDataAvailable() & XDR) + { + *res = getAccAxis(REG_OUT_X_MSB); + return 1; + } else + return 0; +} + +int16_t MMA8451Q::getAccRawY( int16_t * res) +{ + if ( isDataAvailable() & YDR) + { + *res = getAccAxis(REG_OUT_Y_MSB); + return 1; + } else + return 0; +} + +int16_t MMA8451Q::getAccRawZ( int16_t * res) +{ + if ( isDataAvailable() & ZDR) + { + *res = getAccAxis(REG_OUT_Z_MSB); + return 1; + } else + return 0; +} + +unsigned int MMA8451Q::isDataAvailable( void) +{ + unsigned char status; + + readRegs( REG_STATUS, &status, 1); + + return (status); + +} + void MMA8451Q::readRegs(int addr, uint8_t * data, int len) { char t[1] = {addr}; m_i2c.write(m_addr, t, 1, true);
--- a/MMA8451Q.h Tue May 28 20:19:38 2013 +0000 +++ b/MMA8451Q.h Thu Aug 22 15:21:47 2013 +0000 @@ -149,6 +149,34 @@ void getAccAllAxis(float * res); /** + * Get raw value for X axis acceleration + * + * @returns X axis acceleration + */ + int16_t getAccRawX( int16_t * res); + + /** + * Get raw value for Y axis acceleration + * + * @returns Y axis acceleration + */ + int16_t getAccRawY( int16_t * res); + + /** + * Get raw value for Z axis acceleration + * + * @returns Z axis acceleration + */ + int16_t getAccRawZ( int16_t * res); + + /** + * Get raw values for XYZ axis acceleration + * + * @param res array where acceleration data will be stored + */ + unsigned int getAccRawAllAxis(int16_t * res); + + /** * Configure the Accelerometere for free fall detection * * @param pointer to the user function to execute after IRQ assertion @@ -210,6 +238,8 @@ */ void DataReady( void(*fptr)(void), unsigned char ODR); + unsigned int isDataAvailable( void); + /** * Soft Reset * @param none