UART sleep is not working

alhadi
Posts: 15
Joined: Thu Apr 14, 2022 9:29 am

UART sleep is not working

Postby alhadi » Mon Aug 28, 2023 11:34 am

Hello,
I'm testing UART wakeup to use later on another application. But it's not working with me on v4.4.
It is working fine on Arduino for some reason but not on esp-idf. So, the HW is fine.
I'm assuming I missed something in sdkconfig maybe?
My hw is esp32s3

My code:

Code: Select all

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_sleep.h"
#include "esp_log.h"
#include "driver/uart.h"
#include "driver/gpio.h"

#define RX_PIN 36 //UART_PIN_NO_CHANGE 


void app_main() {
    // Configure UART
    uart_config_t uart_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };

    // init uart 0
    uart_param_config(UART_NUM_0, &uart_config);
    uart_set_pin(UART_NUM_0, UART_PIN_NO_CHANGE, RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
    uart_driver_install(UART_NUM_0, 256, 0, 0, NULL, 0);

    esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
    esp_sleep_enable_timer_wakeup(30 * 1000 * 1000);
    uart_set_wakeup_threshold(UART_NUM_0, 3);
    esp_sleep_enable_uart_wakeup(UART_NUM_0);

    while(1){
        // Enter light sleep mode
        vTaskDelay(pdMS_TO_TICKS(1000));
        esp_light_sleep_start();
		
		vTaskDelay(pdMS_TO_TICKS(1000));
        ESP_LOGI("TAG", "After wakeup");
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}
The arduino code that is working:

Code: Select all

#include <esp_sleep.h>
#include <driver/uart.h>
 
int variable = 0;
 
void setup() {
    Serial.begin(115200);
 
    while(!Serial){delay(500);}
 
    delay(1000);
 
    Serial.println();
    Serial.println("LIGHT SLEEP ENABLED");
    delay(100);

    uart_set_wakeup_threshold(UART_NUM_0, 3);
    esp_sleep_enable_uart_wakeup(UART_NUM_0);
     
    esp_light_sleep_start();
 
    Serial.begin(115200);
    while(!Serial){delay(500);}
    // Clean Serial from wake up message
    Serial.flush();
    Serial.readString();
 
    Serial.println();
    Serial.println("LIGHT SLEEP WAKE UP");
}
 
void loop() {
    while (Serial.available()>0){
        Serial.write(Serial.read());
    }
}
my sdkconfig is default

alhadi
Posts: 15
Joined: Thu Apr 14, 2022 9:29 am

Re: UART sleep is not working

Postby alhadi » Tue Aug 29, 2023 2:33 pm

Any reply please?

Who is online

Users browsing this forum: Bing [Bot] and 338 guests