I2C Accelerometer library

Dependents:   FRDMSTBC-A8491_SensorShield xtrinsic_sensors 1-FRDM-Gimbal-LAB

Revision:
0:4f7ab3a47e7b
Child:
1:ce9ae6fa9407
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8491.cpp	Wed Mar 23 07:07:06 2016 +0000
@@ -0,0 +1,48 @@
+ /* Copyright (c) 2015 NXP Semiconductors. MIT License
+*
+* 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
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "MMA8491.h"
+#include "mbed.h"
+
+MMA8491::MMA8491(PinName sda, PinName scl, PinName en) : MMA8491_i2c(sda,scl),MMA8491_en(en)
+ {
+    MMA8491_en=0;
+ }
+    
+ void MMA8491::acquire_MMA8491_data_g(float * a_data)
+ {
+  
+   char data_bytes[7];
+   char d[1];
+     
+   MMA8491_en=1;
+   wait(0.001);
+   d[0]=MMA8491_STATUS;
+   MMA8491_i2c.write(MMA8491_I2C_ADDRESS,d,1,true);  
+   MMA8491_i2c.read(MMA8491_I2C_ADDRESS,data_bytes,7);// Read the 6 data bytes - LSB and MSB for X, Y and Z Axes.
+   MMA8491_en=0;
+  
+   
+   // a_data[0]= ((float)((int16_t)data_bytes[1]));
+   a_data[0] =  ((float)((int16_t)(((data_bytes[1]*256) + (data_bytes[2])))>> 2) * 0.0009765);
+   a_data[1] =  ((float)((int16_t)(((data_bytes[3]*256) + (data_bytes[4])))>> 2) * 0.0009765);
+   a_data[2] =  ((float)((int16_t)(((data_bytes[5]*256) + (data_bytes[6])))>> 2) * 0.0009765);
+   
+ }
+
+     
\ No newline at end of file