BMP280から気圧データを取得します。updateで更新動作、getpressで値を読み出します
Revision 1:a65c7f637b1e, committed 2018-02-13
- Comitter:
- kim1212
- Date:
- Tue Feb 13 04:19:43 2018 +0000
- Parent:
- 0:54d7f18450e6
- Commit message:
- ?????????????????
Changed in this revision
BMP280.cpp | Show annotated file Show diff for this revision Revisions of this file |
BMP280.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/BMP280.cpp Sun Dec 04 14:38:21 2016 +0000 +++ b/BMP280.cpp Tue Feb 13 04:19:43 2018 +0000 @@ -4,7 +4,7 @@ BMP280::BMP280(PinName mosi,PinName miso,PinName sck,PinName _cs):bmp(mosi,miso,sck),cs(_cs) { cs=1; - bmp.frequency(1000000); + bmp.frequency(10000000); bmp.format(8,3); wait(0.1); @@ -43,12 +43,17 @@ } -void BMP280::init(char t_osr,char p_osr,char t_sb,char IIR){ - char data=((t_osr<<5)|(p_osr<<2))|0b11; +void BMP280::init(char t_osr,char p_osr,char IIR){ + _t_osr=t_osr; + _p_osr=p_osr; + _IIR=IIR; + + //forced mode trigger + char data=((t_osr<<5)|(p_osr<<2))|0b01; writebyte(0xf4,data);//config data=0; - data=(t_sb<<5)|(IIR<<2); + data=(IIR<<2); writebyte(0xf5,data); } @@ -117,15 +122,22 @@ adc_P=(int)((data[2]>>4)|(data[1]<<4))|(data[0]<<12); + //forced mode trigger + char buf=((_t_osr<<5)|(_p_osr<<2))|0b01; + writebyte(0xf4,buf);//config + buf=(_IIR<<2); + writebyte(0xf5,buf); + bmp280_compensate_T_int32(adc_T); press=bmp280_compensate_P_int64(adc_P); + + return true; - } + }else return false; -return false; } -float BMP280::getpress(){ - return (float)press; +unsigned int BMP280::getpress(){ + return press; } \ No newline at end of file
--- a/BMP280.h Sun Dec 04 14:38:21 2016 +0000 +++ b/BMP280.h Tue Feb 13 04:19:43 2018 +0000 @@ -9,7 +9,7 @@ int main() { - bmp.init(OSR_1,OSR_4,T_SB_0_5,IIR_0); + bmp.init(OSR_1,OSR_4,IIR_0); while(1) { @@ -26,18 +26,9 @@ #define OSR_8 0b100 #define OSR_16 0b101 -#define T_SB_0_5 0b000 -#define T_SB_62_5 0b001 -#define T_SB_125 0b010 -#define T_SB_250 0b011 -#define T_SB_500 0b100 -#define T_SB_1000 0b101 -#define T_SB_2000 0b110 -#define T_SB_4000 0b111 - #define IIR_0 0b000 #define IIR_4 0b100 -#define IIR_16 0b10000 +#define IIR_16 0b111 @@ -47,7 +38,7 @@ public: BMP280(PinName mosi,PinName miso,PinName sck,PinName _cs); - void init(char t_osr,char p_osr,char t_sb,char IIR); + void init(char t_osr,char p_osr,char IIR); char readbyte(char adr); void writebyte(char adr,char data); void readnbyte(char adr,char *data,char num); @@ -55,7 +46,7 @@ int bmp280_compensate_T_int32(int adc_T); unsigned int bmp280_compensate_P_int64(int adc_P); bool update(); - float getpress(); + unsigned int getpress(); private: @@ -66,6 +57,9 @@ short dig_T2,dig_T3,dig_P2,dig_P3,dig_P4,dig_P5,dig_P6,dig_P7,dig_P8,dig_P9; unsigned int press; + char _t_osr; + char _p_osr; + char _IIR; };