My version of the library for this accelerometer. It works on 800Hz data rate.

Fork of MMA8451Q by Antonio Quevedo

Revision:
1:9c229882cd2b
Parent:
0:7c9ab58f6af3
--- a/MMA8451Q.cpp	Wed Jun 04 19:16:47 2014 +0000
+++ b/MMA8451Q.cpp	Tue Jul 18 18:34:24 2017 +0000
@@ -36,9 +36,10 @@
     uint8_t data[2] = {REG_CTRL_REG1, 0x00}; // Puts acc in standby for configuring
     writeRegs(data, 2);
     data[0] = REG_XYZ_DATA_CFG; // Writing 00 turns off high-pass filter and sets full scale range to 2g
-    // data[1] = 0x01; for 4g
-    // data[1] = 0x02; for 8g
-    writeRegs(data, 2);
+                                // data[1] = 0x01; for 4g
+                                // data[1] = 0x02; for 8g
+    data[1] = 0x00;
+    writeRegs(data, 2); 
     data[0] = REG_CTRL_REG2;
     data[1] = 0x00; // Disable self-test, software reset and auto-sleep; operates in normal mode
     writeRegs(data, 2);
@@ -50,7 +51,7 @@
     data[0] = REG_CTRL_REG5;
     writeRegs(data, 2); // Routes Data Ready interrupt to INT1
     data[0] = REG_CTRL_REG1; 
-    data[1] = 0x09; // Data rate is 800Hz
+    data[1] = 0x09; // Data rate is 400Hz
     writeRegs(data, 2);
 }
 
@@ -59,9 +60,9 @@
 void MMA8451Q::getAccAllAxis(int16_t * res) {
     uint8_t temp[6];
     readRegs(REG_OUT_X_MSB, temp, 6);
-    res[0] = (temp[0] * 256) + temp[1];
-    res[1] = (temp[2] * 256) + temp[3];
-    res[2] = (temp[4] * 256) + temp[5];
+    res[0] = ((temp[0] << 8) + temp[1]);
+    res[1] = ((temp[2] << 8) + temp[3]);
+    res[2] = ((temp[4] << 8) + temp[5]);
 }
 
 void MMA8451Q::readRegs(int addr, uint8_t * data, int len) {