61 lines
1.7 KiB
C
61 lines
1.7 KiB
C
/* UART Echo Example
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
*/
|
|
#include <stdio.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "driver/uart.h"
|
|
#include "driver/gpio.h"
|
|
#include "sdkconfig.h"
|
|
#include "esp_log.h"
|
|
#include "uart.h"
|
|
|
|
/**
|
|
* This is an example which echos any data it receives on configured UART back to the sender,
|
|
* with hardware flow control turned off. It does not use UART driver event queue.
|
|
*
|
|
* - Port: configured UART
|
|
* - Receive (Rx) buffer: on
|
|
* - Transmit (Tx) buffer: off
|
|
* - Flow control: off
|
|
* - Event queue: off
|
|
* - Pin assignment: see defines below (See Kconfig)
|
|
*/
|
|
|
|
#define UART_TXD_PIN 14
|
|
#define UART_RXD_PIN 21
|
|
#define UART_RTS_PIN (-1)
|
|
#define UART_CTS_PIN 47
|
|
|
|
static const char *TAG = "UART2";
|
|
#define UART2_BAUD_RATE (115200)
|
|
#define UART_PORT_NUM (2)
|
|
#define BUF_SIZE (1024)
|
|
|
|
static void uart2_init(void)
|
|
{
|
|
uart_config_t uart_config = {
|
|
.baud_rate = UART2_BAUD_RATE,
|
|
.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(UART_PORT_NUM, BUF_SIZE * 2, 0, 0, NULL, intr_alloc_flags));
|
|
ESP_ERROR_CHECK(uart_param_config(UART_PORT_NUM, &uart_config));
|
|
ESP_ERROR_CHECK(uart_set_pin(UART_PORT_NUM, UART_TXD_PIN, UART_RXD_PIN, UART_RTS_PIN, UART_CTS_PIN));
|
|
}
|
|
|
|
|