X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=Src%2Fbmp085.c;h=d150b90fb5cfdd25faee56be2935321464184848;hb=d986174e8b13292d8a6d748dfe7f577e05780a8a;hp=76f548f16230d46bc5e1a05990a86e8399fdae5e;hpb=a660e78ffe99e98c4708f1dda166a47553bf9240;p=home-hw.git diff --git a/Src/bmp085.c b/Src/bmp085.c index 76f548f..d150b90 100644 --- a/Src/bmp085.c +++ b/Src/bmp085.c @@ -4,74 +4,37 @@ #include "util.h" #include "app.h" +static byte bmp_i2c_buf[4]; +volatile byte *bmp_i2c_ptr; +volatile byte bmp_i2c_len; +volatile byte bmp_i2c_addr; + static uint bmp_read(uint reg, uint bytes) { + bmp_i2c_buf[0] = reg; + bmp_i2c_ptr = bmp_i2c_buf; + bmp_i2c_len = 1; + bmp_i2c_addr = 0xee; + LL_I2C_GenerateStartCondition(I2C1); - while (!LL_I2C_IsActiveFlag_SB(I2C1)) - ; - LL_I2C_TransmitData8(I2C1, 0xee); - while (!LL_I2C_IsActiveFlag_ADDR(I2C1)) - ; - LL_I2C_ClearFlag_ADDR(I2C1); - while (!LL_I2C_IsActiveFlag_TXE(I2C1)) - ; - LL_I2C_TransmitData8(I2C1, reg); - while (!LL_I2C_IsActiveFlag_TXE(I2C1)) + LL_I2C_EnableIT_TX(I2C1); + + while (bmp_i2c_len) ; - LL_I2C_GenerateStopCondition(I2C1); + + bmp_i2c_ptr = bmp_i2c_buf; + bmp_i2c_len = bytes; + bmp_i2c_addr = 0xef; LL_I2C_GenerateStartCondition(I2C1); - while (!LL_I2C_IsActiveFlag_SB(I2C1)) - ; - LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_ACK); - LL_I2C_TransmitData8(I2C1, 0xef); - while (!LL_I2C_IsActiveFlag_ADDR(I2C1)) + LL_I2C_EnableIT_RX(I2C1); + + while (bmp_i2c_len) ; - // This is quite tricky (see manual) uint d = 0; - if (bytes == 1) - { - LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_NACK); - LL_I2C_ClearFlag_ADDR(I2C1); - LL_I2C_GenerateStopCondition(I2C1); - while (!LL_I2C_IsActiveFlag_RXNE(I2C1)) - ; - d = (d << 8) | LL_I2C_ReceiveData8(I2C1); - } - else if (bytes == 2) - { - LL_I2C_ClearFlag_ADDR(I2C1); - LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_NACK); - while (!LL_I2C_IsActiveFlag_BTF(I2C1)) - ; - LL_I2C_GenerateStopCondition(I2C1); - for (uint i=0; i<2; i++) - d = (d << 8) | LL_I2C_ReceiveData8(I2C1); - } - else - { - LL_I2C_ClearFlag_ADDR(I2C2); - - uint d = 0; - for (uint i=0; i