Library to interface MMA8451Q sensor

Dependents:   LELEC_2811_Accelerometer_2 LELEC_2811_Multiple_Sensors LELEC_2811_acquiring_data LELEC_2811_acquiring_data_working

Files at this revision

API Documentation at this revision

Comitter:
martlefebvre94
Date:
Sun Sep 23 09:57:19 2018 +0000
Parent:
0:2a71c4ec3ee2
Commit message:
Setting of the FSR in the object declaration

Changed in this revision

MMA8451Q.cpp Show annotated file Show diff for this revision Revisions of this file
MMA8451Q.h Show annotated file Show diff for this revision Revisions of this file
diff -r 2a71c4ec3ee2 -r 51c9ede6bb48 MMA8451Q.cpp
--- a/MMA8451Q.cpp	Sat Sep 22 23:15:49 2018 +0000
+++ b/MMA8451Q.cpp	Sun Sep 23 09:57:19 2018 +0000
@@ -27,14 +27,13 @@
 
 #define UINT14_MAX        16383
 
-MMA8451Q::MMA8451Q(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) {
+MMA8451Q::MMA8451Q(PinName sda, PinName scl, int addr, uint8_t fsr) : m_i2c(sda, scl), m_addr(addr) {
     
     // Place the peripheral in standby mode to configure the full scale range
     uint8_t data[2] = {REG_CTRL_REG_1, 0x00};
     writeRegs(data, 2);
     
     // Set the scale
-    uint8_t fsr = 0x02;
     setScale(fsr);
     
     // Activate the peripheral
@@ -96,6 +95,13 @@
     writeRegs(data, 8);
 }
 
+uint8_t MMA8451Q::Read_Status()
+{
+    uint8_t Status;
+    readRegs(0, &Status, 1);
+    return Status;
+}
+
 void MMA8451Q::readRegs(int addr, uint8_t * data, int len) {
     char t[1] = {addr};
     m_i2c.write(m_addr, t, 1, true);
diff -r 2a71c4ec3ee2 -r 51c9ede6bb48 MMA8451Q.h
--- a/MMA8451Q.h	Sat Sep 22 23:15:49 2018 +0000
+++ b/MMA8451Q.h	Sun Sep 23 09:57:19 2018 +0000
@@ -56,7 +56,7 @@
   * @param sdl SCL pin
   * @param addr addr of the I2C peripheral
   */
-  MMA8451Q(PinName sda, PinName scl, int addr);
+  MMA8451Q(PinName sda, PinName scl, int addr, uint8_t fsr);
 
   /**
   * MMA8451Q destructor
@@ -99,6 +99,8 @@
   void getAccAllAxis(float * res);
   
   int16_t getAccAxis(uint8_t addr);
+  
+  uint8_t Read_Status();
 
 private:
   I2C m_i2c;
@@ -106,7 +108,6 @@
   void readRegs(int addr, uint8_t * data, int len);
   void writeRegs(uint8_t * data, int len);
   void setScale(uint8_t fsr);
-  // int16_t getAccAxis(uint8_t addr);
 
 };