This is a simple device driver for the 3 axis accelerometer MMA8452 that works with mbed.

Dependents:   MMA8452_test S05APP3_routeur

Revision:
3:ffb0b1650ca2
Parent:
2:66db0f91b215
Child:
5:b3d0abd97e55
--- a/MMA8452.h	Tue Oct 08 16:13:14 2013 +0000
+++ b/MMA8452.h	Wed Oct 16 14:11:04 2013 +0000
@@ -92,13 +92,19 @@
 #define FF_MT_THS 0X17                      // Type 'read' : Freefaul motion threshold register
 #define FF_COUNT 0X18                       // Type 'read' : Freefaul motion debouce counter
 
-#define ASLP_COUNT 0x29                     // Type 'read/write' : Counter setting for auto sleep
+#define ASLP_COUNT 0x29                     // Type 'read/write' : Counter settings for auto sleep
 #define CTRL_REG_1 0x2A                     // Type 'read/write' :
 #define CTRL_REG_2 0x2B                     // Type 'read/write' :
 #define CTRL_REG_3 0x2C                     // Type 'read/write' :
 #define CTRL_REG_4 0x2D                     // Type 'read/write' :
 #define CTRL_REG_5 0x2E                     // Type 'read/write' :
 
+// Defined in table 13 of the Freescale PDF
+#define STANDBY 0x00                        // State value returned after a SYSMOD request, it can be in state STANDBY, WAKE or SLEEP
+#define WAKE 0x01                           // State value returned after a SYSMOD request, it can be in state STANDBY, WAKE or SLEEP
+#define SLEEP 0x02                          // State value returned after a SYSMOD request, it can be in state STANDBY, WAKE or SLEEP
+#define ACTIVE 0x01                         // Stage value returned and set in Control Register 1, it can be STANDBY=00, or ACTIVE=01
+
 
  
 #define TILT_STATUS 0x03        // Tilt Status (Read only)
@@ -134,12 +140,53 @@
         */
       ~Accelerometer_MMA8452();
       
+      
+      
+      /** Get system mode of the MMA8452 (not required)
+        *   returns 0 for success in reading the system mode of the chip
+        *   returns 1 for failure in reading the system mode of the chip
+        *   -currently no retries or waiting is done, this method tries 1 time then exits.
+        *
+        *   This method is used to find out the system mode of the chip ACTIVE = 0x00 or STANDBY = 0x01
+      */
+      int get_SystemMode(int& deviceSystemMode);
+      
+      
+      
+      /** Get status of the MMA8452 (not required)
+        *   returns 0 for success in reading the status of the chip
+        *   returns 1 for failure in reading the status of  the chip
+        *   -currrently no retries or waiting is done, this method tries 1 time then exits.
+        *
+        *   This method is used to find out the real time status of the device it shows if
+        *   x,y and z values have been overwritten before they have been read since a change happened.
+        *   
+      */
+      int get_Status(int& deviceStatus);
+     
+      
+      
       /** Activate the MMA8452 (required)
         *   returns 0 for success in activating the chip
         *   returns 1 for failure in activating the chip
         *   -currrently no retries or waiting is done, this method tries 1 time the exits.
+        *
+        *   This will set the device 'active' even if it's already active. It's just a way to force that state.
       */
       int activate();
+ 
+ 
+ 
+       /** Standby the MMA8452 (not required)
+        *   returns 0 for success in activating the chip
+        *   returns 1 for failure in activating the chip
+        *   -currrently no retries or waiting is done, this method tries 1 time the exits.
+        *
+        *   This will set the device 'standby' even if it's already in standby. It's just a way to force that state.
+      */
+      int standby();
+
+ 
       
        /** Initialization of device MMA8452 (required)
         */
@@ -151,32 +198,29 @@
         * return 0 for success or
         * return 1 for failure.
         */        
-      int get_DeviceID(int& deviceID);    
-       /** Read the Tilt Angle using Three Axis
-        *
-        * @param *x Value of x tilt
-        * @param *y Value of y tilt
-        * @param *z Value of z tilt
-        */
-      void read_Tilt(float *x, float *y, float *z);
+      int get_DeviceID(int& deviceID);  
       
+      int read_y();
+      
+      int read_z();  
+
       /** Read the x register of the MMA8452
         *
         * @returns The value of x acceleration
         */
-      int read_x();
-      
+      int read_x_raw(char *xaxis);
+      //int read_x(int& xaxisLSB);
       /** Read the y register of the MMA8452
         *
         * @returns The value of y acceleration
         */
-      int read_y();
+      int read_y_raw(char *yaxis);
       
       /** Read the z register of the MMA8452
         *
         * @returns The value of z acceleration
         */
-       int read_z();
+       int read_z_raw(char * zaxis);
       
       /** Read the x,y and z registers of the MMA8452
        *