Ver código fonte

I2C does not work?.

Vladimir N. Shilov 1 ano atrás
pai
commit
114c6825fa
2 arquivos alterados com 24 adições e 23 exclusões
  1. 12 8
      lib/htu21.c
  2. 12 15
      src/main.c

+ 12 - 8
lib/htu21.c

@@ -18,7 +18,7 @@ htu_err_t htu_GetTemperature(int16_t * temperature) {
   if (i2cs == 0) {
     Delay(90);
     i2c_rd_reg(addr, buf);
-    if(buf[2] == CalcSht21Crc(buf,2)) {
+//    if(buf[2] == CalcSht21Crc(buf,2)) {
       val = buf[0];
       val <<= 8;
       val |= (buf[1] & 0xfc);
@@ -29,10 +29,12 @@ htu_err_t htu_GetTemperature(int16_t * temperature) {
       val /= 1638400; // 2^16/4*100
       *temperature = val - 4685;
       return HTU_OK;
-    } else {
-      return HTU_CRC_Temp;
-    }
+//    } else {
+//      *temperature = 1;
+//      return HTU_CRC_Temp;
+//    }
   } else {
+    *temperature = 777;
     return HTU_I2C;
   }
 }
@@ -42,7 +44,7 @@ htu_err_t htu_GetHumidity(uint16_t * humidity) {
   if (i2cs == 0) {
     Delay(60);
     i2c_rd_reg(addr, buf);
-    if(buf[2] == CalcSht21Crc(buf,2)) {
+//    if(buf[2] == CalcSht21Crc(buf,2)) {
       val = buf[0];
       val <<= 8;
       val |= (buf[1] & 0xfc);
@@ -53,10 +55,12 @@ htu_err_t htu_GetHumidity(uint16_t * humidity) {
       val /= 65536;
       *humidity = val - 60;
       return HTU_OK;
-    } else {
-      return HTU_CRC_Humidity;
-    }
+//    } else {
+//      *humidity = 1;
+//      return HTU_CRC_Humidity;
+//    }
   } else {
+    *humidity = 555;
     return HTU_I2C;
   }
 }

+ 12 - 15
src/main.c

@@ -45,6 +45,9 @@ void main(void)
 {
   /* Board Configuration */
   boardInit();
+  Delay(1000);
+  LedDigits[3] = led_O;
+  LedDigits[7] = led_H;
 
   /* I2C Configuration */
   i2c_master_init();
@@ -63,28 +66,22 @@ void main(void)
 
 /* Private functions ---------------------------------------------------------*/
 static void showT(void) {
-  int16_t t;
+  int16_t t = (Temperature + 5) / 10;;
   uint8_t a;
-  if (Temperature > 0) {
-    LedDigits[0] = LED_OUT_PL;
-    t = (Temperature + 5) / 10;
-  } else {
-    LedDigits[0] = LED_OUT_MM;
-    t = ((Temperature + 5) / 10) * -1;
-  }
-  LedDigits[1] = t / 100;
+
+  LedDigits[0] = t / 100;
   a = t % 100;
-  LedDigits[2] = a / 10;
-  LedDigits[3] = a % 10;
+  LedDigits[1] = a / 10;
+  LedDigits[2] = a % 10;
 }
 
 static void showH(void) {
  uint8_t a;
- LedDigits[4] = LED_OUT_H;
- LedDigits[5] = Humidity / 100;
+
+ LedDigits[4] = Humidity / 100;
  a = Humidity % 100;
- LedDigits[6] = a / 10;
- LedDigits[7] = a % 10;
+ LedDigits[5] = a / 10;
+ LedDigits[6] = a % 10;
 }
 
 static void boardInit(void) {