Library for MMA7660FC Accelerometer device

Dependents:   TestCode_MMA7660FC 3D_Accelerometer_Tester RTOS-aap-board-modules embed_Grove_3-Axis_Digital_Accelerometer ... more

Revision:
7:74eb2a4803ba
Parent:
6:10aa804dee97
Child:
8:122af194c74b
--- a/MMA7660FC.cpp	Sun Sep 23 10:58:35 2012 +0000
+++ b/MMA7660FC.cpp	Wed Aug 07 19:33:25 2013 +0000
@@ -20,29 +20,17 @@
  
 #include "MMA7660FC.h"
 
-#define OUT_X 0x00              // [6:0] are Read Only 6-bit output value X (XOUT[5] is 0 if the g direction is positive, 1 is negative)
-#define OUT_Y 0x01              // [6:0] are Read Only 6-bit output value Y (YOUT[5] is 0 if the g direction is positive, 1 is negative)
-#define OUT_Z 0x02              // [6:0] are Read Only 6-bit output value Z (ZOUT[5] is 0 if the g direction is positive, 1 is negative)
-#define TILT_STATUS 0x03        // Tilt Status (Read only)
-#define SRST_STATUS 0x04        // Sample Rate Status Register (Read only)
-#define SPCNT_STATUS 0x05       // Sleep Count Register (Read/Write)
-#define INTSU_STATUS 0x06       // Interrupt Setup Register
-#define MODE_STATUS 0x07        // Mode Register (Read/Write)
-#define SR_STATUS 0x08          // Auto-Wake and Active Mode Portrait/Landscape Samples per Seconds Register (Read/Write)
-#define PDET_STATUS 0x09        // Tap/Pulse Detection Register (Read/Write)
-#define PD_STATUS 0xA           // Tap/Pulse Debounce Count Register (Read/Write)
-
-
 float TILT_XY[64] = {0, 2.69, 5.38, 8.08, 10.81, 13.55, 16.33, 19.16, 22.02, 24.95, 27.95, 31.04, 34.23, 37.54, 41.01, 44.68, 48.59, 52.83, 57.54, 62.95, 69.64, 79.86, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -79.86, -69.64, -62.95, -57.54, -52.83, -48.59, -44.68, -41.01, -37.54, -34.23, -31.04, -27.95, -24.95, -22.02, -19.16, -16.33, -13.55, -10.81, -8.08, -5.38, -2.69}; 
-float TILT_Z[64] = {90.00, 87.31, 84.62, 81.92, 79.19, 76.45, 73.67, 70.84, 67.98, 65.05, 62.05, 58.96, 55.77, 52.46, 48.99, 45.32, 41.41, 37.17, 32.46, 27.05, 20.36, 10.14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10.14, -20.36, -27.05, -32.46, -37.17, -41.41, -45.32, -48.99, -52.46, -55.77, -58.96, -62.05, -65.05, -67.98, -70.84, -73.67, -76.45, -79.19, -81.92, -84.62};
+float TILT_Z[64] = {90.00, 87.31, 84.62, 81.92, 79.19, 76.45, 73.67, 70.84, 67.98, 65.05, 62.05, 58.96, 55.77, 52.46, 48.99, 45.32, 41.41, 37.17, 32.46, 27.05, 20.36, 10.14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10.14, -20.36, -27.05, -32.46, -37.17, -41.41, -45.32, -48.99, -52.46, -55.77, -58.96, -62.05, -65.05, -67.98, -70.84, -73.67, -76.45, -79.19, -81.92, -84.62, -87.31};
 
 
 
         // Connect module at I2C address addr using I2C port pins sda and scl
-MMA7660FC::MMA7660FC(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr)
+MMA7660FC::MMA7660FC(PinName sda, PinName scl, int addr) : m_i2c(sda, scl)
 {
-    SPI_W_Address = m_addr;                 // Write address
-    SPI_R_Address = SPI_W_Address | 1;      // Read address           
+    SPI_W_Address = addr;                 // Write address
+    SPI_R_Address = SPI_W_Address | 1;      // Read address  
+               
 }
 
 
@@ -58,8 +46,7 @@
 {
     
     write_reg(INTSU_STATUS, 0x10);      // automatic interrupt after every measurement
-    write_reg(SR_STATUS, 0x00);         // 120 Samples/Second
-    write_reg(MODE_STATUS, 0x01);       // Active Mode
+    write_reg(SR_STATUS, 0x07);         // 1 Samples/Second
     
 }
 
@@ -169,3 +156,12 @@
     m_i2c.write(SPI_W_Address, cmd, 2);
                   
 }
+
+
+        //  check if the address exist on an I2C bus 
+int MMA7660FC::check()
+{
+    
+    return m_i2c.write(SPI_W_Address, NULL, 0); 
+
+}
\ No newline at end of file