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.
LPS331.cpp
00001 //********************** 00002 // LPS331.cpp for mbed 00003 // 00004 // LPS331 barometer(P0_5,P0_4); 00005 // or 00006 // I2C i2c(P0_5,P0_4); 00007 // LPS331 barometer(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 "LPS331.h" 00015 00016 LPS331::LPS331 (PinName sda, PinName scl) : _i2c(sda, scl) { 00017 init(); 00018 } 00019 LPS331::LPS331 (I2C& p_i2c) : _i2c(p_i2c) { 00020 init(); 00021 } 00022 00023 void LPS331::put(unsigned char a, unsigned char b) 00024 { 00025 buf[0]=a; 00026 buf[1]=b; 00027 _i2c.write(LPS331_ADDR, buf, 2); 00028 } 00029 00030 00031 void LPS331::get(unsigned char a) 00032 { 00033 buf[0] = a; 00034 _i2c.write(LPS331_ADDR, buf, 1, true); // no stop, repeated 00035 _i2c.read( LPS331_ADDR, buf, 1); 00036 00037 } 00038 00039 long LPS331::value() 00040 { 00041 00042 // XL first and H last 00043 // get press_xl 00044 get(LPS331_PRESS_POUT_XL_REH); 00045 press.byte.LB=buf[0]; 00046 // get tpress_low 00047 get(LPS331_PRESS_OUT_L); 00048 press.byte.HB=buf[0]; 00049 // get press_high 00050 get(LPS331_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 LPS331::temperature() 00060 { 00061 00062 // L first and H last 00063 // get tpress_low 00064 get(LPS331_TEMP_OUT_L); 00065 temp.byte.LB=buf[0]; 00066 // get press_high 00067 get(LPS331_TEMP_OUT_H); 00068 temp.byte.HB=buf[0]; 00069 return temp.S; 00070 00071 // C = 42.5 + temp.S / 480 00072 // range:0 to 80C 00073 // accuracy:+-2C 00074 } 00075 00076 00077 void LPS331::init() 00078 { 00079 // Power ON Cycle=1Hz 00080 put(LPS331_CTRL_REG1, 0x90); 00081 } 00082 00083 00084
Generated on Mon Jul 18 2022 11:41:35 by
1.7.2