Library for NXP's MMA8653

Files at this revision

API Documentation at this revision

Comitter:
takuhachisu
Date:
Fri Aug 31 08:21:23 2018 +0000
Parent:
0:c101a5ec5ef2
Commit message:
Library for NXP's MMA8653;

Changed in this revision

MMA8653.cpp Show annotated file Show diff for this revision Revisions of this file
MMA8653.h Show annotated file Show diff for this revision Revisions of this file
--- a/MMA8653.cpp	Thu Aug 30 04:52:39 2018 +0000
+++ b/MMA8653.cpp	Fri Aug 31 08:21:23 2018 +0000
@@ -1,6 +1,6 @@
 #include "MMA8653.h"
 
-MMA8653::MMA8653(I2C &i2c, FS fs, F_READ fr)
+MMA8653::MMA8653(I2C &i2c, FS fs, DR dr, F_READ fr)
 {
     _i2c = &i2c;
     char value[1];
@@ -16,7 +16,7 @@
 
     // set the fast-read mode and set the device active
     fastReadFlag = (fr != Normal);
-    value[0] = 0x01 | (fr << 1);
+    value[0] = 0x01 | (fr << 1) | (dr << 3);
     byteWrite(CTRL_REG1, value, 1);
 }
 
--- a/MMA8653.h	Thu Aug 30 04:52:39 2018 +0000
+++ b/MMA8653.h	Fri Aug 31 08:21:23 2018 +0000
@@ -59,13 +59,25 @@
         PM4G,
         PM8G
     };
-    
+
+    // Data rate selection in register 0x02A[5-3]
+    enum DR {
+        DR800HZ = 0,
+        DR400HZ,
+        DR200HZ,
+        DR100HZ,
+        DR50HZ,
+        DR12_5HZ,
+        DR6_25HZ,
+        DR1_56HZ
+    };
+
     // Fast-read mode in register 0x02A[1]
     enum F_READ {
         Normal = 0,
         FastRead
     };
-    
+
     /**
     * Create a MMA8653 object
     *
@@ -73,8 +85,8 @@
     * @param dr dynamic range setting
     * @param fr fast read setting
     */
-    MMA8653(I2C &i2c, FS fs = PM2G, F_READ fr = Normal);
-    
+    MMA8653(I2C &i2c, FS fs = PM2G, DR dr= DR800HZ, F_READ fr = Normal);
+
     /**
      * Read 3-axis acceleration in floating point values (unit: G)
      *
@@ -88,7 +100,7 @@
      * @param *val array where acceleration data will be stored
      */
     void ReadXYZ_s16(short *val);
-    
+
     /**
      * Read 3-axis acceleration in signed 8-bit values (fast read should be on)
      *