MEMS pressure sensor by STMicroelectronics. FIFO Hardware digital filter as default.

Fork of LPS25H by Kenji Arai

Revision:
2:92691fd6cb75
Parent:
1:9db35e42ddbc
diff -r 9db35e42ddbc -r 92691fd6cb75 LPS25H.cpp
--- a/LPS25H.cpp	Tue Aug 22 10:18:07 2017 +0000
+++ b/LPS25H.cpp	Sun Oct 14 02:00:36 2018 +0000
@@ -13,14 +13,14 @@
 
 #include "LPS25H.h"
 
-LPS25H::LPS25H (PinName p_sda, PinName p_scl, uint8_t addr) :
+LPS25H::LPS25H (PinName p_sda, PinName p_scl) :
  _i2c_p(new I2C(p_sda, p_scl)), _i2c(*_i2c_p)
 {
-    LPS25H_addr = addr;
+    LPS25H_addr = LPS25H_V_CHIP_ADDR;
     LPS25H_mode = FIFO_HW_FILTER;
     init();
 }
-
+/*
 LPS25H::LPS25H (PinName p_sda, PinName p_scl, uint8_t addr, uint8_t mode) :
  _i2c_p(new I2C(p_sda, p_scl)), _i2c(*_i2c_p)
 {
@@ -42,23 +42,23 @@
     LPS25H_mode = mode;
     init();
 }
-
+*/
 /////////////// Initialize ////////////////////////////////
 void LPS25H::init(void)
 {
     _i2c.frequency(100000);
     // Check acc is available of not
-    dt[0] = LPS25H_WHO_AM_I;
-    _i2c.write(LPS25H_addr, dt, 1, true);
-    _i2c.read(LPS25H_addr, dt, 1, false);
-    if (dt[0] == I_AM_LPS25H) {
-        LPS25H_id = I_AM_LPS25H;
-        LPS25H_ready = 1;
-    } else {
-        LPS25H_id = 0;
-        LPS25H_ready = 0;
-        return;     // acc chip is NOT on I2C line then terminate
-    }
+    //dt[0] = LPS25H_WHO_AM_I;
+    //_i2c.write(LPS25H_addr, dt, 1, true);
+    //_i2c.read(LPS25H_addr, dt, 1, false);
+    // if (dt[0] == I_AM_LPS25H) {
+    //     LPS25H_id = I_AM_LPS25H;
+    //     LPS25H_ready = 1;
+    // } else {
+    //     LPS25H_id = 0;
+    //     LPS25H_ready = 0;
+    //     return;     // acc chip is NOT on I2C line then terminate
+    // }
     if (LPS25H_mode == FIFO_HW_FILTER){
         // Hardware digital filter
         // AN4450 April 2014 Rev1 P20/26,
@@ -88,19 +88,21 @@
 /////////////// Start conv. and gwt all data //////////////
 void LPS25H::get(void)
 {
-    if (LPS25H_ready == 0) {
+   /* if (LPS25H_ready == 0) {
         press = 0;
         temp = 0;
+        alt = 0;
         return;
-    }
+    }*/
     dt[0] = LPS25H_PRESS_POUT_XL | 0x80;
     _i2c.write(LPS25H_addr, dt, 1, true);
     _i2c.read(LPS25H_addr, dt, 3, false);
     press = dt[2] << 16 | dt[1] << 8 | dt[0];
-    dt[0] = LPS25H_TEMP_OUT_L | 0x80;
-    _i2c.write(LPS25H_addr, dt, 1, true);
-    _i2c.read(LPS25H_addr, dt, 2, false);
-    temp = dt[1] << 8 | dt[0];
+  //  dt[0] = LPS25H_TEMP_OUT_L | 0x80;
+  // _i2c.write(LPS25H_addr, dt, 1, true);
+  //  _i2c.read(LPS25H_addr, dt, 2, false);
+  //  temp = dt[1] << 8 | dt[0];
+    alt = (1-pow((press/4096)/1013.25,0.190284))*145366.45;
 }
 
 /////////////// Read data from sensor /////////////////////
@@ -110,19 +112,24 @@
 }
 
 /////////////// Read data from sensor /////////////////////
-float LPS25H::temperature()
+/*float LPS25H::temperature()
 {
     return (float)temp / 480  + 42.5;
+}*/
+/////////////// Read data from sensor /////////////////////
+float LPS25H::altitude(void) {
+    
+    return  alt/3.280839895;
 }
 
 /////////////// ID ////////////////////////////////////////
-uint8_t LPS25H::read_id()
+/*uint8_t LPS25H::read_id()
 {
     dt[0] = LPS25H_WHO_AM_I;
     _i2c.write(LPS25H_addr, dt, 1, true);
     _i2c.read(LPS25H_addr, dt, 1, false);
     return (uint8_t)dt[0];
-}
+}*/
 
 /////////////// I2C Freq. /////////////////////////////////
 void LPS25H::frequency(int hz)