LPS25H library

Dependents:   mbed_LPS25H GR-PEACH_TAMORI

See http://developer.mbed.org/users/yasuyuki/notebook/LPS25H/

Files at this revision

API Documentation at this revision

Comitter:
yasuyuki
Date:
Sun Oct 12 02:42:32 2014 +0000
Commit message:
first release

Changed in this revision

LPS25H.cpp Show annotated file Show diff for this revision Revisions of this file
LPS25H.h Show annotated file Show diff for this revision Revisions of this file
typedef.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPS25H.cpp	Sun Oct 12 02:42:32 2014 +0000
@@ -0,0 +1,83 @@
+//**********************
+// LPS25H.cpp for mbed
+//
+// LPS25H lps25h(P0_5,P0_4);
+// or
+// I2C i2c(P0_5,P0_4);
+// LPS25H lps25h(i2c);
+//
+// (C)Copyright 2014 All rights reserved by Y.Onodera
+// http://einstlab.web.fc2.com
+//**********************
+
+#include "mbed.h"
+#include "LPS25H.h"
+
+LPS25H::LPS25H (PinName sda, PinName scl) : _i2c(sda, scl) {
+    init();
+}
+LPS25H::LPS25H (I2C& p_i2c) : _i2c(p_i2c) {
+    init();
+}
+
+void LPS25H::put(unsigned char a, unsigned char b)
+{
+    buf[0]=a;
+    buf[1]=b;
+    _i2c.write(LPS25H_ADDR, buf, 2);
+}
+
+
+void LPS25H::get(unsigned char a)
+{
+    buf[0] = a;
+    _i2c.write(LPS25H_ADDR, buf, 1, true); // no stop, repeated
+    _i2c.read( LPS25H_ADDR, buf, 1);
+
+}
+
+long LPS25H::pressure()
+{
+
+    // XL first and H last
+    // get press_xl
+    get(LPS25H_PRESS_POUT_XL_REH);
+    press.byte.LB=buf[0];
+    // get tpress_low
+    get(LPS25H_PRESS_OUT_L);
+    press.byte.HB=buf[0];
+    // get press_high
+    get(LPS25H_PRESS_OUT_H);
+    press.byte.UB=buf[0];
+    return press.Val;
+ 
+    // hPa = press.Val / 4096
+    // Pa = press.Val / 40.96   
+}
+
+
+short LPS25H::temperature()
+{
+
+    // L first and H last
+    // get tpress_low
+    get(LPS25H_TEMP_OUT_L);
+    temp.byte.LB=buf[0];
+    // get press_high
+    get(LPS25H_TEMP_OUT_H);
+    temp.byte.HB=buf[0];
+    return temp.S;
+ 
+    // C = 42.5 + temp.S / 480
+    // range:0 to 80C
+    // accuracy:+-2C
+}
+
+
+void LPS25H::init()
+{
+    // Power ON Cycle=1Hz
+    put(LPS25H_CTRL_REG1, 0x90);
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPS25H.h	Sun Oct 12 02:42:32 2014 +0000
@@ -0,0 +1,62 @@
+//**********************
+// LPS25H.h for mbed
+//
+// (C)Copyright 2014 All rights reserved by Y.Onodera
+// http://einstlab.web.fc2.com
+//**********************
+
+#ifndef LPS25H_H_
+#define LPS25H_H_
+
+#define LPS25H_ADDR                 0xB8
+#define LPS25H_REF_P_XL             0x08
+#define LPS25H_REF_P_L              0x09
+#define LPS25H_REF_P_H              0x0A
+#define LPS25H_WHO_AM_I             0x0F
+#define LPS25H_RES_CONF             0x10
+#define LPS25H_CTRL_REG1            0x20
+#define LPS25H_CTRL_REG2            0x21
+#define LPS25H_CTRL_REG3            0x22
+#define LPS25H_CTRL_REG4            0x23
+#define LPS25H_INT_CFG              0x24
+#define LPS25H_INT_SOURCE           0x25
+#define LPS25H_STATUS_REG           0x27
+#define LPS25H_PRESS_POUT_XL_REH    0x28
+#define LPS25H_PRESS_OUT_L          0x29
+#define LPS25H_PRESS_OUT_H          0x2A
+#define LPS25H_TEMP_OUT_L           0x2B
+#define LPS25H_TEMP_OUT_H           0x2C
+#define LPS25H_FIFO_CTRL            0x2E
+#define LPS25H_FIFO_STATUS          0x2F
+#define LPS25H_THS_P_L              0x30
+#define LPS25H_THS_P_H              0x31
+#define LPS25H_RPDS_L               0x39
+#define LPS25H_RPDS_H               0x3A
+
+#include "mbed.h"
+#include "typedef.h"
+
+class LPS25H{
+public:
+    LPS25H (PinName sda, PinName scl);
+    LPS25H (I2C& p_i2c);
+    void init();
+
+    void put(unsigned char a, unsigned char b);
+    void get(unsigned char a);
+    long pressure();
+    short temperature();
+
+protected:
+    
+    I2C _i2c;
+
+    DWORD_VAL press;
+    WORD_VAL temp;
+    char buf[2];
+
+};
+
+#endif /* LPS25H_H_ */
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/typedef.h	Sun Oct 12 02:42:32 2014 +0000
@@ -0,0 +1,55 @@
+//**********************
+// typedef for mbed
+//
+// Condition:
+//
+// (C)Copyright 2014 All rights reserved by Y.Onodera
+// http://einstlab.web.fc2.com
+//**********************
+#ifndef TYPEDEF_H
+#define TYPEDEF_H
+
+typedef unsigned char       BYTE;                           /* 8-bit unsigned  */
+typedef unsigned short int  WORD;                           /* 16-bit unsigned */
+typedef unsigned int        DWORD;                          /* 32-bit unsigned */
+typedef unsigned long long  QWORD;                          /* 64-bit unsigned */
+
+
+typedef union
+{
+    WORD Val;
+    BYTE v[2];
+    short S;
+    struct
+    {
+        BYTE LB;
+        BYTE HB;
+    } byte;
+} WORD_VAL;
+
+typedef union
+{
+    DWORD Val;
+    WORD w[2];
+    BYTE v[4];
+    struct
+    {
+        WORD LW;
+        WORD HW;
+    } word;
+    struct
+    {
+        BYTE LB;
+        BYTE HB;
+        BYTE UB;
+        BYTE MB;
+    } byte;
+    struct
+    {
+        WORD_VAL low;
+        WORD_VAL high;
+    }wordUnion;
+
+} DWORD_VAL;
+
+#endif /* TYPEDEF_H */