X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=Src%2Fbmp085.c;h=76f548f16230d46bc5e1a05990a86e8399fdae5e;hb=a660e78ffe99e98c4708f1dda166a47553bf9240;hp=4df07c2ea9f9554ce96ce9da11f4dc8d942ea242;hpb=20f95c72bf21389ac92f354d8d81f5fe87772fc0;p=home-hw.git diff --git a/Src/bmp085.c b/Src/bmp085.c index 4df07c2..76f548f 100644 --- a/Src/bmp085.c +++ b/Src/bmp085.c @@ -12,7 +12,7 @@ static uint bmp_read(uint reg, uint bytes) LL_I2C_TransmitData8(I2C1, 0xee); while (!LL_I2C_IsActiveFlag_ADDR(I2C1)) ; - LL_I2C_ClearFlag_ADDR(I2C2); + LL_I2C_ClearFlag_ADDR(I2C1); while (!LL_I2C_IsActiveFlag_TXE(I2C1)) ; LL_I2C_TransmitData8(I2C1, reg); @@ -27,23 +27,56 @@ static uint bmp_read(uint reg, uint bytes) LL_I2C_TransmitData8(I2C1, 0xef); while (!LL_I2C_IsActiveFlag_ADDR(I2C1)) ; - LL_I2C_ClearFlag_ADDR(I2C2); + // This is quite tricky (see manual) uint d = 0; - for (uint i=0; i>= (8-oss); @@ -124,30 +153,43 @@ void bmp_init(void) bmp_constants[i] = bmp_read(0xaa + 2*i, 2); } -#if 0 -void run_test(void) -{ - for (;;) - { - debug_puts("Constants:"); - u16 cc[11]; - for (uint i=0; i<11; i++) - { - cc[i] = bmp_read(0xaa + 2*i, 2); - debug_printf(" %04x", cc[i]); - } - debug_puts("\r\n"); - - uint raw_temp = bmp_measure(0x2e, 2); - debug_printf("Raw temperature: %04x\r\n", raw_temp); +enum bmp_state { + BMP_IDLE, + BMP_TEMP, + BMP_PRESSURE, +}; - uint oss = 3; // Over-sampling setting - uint raw_press = bmp_measure(0xf4 | (oss<<6), 3); - debug_printf("Raw pressure: %06x\r\n", raw_press); +static byte bmp_state = BMP_IDLE; +static u16 raw_temp; +static u32 raw_press; +#define BMP_OSS 3 +s16 adjusted_temp; +s16 adjusted_press; - int temp, press; - bmp_recalc(raw_temp, raw_press, oss, cc, &temp, &press); - debug_printf("Temperature: %d ddegC\r\n", temp); - debug_printf("Pressure: %d Pa\r\n", press); +void bmp_step(void) +{ + switch (bmp_state) + { + case BMP_IDLE: + debug_puts("BMP: Start measure\n"); + bmp_start_measure(0x2e); + bmp_state++; + break; + case BMP_TEMP: + if (!LL_GPIO_IsInputPinSet(BMP_DONE_GPIO_Port, BMP_DONE_Pin)) + return; + debug_puts("BMP: Temperature done\n"); + raw_press = bmp_read(0xf6, 2); + bmp_start_measure(0xf4 | (BMP_OSS<<6)); + bmp_state++; + break; + case BMP_PRESSURE: + if (!LL_GPIO_IsInputPinSet(BMP_DONE_GPIO_Port, BMP_DONE_Pin)) + return; + debug_puts("BMP: Pressure done\n"); + raw_press = bmp_read(0xf6, 3); + bmp_recalc(raw_temp, raw_press, BMP_OSS, bmp_constants, &adjusted_temp, &adjusted_press); + bmp_state = BMP_IDLE; + break; } -#endif +}