Sensors ULP协处理器中的ESP32读取DHT22传感器

Sensors ULP协处理器中的ESP32读取DHT22传感器,sensors,esp32,Sensors,Esp32,我试图在ulp深度睡眠中读取dht22传感器,但它不工作,也许有人能告诉我我做错了什么吗 我正在重新实现arduino DHT库,因为它与我的传感器在非ulp模式下工作,它看起来如下: digitalWrite(pin, LOW); // Send start signal pinMode(pin, OUTPUT); delayMicroseconds(800); pinMode(pin, INPUT); digitalWrite(pin, HIGH); // Switch bus

我试图在ulp深度睡眠中读取dht22传感器,但它不工作,也许有人能告诉我我做错了什么吗

我正在重新实现arduino DHT库,因为它与我的传感器在非ulp模式下工作,它看起来如下:

 digitalWrite(pin, LOW); // Send start signal
 pinMode(pin, OUTPUT);
 delayMicroseconds(800);

 pinMode(pin, INPUT);
 digitalWrite(pin, HIGH); // Switch bus to receive data

  // We're going to read 83 edges:
  // - First a FALLING, RISING, and FALLING edge for the start bit
  // - Then 40 bits: RISING and then a FALLING edge per bit
  // To keep our code simple, we accept any HIGH or LOW reading if it's max 85 usecs long

  uint16_t rawHumidity = 0;
  uint16_t rawTemperature = 0;
  uint16_t data = 0;

  for ( int8_t i = -3 ; i < 2 * 40; i++ ) {
    byte age;
    startTime = micros();

    do {
      age = (unsigned long)(micros() - startTime);
      if ( age > 90 ) {
        error = ERROR_TIMEOUT;
        return;
      }
    }
    while ( digitalRead(pin) == (i & 1) ? HIGH : LOW );

    if ( i >= 0 && (i & 1) ) {
      // Now we are being fed our 40 bits
      data <<= 1;

      // A zero max 30 usecs, a one at least 68 usecs.
      if ( age > 30 ) {
        data |= 1; // we got a one
      }
    }

    switch ( i ) {
      case 31:
        rawHumidity = data;
        break;
      case 63:
        rawTemperature = data;
        data = 0;
        break;
    }
  }
在我的ulp脚本文件中:

.set temp_humidity_sensor_pin, 13 // gpio 15 (adc 13)

send_start_signal:

    /* disable hold on gpio 15 (data pin) */
    WRITE_RTC_REG(RTC_IO_TOUCH_PAD3_REG, RTC_IO_TOUCH_PAD3_HOLD_S, 1, 0)

    /* switch to output mode */
    WRITE_RTC_REG(RTC_GPIO_OUT_W1TS_REG, RTC_GPIO_OUT_DATA_W1TS_S + temp_humidity_sensor_pin, 1, 1)

    /* send start signal (LOW) */
    WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + temp_humidity_sensor_pin, 1, 0)

    /* pull low for 800 microseconds (8Mhz) */
    wait    6400

    /* switch to input mode */
    WRITE_RTC_REG(RTC_GPIO_OUT_W1TC_REG, RTC_GPIO_OUT_DATA_W1TC_S + temp_humidity_sensor_pin, 1, 1)

    /* switch bus to receive data (HIGH) */
    WRITE_RTC_REG(RTC_GPIO_OUT_REG, RTC_GPIO_OUT_DATA_S + temp_humidity_sensor_pin, 1, 1)

wait_for_sensor_preparation_low:

    READ_RTC_REG(RTC_GPIO_IN_REG, RTC_GPIO_IN_NEXT_S + temp_humidity_sensor_pin, 1)
    and r0, r0, 1
    jump wait_for_sensor_preparation_low, eq

wait_for_sensor_preparation_high:

    READ_RTC_REG(RTC_GPIO_IN_REG, RTC_GPIO_IN_NEXT_S + temp_humidity_sensor_pin, 1) 
    and r0, r0, 0
    jump wait_for_sensor_preparation_high, eq

    jump wake_up // <-- never called :(
。设置温度湿度传感器引脚,13//gpio 15(adc 13)
发送启动信号:
/*在gpio 15(数据引脚)上禁用保持*/
写入\u RTC\u注册表(RTC\u IO\u TOUCH\u PAD3\u注册表,RTC\u IO\u TOUCH\u PAD3\u保持,1,0)
/*切换到输出模式*/
写入RTC注册(RTC GPIO OUT W1TS注册,RTC GPIO OUT数据W1TS+温度湿度传感器针脚,1,1)
/*发送启动信号(低)*/
写入\u RTC\u REG(RTC\u GPIO\u OUT\u REG,RTC\u GPIO\u OUT\u数据\u S+温度\u湿度\u传感器\u引脚,1,0)
/*拉低800微秒(8Mhz)*/
等等6400
/*切换到输入模式*/
写入RTC登记(RTC GPIO OUT W1TC登记,RTC GPIO OUT数据W1TC S+温度湿度传感器针脚,1,1)
/*开关总线以接收数据(高)*/
写入RTC注册(RTC GPIO OUT注册,RTC GPIO OUT数据+温度湿度传感器针脚,1,1)
等待\u传感器\u准备\u低:
读取\u RTC\u注册表(RTC\u GPIO\u输入\u注册表,RTC\u GPIO\u输入\u下一个\u S+温度\u湿度\u传感器\u引脚,1)
和r0,r0,1
跳转等待传感器准备低,均衡器
等待\u传感器\u准备\u高:
读取\u RTC\u注册表(RTC\u GPIO\u输入\u注册表,RTC\u GPIO\u输入\u下一个\u S+温度\u湿度\u传感器\u引脚,1)
和r0,r0,0
跳转等待传感器准备高,均衡器
跳转唤醒//您的“and r0,r0,0”指令(接近末尾)总是将r0设置为零(定义为x&0==0),这意味着下面的跳转指令将永远循环。请记住,“eq”标志实际上并不意味着“相等”。它的意思是“零”。我想你想要:

wait_for_sensor_preparation_low:

    READ_RTC_REG(RTC_GPIO_IN_REG, RTC_GPIO_IN_NEXT_S + temp_humidity_sensor_pin, 1)
    and r0, r0, 1
    jump wait_for_sensor_preparation_high, eq
    jump wait_for_sensor_preparation_low

wait_for_sensor_preparation_high:

    READ_RTC_REG(RTC_GPIO_IN_REG, RTC_GPIO_IN_NEXT_S + temp_humidity_sensor_pin, 1) 
    and r0, r0, 1
    jump wait_for_sensor_preparation_high, eq

顺便说一下,我为ULP编写了一个C编译器,这会让您的生活更轻松。已打开

感谢您的帮助和对“eq”标志的澄清,它现在可以正常工作了。这是我第一次在汇编程序中编写代码,我将尝试您的编译器,希望这是最后一次:D
wait_for_sensor_preparation_low:

    READ_RTC_REG(RTC_GPIO_IN_REG, RTC_GPIO_IN_NEXT_S + temp_humidity_sensor_pin, 1)
    and r0, r0, 1
    jump wait_for_sensor_preparation_high, eq
    jump wait_for_sensor_preparation_low

wait_for_sensor_preparation_high:

    READ_RTC_REG(RTC_GPIO_IN_REG, RTC_GPIO_IN_NEXT_S + temp_humidity_sensor_pin, 1) 
    and r0, r0, 1
    jump wait_for_sensor_preparation_high, eq