Added basic bmp280 structure - functional

temperature readout must be added and compensation must be checked
This commit is contained in:
Matthias Mitscherlich
2023-02-08 12:14:27 +01:00
parent 35c940ca5b
commit edeaedeb07
5 changed files with 220 additions and 41 deletions
+16 -39
View File
@@ -110,27 +110,10 @@ static void devTask(void* parameters);
static void colourMapTask(void* parameters);
static int bmp280_compensate_T_int32(int adc_T);
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
int t_fine;
uint16_t dig_T1 = 0x6AA3;
int16_t dig_T2 = 0x6555;
int16_t dig_T3 = 0x0032;
int bmp280_compensate_T_int32(int adc_T)
{
int var1, var2, T;
var1 = ((((adc_T>>3) - ((int)dig_T1<<1))) * ((int)dig_T2)) >> 11;
var2 = (((((adc_T>>4) - ((int)dig_T1)) * ((adc_T>>4) - ((int)dig_T1))) >> 12) * ((int)dig_T3)) >> 14;
t_fine = var1 + var2;
T = (t_fine * 5 + 128) >> 8;
return T;
}
extern "C" void app_main(void)
{
esp_log_level_set("*", ESP_LOG_WARN);
@@ -209,22 +192,27 @@ extern "C" void app_main(void)
// SourceData: GPIO 9
I2C i2c0(8, 9);
uint8_t data[6];
// Read BME280 ID register
i2c0.read_register(0x76, 0xD0, data, 1);
LOGGER_DEBUG("BMP280 ID: %02X", data[0]);
// Read compensation values
i2c0.read_register(0x76, 0x88, data, 6);
// Set the oversampling to x1
uint8_t writeData = 0x27;
i2c0.write_register(0x76, 0xF4, &writeData, 1);
//--------------------------------------------
// BMP280
//
// Communicates on I2C i2c0
// Has slave address 0x76
BMP280 bmp280(&i2c0, 0x76);
// Reset the sensor
bmp280.resetSensor();
// Make sure to apply a wait cycle between reset and continuous use - 2ms is advised as minimum
vTaskDelay(10);
// Initialize the BMP280
bmp280.initialize();
// Set the temperature Oversampling
bmp280.setSensorTemperatureOversampling(BMP280::BMP280_Oversampling_t::X1);
// Set the sensor to NORMAL mode
bmp280.setSensorMode(BMP280::BMP280_Mode_t::NORMAL);
//--------------------------------------------
// LED Matrix
//
matrix.setGlobalColour(0x10, 0, 0x04);
// matrix.setGlobalColour(0x80, 0, 0x40);
@@ -286,17 +274,6 @@ extern "C" void app_main(void)
matrix.setPixelValue(10, 9, clock.getTime() % 2);
i2c0.read_register(0x76, 0xF7, data, 3);
LOGGER_DEBUG("BMP280 pressure: %02X %02X %02X", data[0], data[1], data[2]);
i2c0.read_register(0x76, 0xFA, data, 3);
int32_t value = 0;
value |= data[0] << 12;
value |= data[1] << 4;
value |= data[2] >> 4;
int valueComp = bmp280_compensate_T_int32(value);
LOGGER_DEBUG("BMP280 temperature: %02X %02X %02X -> %d", data[0], data[1], data[2], valueComp);
// Update the clock every second (1000 ms)
vTaskDelay(1000);