NXP / FXLS8471

Dependents:   FRDMSTBC-A8471_SensorShield_HelloWorld

Fork of MMA8652FC by NXP

Files at this revision

API Documentation at this revision

Comitter:
AswinSivakumar
Date:
Wed Mar 23 05:34:00 2016 +0000
Parent:
0:6642dad09196
Child:
2:0eacd0e5db3b
Commit message:
Initial commit

Changed in this revision

FXLS8471.cpp Show annotated file Show diff for this revision Revisions of this file
FXLS8471.h Show annotated file Show diff for this revision Revisions of this file
MMA8652.cpp Show diff for this revision Revisions of this file
MMA8652.h Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FXLS8471.cpp	Wed Mar 23 05:34:00 2016 +0000
@@ -0,0 +1,72 @@
+ /* 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 "FXLS8471.h"
+ #include "mbed.h"
+
+FXLS8471::FXLS8471(PinName MOSI, PinName MISO, PinName CLK, PinName CS) : FXLS8471_spi(MOSI,MISO,CLK), FXLS8471_cs(CS)
+ {
+      FXLS8471_cs=1;
+ }
+    
+ void FXLS8471::FXLS8471_config(void)
+ {
+   char d[2]; 
+   d[0] = FXLS8471_CTRL_REG1;                     //Puts device in Standby mode
+   FXLS8471_cs=0;
+   FXLS8471_spi.write(d[0]+128); 
+   FXLS8471_spi.write(0x00);  
+   FXLS8471_spi.write(0x00);  
+   FXLS8471_cs=1;
+          
+   
+   d[0] = FXLS8471_CTRL_REG1;                     //Puts device in Active mode
+   FXLS8471_cs=0;
+   FXLS8471_spi.write(d[0]+128); 
+   FXLS8471_spi.write(0x01);  
+   FXLS8471_spi.write(0x01);  
+   FXLS8471_cs=1;  
+      
+ }
+ 
+  
+ 
+ void FXLS8471::acquire_FXLS8471_data_g(float * a_data)
+ {
+  
+   char data_bytes[7];
+   char d[1];
+   int count=1;
+   d[0]=0x01;
+   
+   FXLS8471_cs=0;
+   FXLS8471_spi.write(d[0]); 
+   FXLS8471_spi.write(0x00);  
+   while(count<7)
+   {  data_bytes[count]= FXLS8471_spi.write(0xff);  count=count+1;
+   }
+   FXLS8471_cs=1;
+   
+   // a_data[0]= ((float)((int16_t)data_bytes[1]));
+   a_data[0] =  ((float)((int16_t)(((data_bytes[1]*256) + (data_bytes[2])))>> 4) * 0.0009765);
+   a_data[1] =  ((float)((int16_t)(((data_bytes[3]*256) + (data_bytes[4])))>> 4) * 0.0009765);
+   a_data[2] =  ((float)((int16_t)(((data_bytes[5]*256) + (data_bytes[6])))>> 4) * 0.0009765);
+   
+ }
+
+     
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FXLS8471.h	Wed Mar 23 05:34:00 2016 +0000
@@ -0,0 +1,45 @@
+ /* 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.
+*/
+
+#ifndef FXLS8471_H
+#define FXLS8471_H
+#include "mbed.h"
+
+#define FXLS8471_STATUS 0x00
+#define FXLS8471_WHO_AM_I 0x0D
+#define FXLS8471_CTRL_REG1 0x2A
+#define FXLS8471_CTRL_REG2 0x2B
+#define FXLS8471_WHO_AM_I_VALUE 0x6A
+
+class FXLS8471
+{
+    public:
+    
+    FXLS8471(PinName MOSI, PinName MISO, PinName CLK, PinName CS);
+      
+    void FXLS8471_config(void);
+        
+    void acquire_FXLS8471_data_g(float * du);
+    
+    private:
+    SPI FXLS8471_spi;
+    DigitalOut FXLS8471_cs;
+    
+};
+
+#endif
\ No newline at end of file
--- a/MMA8652.cpp	Sat Jan 23 00:07:11 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
- /* 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 "MMA8652.h"
- #include "mbed.h"
-
-MMA8652::MMA8652(PinName sda, PinName scl) : MMA8652_i2c(sda,scl)
- {
-       
- }
-    
- void MMA8652::MMA8652_config(void)
- {
-   char d[2]; 
-   d[0] = MMA8652_CTRL_REG1;                     //Puts device in Standby mode
-   d[1] = 0x00; 
-   MMA8652_i2c.write(MMA8652_I2C_ADDRESS, d,2);   
-          
-   
-   d[0] = MMA8652_CTRL_REG1;                     //Puts device in Active mode
-   d[1] = 0x01;
-   MMA8652_i2c.write(MMA8652_I2C_ADDRESS, d,2);   
-      
- }
- 
-  
- 
- void MMA8652::acquire_MMA8652_data_g(float * a_data)
- {
-  
-   char data_bytes[7];
-   char d[1];
-   d[0]=MMA8652_STATUS;
-  MMA8652_i2c.write(MMA8652_I2C_ADDRESS,d,1,true);  // Read the 6 data bytes - LSB and MSB for X, Y and Z Axes.
-   MMA8652_i2c.read(MMA8652_I2C_ADDRESS,data_bytes,7);
-   
-   a_data[0] =  ((float)((int16_t)(((data_bytes[1]*256) + (data_bytes[2])))>> 4) * 0.0009765);
-   a_data[1] =  ((float)((int16_t)(((data_bytes[3]*256) + (data_bytes[4])))>> 4) * 0.0009765);
-   a_data[2] =  ((float)((int16_t)(((data_bytes[5]*256) + (data_bytes[6])))>> 4) * 0.0009765);
-   
- }
-
-     
\ No newline at end of file
--- a/MMA8652.h	Sat Jan 23 00:07:11 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
- /* 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.
-*/
-
-#ifndef MMA8652_H
-#define MMA8652_H
-#include "mbed.h"
-
-#define MMA8652_I2C_ADDRESS (0x1D<<1)
-
-#define MMA8652_STATUS 0x00
-#define MMA8652_WHO_AM_I 0x0D
-#define MMA8652_CTRL_REG1 0x2A
-#define MMA8652_CTRL_REG2 0x2B
-#define MMA8652_WHO_AM_I_VALUE 0x4A
-
-class MMA8652
-{
-    public:
-    
-    MMA8652(PinName sda, PinName scl);
-      
-    void MMA8652_config(void);
-        
-    void acquire_MMA8652_data_g(float * du);
-    
-    private:
-    I2C MMA8652_i2c;
-    
-};
-
-#endif
\ No newline at end of file