|
|
@ -11,6 +11,7 @@ |
|
|
|
// #define BMP_MOSI 23
|
|
|
|
// #define BMP_CS 32
|
|
|
|
|
|
|
|
Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); |
|
|
|
// Adafruit_BMP280 bmp(BARO_CS);
|
|
|
|
// Adafruit_BMP280 bmp(BARO_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
|
|
|
|
// BMP280_DEV bmp(BARO_CS);
|
|
|
@ -23,9 +24,8 @@ BARO::BARO(void) { |
|
|
|
pinMode(BARO_CS, OUTPUT); |
|
|
|
// For now we use digitalWrite, later change to DMA
|
|
|
|
digitalWrite(BARO_CS, LOW); |
|
|
|
|
|
|
|
delay(10); |
|
|
|
digitalWrite(BARO_CS, HIGH); // Temporary set to unselect
|
|
|
|
// digitalWrite(BARO_CS, HIGH); // Temporary set to unselect
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -69,8 +69,12 @@ int8_t BARO::bmp280_init(void) { |
|
|
|
uint8_t try_count = 5; |
|
|
|
|
|
|
|
while(try_count) { |
|
|
|
result = bmp280_get_regs(BMP280_REGISTER_CHIPID, BMP280_CHIP_ID1); |
|
|
|
// result = bmp280_get_regs(BMP280_REGISTER_CHIPID, BMP280_CHIP_ID1);
|
|
|
|
beginTransaction(); |
|
|
|
result = read_register(BMP280_REGISTER_CHIPID); |
|
|
|
endTransaction(); |
|
|
|
|
|
|
|
Serial.print("BMP280 Retry #"); Serial.print(try_count); Serial.print(" "); Serial.println(result); |
|
|
|
delay(10); |
|
|
|
try_count--; |
|
|
|
} |
|
|
@ -88,14 +92,37 @@ void BARO::begin(void) { |
|
|
|
// bit 7
|
|
|
|
// bmp280_soft_reset();
|
|
|
|
// delay(3000);
|
|
|
|
bmp280_init(); |
|
|
|
// bmp280_init();
|
|
|
|
// bmp280_init();
|
|
|
|
// beginTransaction();
|
|
|
|
|
|
|
|
beginTransaction(); |
|
|
|
delayMicroseconds(100); |
|
|
|
uint8_t status = _SPI.transfer(BMP280_REGISTER_CHIPID); |
|
|
|
status = _SPI.transfer(0xFF); |
|
|
|
Serial.print("BMP280: "); Serial.println(status); |
|
|
|
endTransaction(); |
|
|
|
if(!bmp.begin()) { |
|
|
|
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!")); |
|
|
|
} |
|
|
|
|
|
|
|
/* Default settings from datasheet. */ |
|
|
|
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ |
|
|
|
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ |
|
|
|
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ |
|
|
|
Adafruit_BMP280::FILTER_X16, /* Filtering. */ |
|
|
|
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ |
|
|
|
|
|
|
|
Serial.print(F("Temperature = ")); |
|
|
|
Serial.print(bmp.readTemperature()); |
|
|
|
Serial.println(" *C"); |
|
|
|
|
|
|
|
Serial.print(F("Pressure = ")); |
|
|
|
Serial.print(bmp.readPressure()); |
|
|
|
Serial.println(" Pa"); |
|
|
|
|
|
|
|
Serial.print(F("Approx altitude = ")); |
|
|
|
Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */ |
|
|
|
Serial.println(" m"); |
|
|
|
Serial.println(); |
|
|
|
|
|
|
|
// uint8_t status = read_register(BMP280_REGISTER_CHIPID);
|
|
|
|
// Serial.print("BMP280: "); Serial.println(status);
|
|
|
|
// endTransaction();
|
|
|
|
|
|
|
|
/***
|
|
|
|
if(!bmp.begin()) { |
|
|
@ -127,15 +154,47 @@ void BARO::get_reading(void) { |
|
|
|
**/ |
|
|
|
// pressure = bmp.readPressure() / 100.0;
|
|
|
|
// Serial.print(F("BMP280 ")); Serial.print(pressure); Serial.println(F("hPa "));
|
|
|
|
Serial.println(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */ |
|
|
|
vTaskDelay(500); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inline void BARO::beginTransaction() { |
|
|
|
_SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0)); |
|
|
|
digitalWrite(BARO_CS, LOW); |
|
|
|
delayMicroseconds(10); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inline void BARO::endTransaction() { |
|
|
|
digitalWrite(BARO_CS, HIGH); |
|
|
|
delayMicroseconds(100); |
|
|
|
_SPI.endTransaction(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint8_t BARO::read_register(uint8_t addr) { |
|
|
|
int8_t status; |
|
|
|
uint8_t result; |
|
|
|
|
|
|
|
beginTransaction(); |
|
|
|
status = _SPI.transfer(0x80 | addr); |
|
|
|
result = _SPI.transfer(0xFF); |
|
|
|
result = _SPI.transfer(0xFF); |
|
|
|
endTransaction(); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint8_t BARO::write_register(uint8_t addr, const uint8_t data) { |
|
|
|
int8_t status; |
|
|
|
uint8_t result; |
|
|
|
|
|
|
|
beginTransaction(); |
|
|
|
status = _SPI.transfer(addr); |
|
|
|
result = _SPI.transfer(data); |
|
|
|
endTransaction(); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |