ESP32学习(外设-UART)

/**
 * @brief UART configuration parameters for uart_param_config function
 */
typedef struct {
    int baud_rate;                      /*!< UART baud rate*/
    uart_word_length_t data_bits;       /*!< UART byte size*/
    uart_parity_t parity;               /*!< UART parity mode*/
    uart_stop_bits_t stop_bits;         /*!< UART stop bits*/
    uart_hw_flowcontrol_t flow_ctrl;    /*!< UART HW flow control mode (cts/rts)*/
    uint8_t rx_flow_ctrl_thresh;        /*!< UART HW RTS threshold*/
    union {
        uart_sclk_t source_clk;         /*!< UART source clock selection */
        bool use_ref_tick  __attribute__((deprecated)); /*!< Deprecated method to select ref tick clock source, set source_clk field instead */
    };
} uart_config_t;

ESP32总共有三个串口分别是UART_NUM0,UART_NUM1,UART_NUM2。串口0作为软件日志打印接口,其他串口可以为我们所用,比较灵活的是

所有串口的IO都可以*设置。上面结构体是串口配置结构体包含了串口的波特率,数据长度,奇偶检验,停止位,硬件流控制,还有时钟源。

esp_err_t uart_driver_install(uart_port_t uart_num, int rx_buffer_size, int tx_buffer_size, int queue_size, QueueHandle_t* uart_queue, int intr_alloc_flags);

串口驱动安装函数,参数有串口号,接收缓存大小,发送缓存大小,队列大小,队列句柄,中断标志位

uart_param_config(uart_port_t uart_num, const uart_config_t *uart_config);

串口参数配置函数,参数有串口号,以及串口参数配置结构体

uart_set_pin(uart_port_t uart_num, int tx_io_num, int rx_io_num, int rts_io_num, int cts_io_num)

串口引脚设置,可以设置串口4个引脚,一般设置TX RX即可。

int uart_read_bytes(uart_port_t uart_num, void *buf, uint32_t length, TickType_t ticks_to_wait)
int uart_write_bytes(uart_port_t uart_num, const void *src, size_t size)

第一个函数是读函数,参数有串口号,缓存地址,缓存长度,等待时间

第二个函数是写函数,也就是发送函数,参数有串口号,数据源首地址,发送数据长度

 

上一篇:ESP32学习(外设-GPIO)


下一篇:利用libcurl库实现post数据上传