ESP_Gargamel wrote: ↑Thu Aug 26, 2021 2:25 am
你参看一下示例 examples/peripherals/uart/uart_echo
已解决,不是简单的串口应用。
LOG 串口在平时只是用于输出,UART0只有TX在工作,之前请教的是如何让RX也工作起来。
先显性的初始化一下UART0
Code: Select all
void DebugUartInit(void)
{
uart_config_t uartConfig =
{
.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,
};
uart_driver_install(UART_NUM_0, BUF_SIZE, BUF_SIZE*2, 0, NULL, 0);
uart_param_config(UART_NUM_0, &uartConfig);
uart_set_pin(UART_NUM_0, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
}
然后使用时候
Code: Select all
sReceiveData.size = 0;
sReceiveData.size = uart_read_bytes(UART_NUM_0, sReceiveData.data, BUF_SIZE, 100);
if(sReceiveData.size)
{
ESP_LOGI(TAG, "Size: %d", sReceiveData.size);
}
即可获取到数据