BME280 Combined humidity and pressure sensor library with SPI interface
Dependents: BME280_SPI_Hello TYBLE16_simple_data_logger mpl115a2_display_local GS_final
Fork of BME280 by
Revision 8:f0faf51d3d4a, committed 2017-03-13
- Comitter:
- MACRUM
- Date:
- Mon Mar 13 15:37:22 2017 +0000
- Parent:
- 7:dfd6107f1f92
- Commit message:
- Change initialize values
Changed in this revision
BME280_SPI.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r dfd6107f1f92 -r f0faf51d3d4a BME280_SPI.cpp --- a/BME280_SPI.cpp Mon Mar 13 07:23:21 2017 +0000 +++ b/BME280_SPI.cpp Mon Mar 13 15:37:22 2017 +0000 @@ -55,12 +55,12 @@ _cs = 0; _spi.write(0xf2 & BME280_SPI_MASK); // ctrl_hum - _spi.write(0x01); // Humidity oversampling x1 + _spi.write(0x04); // Humidity oversampling x4 _cs = 1; _cs = 0; _spi.write(0xf4 & BME280_SPI_MASK); // ctrl_meas - _spi.write(0x27); // Temparature oversampling x1, Pressure oversampling x1, Normal mode + _spi.write((4<<5)|(4<<2)|3); // Temparature oversampling x4, Pressure oversampling x4, Normal mode _cs = 1; _cs = 0; @@ -68,6 +68,8 @@ _spi.write(0xa0); // Standby 1000ms, Filter off, 4-wire SPI interface _cs = 1; + wait(1); + _cs = 0; _spi.write(0x88); // read dig_T regs for(int i = 0; i < 6; i++) @@ -82,7 +84,7 @@ DEBUG_PRINT("dig_T = %d, %d, %d\n", dig_T1, dig_T2, dig_T3); _cs = 0; - _spi.write(0x8e); + _spi.write(0x8e); // read dig_P regs for(int i = 0; i < 18; i++) cmd[i] = _spi.write(0); _cs = 1; @@ -101,7 +103,7 @@ DEBUG_PRINT("dig_P = %d, %d, %d, %d, %d, %d, %d, %d, %d\n", dig_P1, dig_P2, dig_P3, dig_P4, dig_P5, dig_P6, dig_P7, dig_P8, dig_P9); _cs = 0; - _spi.write(0xA1); // read dig_H regs + _spi.write(0xA1); // read dig_H1 reg cmd[0] = _spi.write(0); _cs = 1; @@ -126,15 +128,15 @@ { uint32_t temp_raw; float tempf; - char cmd[4]; + char cmd[3]; _cs = 0; _spi.write(0xfa); for(int i = 0; i < 3; i++) - cmd[1+i] = _spi.write(0); + cmd[i] = _spi.write(0); _cs = 1; - temp_raw = (cmd[1] << 12) | (cmd[2] << 4) | (cmd[3] >> 4); + temp_raw = (cmd[0] << 12) | (cmd[1] << 4) | (cmd[2] >> 4); int32_t temp; @@ -153,15 +155,15 @@ { uint32_t press_raw; float pressf; - char cmd[4]; + char cmd[3]; _cs = 0; _spi.write(0xf7); // press_msb for(int i = 0; i < 3; i++) - cmd[1+i] = _spi.write(0); + cmd[i] = _spi.write(0); _cs = 1; - press_raw = (cmd[1] << 12) | (cmd[2] << 4) | (cmd[3] >> 4); + press_raw = (cmd[0] << 12) | (cmd[1] << 4) | (cmd[2] >> 4); int32_t var1, var2; uint32_t press; @@ -193,15 +195,15 @@ { uint32_t hum_raw; float humf; - char cmd[4]; + char cmd[2]; _cs = 0; _spi.write(0xfd); // hum_msb for(int i = 0; i < 2; i++) - cmd[1+i] = _spi.write(0); + cmd[i] = _spi.write(0); _cs = 1; - hum_raw = (cmd[1] << 8) | cmd[2]; + hum_raw = (cmd[0] << 8) | cmd[1]; int32_t v_x1;