arthur yuan / MMA8452

Fork of MMA8452 by Craig Evans

Revision:
1:6aa59bbc3e38
Parent:
0:df3b9e41edf3
--- a/MMA8452.cpp	Sun Mar 08 15:31:02 2015 +0000
+++ b/MMA8452.cpp	Mon May 11 03:00:46 2015 +0000
@@ -36,6 +36,12 @@
     data |=  (1<<3);
     sendByteToRegister(data,CTRL_REG1);
 
+    //Interrupt Control Register (Set b1 - Interrupt polarity ACTIVE high - p39 Datasheet)
+    data = readByteFromRegister(CTRL_REG3);
+    data |=  (1<<1); //IPOL bit selects the polarity of the interrupt signal.
+    //When IPOL is ‘0’ (default value) any interrupt event will signaled with a logical 0.
+    sendByteToRegister(data,CTRL_REG3);
+
     //// Can also change default 2g range to 4g or 8g (p22 datasheet)
     data = readByteFromRegister(XYZ_DATA_CFG);
     data |=  (1<<0); // set bit 0 - 4g range
@@ -46,8 +52,53 @@
     data |= (1<<0);   // set bit 0 in CTRL_REG1
     sendByteToRegister(data,CTRL_REG1);
 
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    // only apply for landscape/portrait orientation
+    /*
+    //Set the PL_EN bit in Register.This will enable the orientation detection.
+    data = readByteFromRegister (0x11);
+    data |= 0x40;
+    sendByteToRegister(0x11, PL_CFG);
+
+
+    //Set the Back/Front Angle trip points
+    data = readByteFromRegister(0x13);
+    data &= 0x3F; //Clear bit 7 and 6
+    data |= 0x00;
+    sendByteToRegister(0x13,PL_BF_ZCOMP);
+
+    //Set the Z-Lockout angle trip point
+    data = readByteFromRegister(0x1C); //Read out contents of the register
+
+
+    //Set the Trip Threshold Angle
+    data = readByteFromRegister(0x14);
+    //P_L_THS_Data& = 0x07;
+    //P_L_THS_Data | = (0x07)<<3; //Set Threshold to 15°
+    //sendByteToRegister(0x14, P_L_THS);
+
+    //Set the Hysteresis Angle
+    data = readByteFromRegister(0x14);
+    //P_L_THS_Data | = 0x01; //Set Hysteresis to ±4°
+    //sendByteToRegister(0x14, P_L_THS);
+
+//Register 0x2D, Control Register 4 configures all embedded features for interrupt detection.
+    data = readByteFromRegister(0x2D); //Read out the contents of the register
+    data |= 0x10; //Set bit 4
+    sendByteToRegister(0x2D, CTRL_REG4); //Set the bit and write into CTRL_REG4
+
+//Register 0x2E is Control Register 5 which gives the option of routing the interrupt
+    data = readByteFromRegister(0x2E);
+    data |= 0x10; //Set bit 4 to choose the interrupt to route to INT1
+    sendByteToRegister(0x2E, CTRL_REG5); //Write in the interrupt routing selection
+
+// Set the debounce counter in register
+    sendByteToRegister(0x12, 0x05); //This sets the debounce counter to 100 ms at 50 Hz */
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////
 }
 
+
 // read acceleration data from device
 Acceleration MMA8452::readValues()
 {
@@ -76,11 +127,11 @@
     //  "   "          512      "      4g     "
     //  "   "          256      "      8g     "
     Acceleration acc;
-    
+
     acc.x = x/512.0;
     acc.y = y/512.0;
     acc.z = z/512.0;
-    
+
     return acc;
 }