Pārlūkot izejas kodu

estaba cambiada la lectura de valores del bus

dacowars 1 mēnesi atpakaļ
vecāks
revīzija
0b8ff07dab
1 mainītis faili ar 10 papildinājumiem un 9 dzēšanām
  1. 10 9
      main/main.c

+ 10 - 9
main/main.c

@@ -14,10 +14,10 @@ static const char *TAG = "DHT22";
 static portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
 
 // Macro to check the return value of a function and log an error if it is not ESP_OK
+// portEXIT_CRITICAL(&mux);  despues del if
 #define CHECK_LOGE(x, msg, ...) do { \
         esp_err_t __; \
         if ((__ = x) != ESP_OK) { \
-            portEXIT_CRITICAL(&mux); \
             ESP_LOGE(TAG, msg, ## __VA_ARGS__); \
             return __; \
         } \
@@ -59,17 +59,18 @@ static inline esp_err_t dht_communication(gpio_num_t pin, uint32_t *data){
     esp_rom_delay_us(1500); // Pull low for at least 1ms
     gpio_set_level(pin, 1); // Release the line
 
-    CHECK_LOGE(get_change_time(pin, 44, 1, &low_time), "Failed to get dht response"); // Wait for the sensor to pull low 20-40us
-    CHECK_LOGE(get_change_time(pin, 88, 0, &high_time), "Failed to get dht response"); // Wait for the sensor to pull high 80us
-    CHECK_LOGE(get_change_time(pin, 88, 1, &low_time), "Failed to get dht response"); // Wait for the sensor to pull low 80us
+    CHECK_LOGE(get_change_time(pin, 44, 0, &low_time), "Failed to get dht response"); // Wait for the sensor to pull low 20-40us
+    CHECK_LOGE(get_change_time(pin, 88, 1, &high_time), "Failed to get dht response"); // Wait for the sensor to pull high 80us
+    CHECK_LOGE(get_change_time(pin, 88, 0, &low_time), "Failed to get dht response"); // Wait for the sensor to pull low 80us
+    
 
     for (uint8_t i = DHT_DATA_BITS; i > 0; i--){
         
         // Wait for the sensor to pull low 50us
-        CHECK_LOGE(get_change_time(pin, 65, 0, &low_time), "Failed dht transmission"); 
+        CHECK_LOGE(get_change_time(pin, 65, 1, &low_time), "Failed dht transmission %d h", i); 
         
         // Wait for the sensor to pull high 26-28us for 0 and 70us for 1
-        CHECK_LOGE(get_change_time(pin, 80, 1, &high_time), "Failed dht transmission"); 
+        CHECK_LOGE(get_change_time(pin, 80, 0, &high_time), "Failed dht transmission %d l", i); 
 
         if (i < 9){
             checksum |= (high_time > low_time) << (i - 1);
@@ -81,7 +82,7 @@ static inline esp_err_t dht_communication(gpio_num_t pin, uint32_t *data){
     }
 
     if (checksum != ((uint8_t)(*data >> 24) + (uint8_t)(*data >> 16) + (uint8_t)(*data >> 8) + (uint8_t)(*data))) {
-        //ESP_LOGE(TAG, "DHT22 checksum mismatch");
+        ESP_LOGE(TAG, "DHT22 checksum mismatch");
         return ESP_ERR_INVALID_CRC;
     }
 
@@ -95,10 +96,10 @@ esp_err_t dht_read(gpio_num_t pin, float *temperature, float *humidity){
     gpio_set_direction(pin, GPIO_MODE_INPUT_OUTPUT_OD);
     gpio_set_level(pin, 1); 
 
-    portENTER_CRITICAL(&mux);
+    //portENTER_CRITICAL(&mux);
     esp_err_t err = dht_communication(pin, &data);
     if (err == ESP_OK) {
-        portEXIT_CRITICAL(&mux);
+       // portEXIT_CRITICAL(&mux);
     }
 
     gpio_set_direction(pin, GPIO_MODE_INPUT_OUTPUT_OD);