BMP280から気圧データを取得します。updateで更新動作、getpressで値を読み出します
Diff: BMP280.cpp
- Revision:
- 1:a65c7f637b1e
- Parent:
- 0:54d7f18450e6
--- 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