LPS25Hのライブラリ(i2C)です

Dependencies:   mbed

Dependents:   quto_LPS25H_sample4

Files at this revision

API Documentation at this revision

Comitter:
PQUTO
Date:
Fri Jan 20 20:43:29 2017 +0000
Commit message:
LPS25H?????????????

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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 028338208ba1 LPS25H.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPS25H.cpp	Fri Jan 20 20:43:29 2017 +0000
@@ -0,0 +1,68 @@
+#include "mbed.h"
+#include "LPS25H.h"
+
+
+//Serial pc(USBTX, USBRX); //tx, rx
+
+
+MyLPS25H::MyLPS25H(PinName SDA, PinName SCL) : _SDA(SDA), _SCL(SCL){
+   // I2C i2c(_SDA, _SCL);
+    }
+
+void MyLPS25H::SetPress()
+{
+    I2C i2c(_SDA, _SCL);    // sda, scl
+    char cmd[2];
+    cmd[0] = WHO_AM_I;
+    i2c.write(SLV_WRITE, cmd, 1);
+    i2c.read(SLV_READ, cmd, 1);
+    char check[1];
+    check[0] = 0xBD;
+
+        
+    if(cmd[0] == check[0]){
+        //pc.printf("LPS25H   OK\r\n");
+    }else{
+        //pc.printf("LPS25H   NG\r\n");
+    }        
+    
+    cmd[0] = CTRL_REG1;
+    cmd[1] = 0xC0;
+    i2c.write(SLV_WRITE, cmd, 2);
+}
+
+float MyLPS25H::GetPress()
+{
+    I2C i2c(_SDA, _SCL);    // sda, scl
+    //char cmd[2];
+    char cmd_H[2];
+    char cmd_L[2];
+    char cmd_XL[2];
+    float Pressure = 0;
+        
+    while(1)
+    {
+        
+    cmd_XL[0] = PRESS_OUT_XL;
+    i2c.write(SLV_WRITE, cmd_XL, 1);
+    i2c.read(SLV_READ, cmd_XL, 1);
+    
+    cmd_L[0] = PRESS_OUT_L;
+    i2c.write(SLV_WRITE, cmd_L, 1);
+    i2c.read(SLV_READ, cmd_L, 1);
+    
+    cmd_H[0] = PRESS_OUT_H;
+    i2c.write(SLV_WRITE, cmd_H, 1);
+    i2c.read(SLV_READ, cmd_H, 1);
+    
+    unsigned long Press_H = 0, Press_L = 0, Press_XL = 0;
+    Press_XL = (long)cmd_XL[0];
+    Press_L = (long)cmd_L[0];
+    Press_H = (long)cmd_H[0];
+   // Pressure = (cmd_H[0]<<20 | cmd_H[1]<<16 | cmd_L[0]<<12 | cmd_L[1]<<8 | cmd_XL[0]<<4 | cmd_XL[1])/4096;
+    Pressure = (float)(Press_H << 16 | Press_L << 8 | Press_XL);
+    return Pressure/4096;
+    }
+    
+}
+    
\ No newline at end of file
diff -r 000000000000 -r 028338208ba1 LPS25H.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPS25H.h	Fri Jan 20 20:43:29 2017 +0000
@@ -0,0 +1,63 @@
+#ifndef _LPS25H_H_
+#define _LPS25H_H_
+
+#define SLV_READ    0xBB
+#define SLV_WRITE   0xBA
+
+
+#define REF_P_XL    0x08
+#define REF_P_L     0x09
+#define REF_P_H     0x0A
+#define WHO_AM_I    0x0F
+#define RES_CONF    0x10
+
+#define CTRL_REG1   0x20
+#define CTR_REG2    0x21
+#define CTR_REG3    0x22
+#define CTR_REG4    0x23
+#define INT_CFG     0x24
+#define INT_SOURCE  0x25
+
+#define STATUS_REG  0x27
+#define PRESS_OUT_XL    0x28
+#define PRESS_OUT_L 0x29
+#define PRESS_OUT_H 0x2A
+#define TEMP_OUT_L  0x2B
+#define TEMP_OUT_G  0x2C
+
+#define FIFO_CTRL   0x2E
+#define FIFO_STATUS 0x2F
+#define THS_P_L     0x30
+#define THS_P_H     0x31
+
+#define RPDS_L      0x39
+#define RPDS_H      0x3A
+
+//I2C i2c(PB_7, PB_6);    // sda, scl
+//Serial pc(USBTX, USBRX); //tx, rx
+    
+class MyLPS25H
+{
+public:
+
+    MyLPS25H(PinName SDA, PinName SCL); 
+    //void I2C i2c(char SDA, char SCL);
+    void SetPress();    //LPS25Hのセットアップ
+    float GetPress();   //気圧データの取得
+    
+private:
+    float Pressure;
+    unsigned long Press_XL, Press_L, Press_H;
+    char cmd[2], cmd_XL[2], cmd_L[2], cmd_H[2];
+    char check[1];
+    PinName _SDA;
+    PinName _SCL;
+};
+
+
+#endif  //_LPS25H_H_
+        
+
+
+
+
diff -r 000000000000 -r 028338208ba1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jan 20 20:43:29 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0ab6a29f35bf
\ No newline at end of file