ESP32 ESP-IDF UART使用模式检测中断报告事件实现 收发数据

官网esp-idf参考代码:D:\esp-idf\examples\peripherals\uart\uart_events

开发环境:Source Insight  + esp-idf 

esp32模块:ESP32-WROOM-32

实现功能:使用ESP32的3个UART全部实现收发,要求3个UART同时接收每条数据长度25间隔时间为100ms。

 

初期看了一下官网的uart例程代码,官网推荐使用模式检测。自己也可以使用直接在ISR中处理中断。

#include 
#include 
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "freertos/queue.h"
#include "driver/gpio.h"


#define BUF_SIZE				(1024)
#define RD_BUF_SIZE 			(BUF_SIZE)


uart_event_t    uart0_event, uart1_event, uart2_event;
QueueHandle_t	uart0_queue, uart1_queue, uart2_queue;


void uart_event_handle(uart_port_t uart_num, QueueHandle_t queue, uart_event_t *event);





void app_main(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
	};
    
	uart_param_config(UART_NUM_0, &uart_config);
	uart_param_config(UART_NUM_1, &uart_config);
	uart_param_config(UART_NUM_2, &uart_config);

	uart_set_pin(UART_NUM_0, GPIO_NUM_1,  GPIO_NUM_3,  UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
	uart_set_pin(UART_NUM_1, GPIO_NUM_18, GPIO_NUM_19, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
	uart_set_pin(UART_NUM_2, GPIO_NUM_16, GPIO_NUM_17, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);

	uart_driver_install(UART_NUM_0, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
	uart_driver_install(UART_NUM_1, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart1_queue, 0);
	uart_driver_install(UART_NUM_2, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart2_queue, 0);

	uart_pattern_queue_reset(UART_NUM_0, 20);
	uart_pattern_queu

你可能感兴趣的:(ESP32)