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

Dependents:   FRDM_DEMO_CODE

Fork of MMA8451Q by Antonio Quevedo

Revision:
1:204db61f9c8f
Parent:
0:7c9ab58f6af3
diff -r 7c9ab58f6af3 -r 204db61f9c8f MMA8451Q.h
--- a/MMA8451Q.h	Wed Jun 04 19:16:47 2014 +0000
+++ b/MMA8451Q.h	Tue Aug 19 15:05:55 2014 +0000
@@ -1,5 +1,4 @@
 /* Copyright (c) 2010-2011 mbed.org, MIT License
-* Copyright (c) 2014 Antonio Quevedo, UNICAMP
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
 * and associated documentation files (the "Software"), to deal in the Software without
@@ -23,26 +22,26 @@
 #include "mbed.h"
 
 /**
-* MMA8451Q accelerometer example, 8-bit samples
+* MMA8451Q accelerometer example
 *
 * @code
 * #include "mbed.h"
 * #include "MMA8451Q.h"
 * 
+* #define MMA8451_I2C_ADDRESS (0x1d<<1)
+* 
 * int main(void) {
 * 
-* MMA8451Q acc(PTE25, PTE24);
+* MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS);
 * PwmOut rled(LED_RED);
 * PwmOut gled(LED_GREEN);
 * PwmOut bled(LED_BLUE);
-* uint8_t data[3];
-*
-*     while (true) {
-          acc.getAccAllAxis(data);       
-*         rled = 1.0 - abs(data[0]/128);
-*         gled = 1.0 - abs(data[0]/128);
-*         bled = 1.0 - abs(data[0]/128);
-*         wait(0.4);
+* 
+*     while (true) {       
+*         rled = 1.0 - abs(acc.getAccX());
+*         gled = 1.0 - abs(acc.getAccY());
+*         bled = 1.0 - abs(acc.getAccZ());
+*         wait(0.1);
 *     }
 * }
 * @endcode
@@ -55,8 +54,9 @@
   *
   * @param sda SDA pin
   * @param sdl SCL pin
+  * @param addr addr of the I2C peripheral
   */
-  MMA8451Q(PinName sda, PinName scl);
+  MMA8451Q(PinName sda, PinName scl, int addr);
 
   /**
   * MMA8451Q destructor
@@ -64,17 +64,47 @@
   ~MMA8451Q();
 
   /**
-   * Get XYZ axis acceleration, 8-bits
+   * Get the value of the WHO_AM_I register
+   *
+   * @returns WHO_AM_I value
+   */
+  uint8_t getWhoAmI();
+
+  /**
+   * Get X axis acceleration
+   *
+   * @returns X axis acceleration
+   */
+  float getAccX();
+
+  /**
+   * Get Y axis acceleration
+   *
+   * @returns Y axis acceleration
+   */
+  float getAccY();
+
+  /**
+   * Get Z axis acceleration
+   *
+   * @returns Z axis acceleration
+   */
+  float getAccZ();
+
+  /**
+   * Get XYZ axis acceleration
    *
    * @param res array where acceleration data will be stored
    */
-  void getAccAllAxis(int16_t * res);
+  void getAccAllAxis(float * res);
 
 private:
   I2C m_i2c;
+  int m_addr;
   void readRegs(int addr, uint8_t * data, int len);
   void writeRegs(uint8_t * data, int len);
+  int16_t getAccAxis(uint8_t addr);
 
 };
 
-#endif
\ No newline at end of file
+#endif