ESP32-WROOM-32 串口2的问题

nick.yao
Posts: 14
Joined: Mon May 13, 2019 11:23 am

ESP32-WROOM-32 串口2的问题

Postby nick.yao » Mon May 27, 2019 7:53 am

我想使用ESP32-WROOM-32的串口2,使用如下初始化代码(在ble_spp_server.c例程中将UART_NUM0 -> UART_NUM2),发现串口2既收不到数据,也发不出来数据,请问使用串口2有什么要注意的吗,还是ESP32-WROOM-32串口2不能用?
static void spp_uart_init(void)
{
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,
};

//Set UART parameters
uart_param_config(UART_NUM_2, &uart_config);
//Set UART pins
uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
//Install UART driver, and get the queue.
uart_driver_install(UART_NUM_2, 4096, 8192, 10,&spp_uart_queue,0);
xTaskCreate(uart_task, "uTask", 2048, (void*)USE_UART, 8, NULL);
}

ESP_houwenxiang
Posts: 118
Joined: Tue Jun 26, 2018 3:09 am

Re: ESP32-WROOM-32 串口2的问题

Postby ESP_houwenxiang » Wed Jun 19, 2019 11:52 am

Hi, 这是因为你串口 2 的 pin 脚没有初始化. 这个代码默认使用的是 UART0, UART0 是默认 log 打印 串口, pin 脚在系统初始化的时候已经配置好, 在这个 example 里面可以不再配置, 但是 UART2 的 pin 脚没有配置过, 需要用 uart_set_pin 指定 pin 脚.
wookooho

xielingy
Posts: 14
Joined: Tue Oct 27, 2020 3:47 am

Re: ESP32-WROOM-32 串口2的问题

Postby xielingy » Tue Oct 27, 2020 3:54 am

//Set UART pins
uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
这段代码不是设置了ping脚吗?

Who is online

Users browsing this forum: No registered users and 58 guests