Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LPS25H by
LPS25H.cpp
00001 //********************** 00002 // LPS25H.cpp for mbed 00003 // 00004 // LPS25H lps25h(P0_5,P0_4); 00005 // or 00006 // I2C i2c(P0_5,P0_4); 00007 // LPS25H lps25h(i2c); 00008 // 00009 // (C)Copyright 2014 All rights reserved by Y.Onodera 00010 // http://einstlab.web.fc2.com 00011 //********************** 00012 00013 #include "mbed.h" 00014 #include "LPS25H.h" 00015 00016 LPS25H::LPS25H (PinName sda, PinName scl) : _i2c(sda, scl) { 00017 init(); 00018 } 00019 LPS25H::LPS25H (I2C& p_i2c) : _i2c(p_i2c) { 00020 init(); 00021 } 00022 00023 void LPS25H::put(unsigned char a, unsigned char b) 00024 { 00025 buf[0]=a; 00026 buf[1]=b; 00027 _i2c.write(LPS25H_ADDR, buf, 2); 00028 } 00029 00030 00031 void LPS25H::get(unsigned char a) 00032 { 00033 buf[0] = a; 00034 _i2c.write(LPS25H_ADDR, buf, 1, true); // no stop, repeated 00035 _i2c.read( LPS25H_ADDR, buf, 1); 00036 00037 } 00038 00039 long LPS25H::pressure() 00040 { 00041 00042 // XL first and H last 00043 // get press_xl 00044 get(LPS25H_PRESS_POUT_XL_REH); 00045 press.byte.LB=buf[0]; 00046 // get tpress_low 00047 get(LPS25H_PRESS_OUT_L); 00048 press.byte.HB=buf[0]; 00049 // get press_high 00050 get(LPS25H_PRESS_OUT_H); 00051 press.byte.UB=buf[0]; 00052 return press.Val; 00053 00054 // hPa = press.Val / 4096 00055 // Pa = press.Val / 40.96 00056 } 00057 00058 00059 short LPS25H::temperature() 00060 { 00061 00062 // L first and H last 00063 // get tpress_low 00064 get(LPS25H_TEMP_OUT_L); 00065 temp.byte.LB=buf[0]; 00066 // get press_high 00067 get(LPS25H_TEMP_OUT_H); 00068 temp.byte.HB=buf[0]; 00069 00070 return temp.S; 00071 00072 // C = 42.5 + temp.S / 480 00073 // range:0 to 80C 00074 // accuracy:+-2C 00075 } 00076 00077 00078 void LPS25H::init() 00079 { 00080 // Power ON Cycle=25Hz 00081 put(LPS25H_CTRL_REG1, 0xC0); 00082 } 00083 00084
Generated on Wed Aug 3 2022 18:18:06 by
1.7.2
