Parcourir la source

Work?. But sensor olways show 32.0C/44.3H.

Vladimir N. Shilov il y a 1 an
Parent
commit
dff82adbdd
2 fichiers modifiés avec 19 ajouts et 6 suppressions
  1. 2 1
      lib/i2c.c
  2. 17 5
      src/main.c

+ 2 - 1
lib/i2c.c

@@ -190,7 +190,8 @@ uint8_t i2c_send(uint8_t addr, uint8_t numTx, uint8_t *bufTx) {
 static uint8_t i2c_read(void) {
     I2C->CR2 &= ~I2C_CR2_ACK;
     i2c_stop();
-    while (!(I2C->SR1 & I2C_SR1_RXNE));
+    I2C_timeout = 2;
+    while (!(I2C->SR1 & I2C_SR1_RXNE) && I2C_timeout);
     return I2C->DR;
 }
 

+ 17 - 5
src/main.c

@@ -45,20 +45,32 @@ void main(void)
   /* Board Configuration */
   boardInit();
   Delay(1000);
-  LedDigits[3] = led_O;
-  LedDigits[7] = led_H;
 
   /* I2C Configuration */
   i2c_init();
   AHT20_Init();
 
+  LedDigits[3] = led_O;
+  LedDigits[7] = led_H;
   /* Infinite loop */
   while (1) {
     AHT20_StartMeasure();
+    LedPoint[1] = 0;
+    LedPoint[5] = 0;
     Delay(450);
-    AHT20_GetData(&Sensor);
-    showT();
-    showH();
+    if (AHT20_GetData(&Sensor)) {
+      LedDigits[0] = led_Minus;
+      LedDigits[1] = led_Minus;
+      LedDigits[2] = led_Minus;
+      LedDigits[4] = led_Minus;
+      LedDigits[5] = led_Minus;
+      LedDigits[6] = led_Minus;
+    } else {
+      showT();
+      showH();
+    }
+    LedPoint[1] = 1;
+    LedPoint[5] = 1;
     Delay(450);
   }