From 0134e19edf7f8ab39707687c020fe083e5b06ba1 Mon Sep 17 00:00:00 2001 From: digitalentity Date: Thu, 2 Apr 2015 08:51:47 +1000 Subject: [PATCH 1/2] Avoid reading data from BMP085 when no EOC event occured --- src/main/drivers/barometer_bmp085.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/drivers/barometer_bmp085.c b/src/main/drivers/barometer_bmp085.c index a67f34f3fe..ad01bdf547 100644 --- a/src/main/drivers/barometer_bmp085.c +++ b/src/main/drivers/barometer_bmp085.c @@ -31,6 +31,7 @@ #include "barometer_bmp085.h" +#if defined(BARO) && defined(BARO_EOC_GPIO) // BMP085, Standard address 0x77 static bool convDone = false; static uint16_t convOverrun = 0; @@ -43,6 +44,7 @@ void EXTI15_10_IRQHandler(void) convDone = true; } } +#endif typedef struct { int16_t ac1; @@ -193,8 +195,8 @@ bool bmp085Detect(const bmp085Config_t *config, baro_t *baro) bmp085.al_version = BMP085_GET_BITSLICE(data, BMP085_AL_VERSION); /* get AL Version */ bmp085_get_cal_param(); /* readout bmp085 calibparam structure */ bmp085InitDone = true; - baro->ut_delay = 6000; // 1.5ms margin according to the spec (4.5ms T convetion time) - baro->up_delay = 27000; // 6000+21000=27000 1.5ms margin according to the spec (25.5ms P convetion time with OSS=3) + baro->ut_delay = 6000; // 1.5ms margin according to the spec (4.5ms T conversion time) + baro->up_delay = 27000; // 6000+21000=27000 1.5ms margin according to the spec (25.5ms P conversion time with OSS=3) baro->start_ut = bmp085_start_ut; baro->get_ut = bmp085_get_ut; baro->start_up = bmp085_start_up; @@ -263,7 +265,9 @@ static int32_t bmp085_get_pressure(uint32_t up) static void bmp085_start_ut(void) { +#if defined(BARO) && defined(BARO_EOC_GPIO) convDone = false; +#endif i2cWrite(BMP085_I2C_ADDR, BMP085_CTRL_MEAS_REG, BMP085_T_MEASURE); } @@ -271,9 +275,13 @@ static void bmp085_get_ut(void) { uint8_t data[2]; +#if defined(BARO) && defined(BARO_EOC_GPIO) // wait in case of cockup - if (!convDone) + if (!convDone) { convOverrun++; + return; // keep old value + } +#endif i2cRead(BMP085_I2C_ADDR, BMP085_ADC_OUT_MSB_REG, 2, data); bmp085_ut = (data[0] << 8) | data[1]; @@ -284,7 +292,11 @@ static void bmp085_start_up(void) uint8_t ctrl_reg_data; ctrl_reg_data = BMP085_P_MEASURE + (bmp085.oversampling_setting << 6); + +#if defined(BARO) && defined(BARO_EOC_GPIO) convDone = false; +#endif + i2cWrite(BMP085_I2C_ADDR, BMP085_CTRL_MEAS_REG, ctrl_reg_data); } @@ -296,9 +308,13 @@ static void bmp085_get_up(void) { uint8_t data[3]; +#if defined(BARO) && defined(BARO_EOC_GPIO) // wait in case of cockup - if (!convDone) + if (!convDone) { convOverrun++; + return; // keep old value + } +#endif i2cRead(BMP085_I2C_ADDR, BMP085_ADC_OUT_MSB_REG, 3, data); bmp085_up = (((uint32_t) data[0] << 16) | ((uint32_t) data[1] << 8) | (uint32_t) data[2]) From 9065efed941864760fe34b7eaf008d2f64135d69 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Tue, 7 Apr 2015 19:50:29 +0100 Subject: [PATCH 2/2] BMP085 code cleanup. --- src/main/drivers/barometer_bmp085.c | 35 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/drivers/barometer_bmp085.c b/src/main/drivers/barometer_bmp085.c index ad01bdf547..c67eb4e6d5 100644 --- a/src/main/drivers/barometer_bmp085.c +++ b/src/main/drivers/barometer_bmp085.c @@ -31,17 +31,19 @@ #include "barometer_bmp085.h" -#if defined(BARO) && defined(BARO_EOC_GPIO) +#ifdef BARO + +#if defined(BARO_EOC_GPIO) // BMP085, Standard address 0x77 -static bool convDone = false; -static uint16_t convOverrun = 0; +static bool isConversionComplete = false; +static uint16_t bmp085ConversionOverrun = 0; // EXTI14 for BMP085 End of Conversion Interrupt void EXTI15_10_IRQHandler(void) { if (EXTI_GetITStatus(EXTI_Line14) == SET) { EXTI_ClearITPendingBit(EXTI_Line14); - convDone = true; + isConversionComplete = true; } } #endif @@ -151,7 +153,7 @@ bool bmp085Detect(const bmp085Config_t *config, baro_t *baro) if (bmp085InitDone) return true; -#if defined(BARO) && defined(BARO_XCLR_GPIO) && defined(BARO_EOC_GPIO) +#if defined(BARO_XCLR_GPIO) && defined(BARO_EOC_GPIO) if (config) { EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; @@ -265,8 +267,8 @@ static int32_t bmp085_get_pressure(uint32_t up) static void bmp085_start_ut(void) { -#if defined(BARO) && defined(BARO_EOC_GPIO) - convDone = false; +#if defined(BARO_EOC_GPIO) + isConversionComplete = false; #endif i2cWrite(BMP085_I2C_ADDR, BMP085_CTRL_MEAS_REG, BMP085_T_MEASURE); } @@ -275,10 +277,9 @@ static void bmp085_get_ut(void) { uint8_t data[2]; -#if defined(BARO) && defined(BARO_EOC_GPIO) - // wait in case of cockup - if (!convDone) { - convOverrun++; +#if defined(BARO_EOC_GPIO) + if (!isConversionComplete) { + bmp085ConversionOverrun++; return; // keep old value } #endif @@ -293,8 +294,8 @@ static void bmp085_start_up(void) ctrl_reg_data = BMP085_P_MEASURE + (bmp085.oversampling_setting << 6); -#if defined(BARO) && defined(BARO_EOC_GPIO) - convDone = false; +#if defined(BARO_EOC_GPIO) + isConversionComplete = false; #endif i2cWrite(BMP085_I2C_ADDR, BMP085_CTRL_MEAS_REG, ctrl_reg_data); @@ -308,10 +309,10 @@ static void bmp085_get_up(void) { uint8_t data[3]; -#if defined(BARO) && defined(BARO_EOC_GPIO) +#if defined(BARO_EOC_GPIO) // wait in case of cockup - if (!convDone) { - convOverrun++; + if (!isConversionComplete) { + bmp085ConversionOverrun++; return; // keep old value } #endif @@ -354,3 +355,5 @@ static void bmp085_get_cal_param(void) bmp085.cal_param.mc = (data[18] << 8) | data[19]; bmp085.cal_param.md = (data[20] << 8) | data[21]; } + +#endif