ESP32 C3, IDF 4.3.1版本, \examples\wifi\power_save\这个例程,加上一个UART接收功能,发现UART数据接收不正常,收不到正确数据(但发UART数据可以)
测试程序如下:
// check if power save/light sleep will affect uart or not
static void uart_task(void *arg)
{
/* Configure parameters of an UART driver,
* communication pins and install the driver */
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,
.source_clk = UART_SCLK_APB,
};
int intr_alloc_flags = 0;
#if CONFIG_UART_ISR_IN_IRAM
intr_alloc_flags = ESP_INTR_FLAG_IRAM;
#endif
ESP_ERROR_CHECK(uart_driver_install(ECHO_UART_PORT_NUM, BUF_SIZE * 4, 0, 0, NULL, intr_alloc_flags));
ESP_ERROR_CHECK(uart_param_config(ECHO_UART_PORT_NUM, &uart_config));
ESP_ERROR_CHECK(uart_set_pin(ECHO_UART_PORT_NUM, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS));
// Configure a temporary buffer for the incoming data
uint8_t *data = (uint8_t *) malloc(BUF_SIZE);
while (1) {
// Read data from the UART
int len = uart_read_bytes(ECHO_UART_PORT_NUM, data, BUF_SIZE, 20 / portTICK_RATE_MS);
if(len > 0) // // Write data back to the UART
uart_write_bytes(ECHO_UART_PORT_NUM, (const char *) data, BUF_SIZE);
vTaskDelay(20 / portTICK_PERIOD_MS); // every uart command gap 8ms
data[0] = 0;
}
free(data);
}
void app_main(void)
{
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );
#if CONFIG_PM_ENABLE
// Configure dynamic frequency scaling:
// maximum and minimum frequencies are set in sdkconfig,
// automatic light sleep is enabled if tickless idle support is enabled.
esp_pm_config_esp32c3_t pm_config = {
.max_freq_mhz = CONFIG_EXAMPLE_MAX_CPU_FREQ_MHZ,
.min_freq_mhz = CONFIG_EXAMPLE_MIN_CPU_FREQ_MHZ,
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE // note ,if enabled this (pw saving), uart will fail to work correctly
.light_sleep_enable = true
#endif
};
ESP_ERROR_CHECK( esp_pm_configure(&pm_config) );
#endif // CONFIG_PM_ENABLE
initialise_wifi();
xTaskCreate(uart_task, "uart_rev_task", ECHO_TASK_STACK_SIZE, NULL, 10, NULL); // configMAX_PRIORITIES - 0
wifi_power_save();
}
当在menuconfig中disable power saving后,串口才能接收正常。
请问,是否是在light sleep 模式下, C3的串口接收不能正常工作?
ESP32 C3 power_save例程下串口收发数据问题
Re: ESP32 C3 power_save例程下串口收发数据问题
power save 模式下,系统会根据任务的运行情况自动决定是否要进入 light sleep 状态,进入睡眠状态后有些管脚就无法保持正常的工作了。这边建议可以在进入睡眠前调用 gpio_hold_en 保持特定管脚的使能。另外在menuconfig → Component config → FreeRTOS 中将 Tick rate 配置为1000看看
Re: ESP32 C3 power_save例程下串口收发数据问题
Tick rate 配置为1000试了下,没有效果。我们是用的AI-think的开发板来测试的,接的是UART0. UART0/UART1引脚可配吗?能否配到能在light sleep下能正常工作的IO?
另外,请问下,是因为light sleep下CLK内部clock精度不高导致的串口接收问题,还是在light sleep下相关电路不工作呢?
另外,请问下,是因为light sleep下CLK内部clock精度不高导致的串口接收问题,还是在light sleep下相关电路不工作呢?
Who is online
Users browsing this forum: No registered users and 56 guests