esp_err_t Core2ForAWS_Port_C_UART_Begin(uint32_t baud)
Configures the UART interface at the specified baud rate.
Definition: core2forAWS.c:549
Configures the UART interface at the specified baud rate.
This is a helper function to simplify building applications with UART. It preconfigures the UART communications with word length of 8 bits, no parity bit, 1 bit for the number of stop bits, and hardware flow control disabled. It sets the baud rate to the user defined value and starts reading from the UART channel 2 and storing data into the ring buffer of length UART_RX_BUF_SIZE.
Usage of the UART convenience methods provided in this BSP aims to simplify development at the expense of compatibility and performance. The configuration above may not be suitable for your application or attached peripheral. For more information about UART communications on the Core2 for AWS IoT EduKit using the ESP32 and how to create your own configuration, visit Espressif's official documentation.
- Note
- The ESP32 is a 3.3v device and requires 3.3v on the UART TX/RX lines. Higher voltages requires the use of a level shifter.
The example below sets the PORT_C_UART_TX_PIN (GPIO 14) pin mode to UART transmit, which will also set PORT_C_UART_RX_PIN (GPIO 13) to UART receiver, and sets the UART baud rate to 115200. It then starts two FreeRTOS tasks — one that transmits "Hello from AWS IoT
EduKit" every two seconds and the other receives the message. The receiver task outputs the number of bytes read from the buffer, the number of bytes that remains unread in the ring buffer, and the message.
To receive the messages transmitted on the same device, run a female-female jumper wire from Port C's TX pin to PORT C's RX pin.
Example:
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "driver/gpio.h"
#include "esp_log.h"
static const char *
TAG =
"UART_DEMO";
static void uart_tx_task(void *arg){
while (1) {
const char *message = "Hello from AWS IoT EduKit";
size_t message_len = strlen(message) + 1;
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
static void uart_rx_task(void *arg){
int rxBytes;
while (1) {
if (rxBytes > 0) {
ESP_LOGI(
TAG,
"Read %d bytes from UART. Received: '%s'", rxBytes, data);
}
vTaskDelay(pdMS_TO_TICKS(100));
}
free(data);
}
void app_main(void){
if (err == ESP_OK){
xTaskCreate(uart_rx_task, "uart_rx", 1024*2, NULL, configMAX_PRIORITIES, NULL);
xTaskCreate(uart_tx_task, "uart_tx", 1024*2, NULL, configMAX_PRIORITIES-1, NULL);
}
}
esp_err_t Core2ForAWS_Port_PinMode(gpio_num_t pin, pin_mode_t mode)
Sets the pin mode of the specified pin.
Definition: core2forAWS.c:431
void Core2ForAWS_Init(void)
Initializes the power chip with default values, enables battery charging, and initializes all enabled...
Definition: core2forAWS.c:32
int Core2ForAWS_Port_C_UART_Receive(uint8_t *message_buffer)
Reads messages in the UART2 receiver ring buffer.
Definition: core2forAWS.c:572
int Core2ForAWS_Port_C_UART_Send(const char *message, size_t len)
Sends a specified length of a user defined message over UART2.
Definition: core2forAWS.c:568
Functions to initialize and access Core2 for AWS IoT EduKit hardware features.
#define UART_RX_BUF_SIZE
The default UART RX ring buffer size.
Definition: core2forAWS.h:202
@ UART
Enable UART RX/TX mode. UART TX only available on Port C—GPIO 14 and UART RX is only available on Por...
Definition: core2forAWS.h:220
#define PORT_C_UART_TX_PIN
The UART transmission pin on expansion port C.
Definition: core2forAWS.h:159
#define TAG
Definition: i2c_device.c:10
- Parameters
-
| [in] | baud | The baud rate (bits per second) of the UART2 channel. |
- Returns
- esp_err_t. 0 or
ESP_OK if successful.