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
Sends a specified length of a user defined message over UART2.
This is a helper function to simplify transmitting data over UART using the UART channel 2. This function does not return until all bytes are either transferred from the ring buffer to the hardware FIFO buffer, or already sent.
For more information about UART communications on the Core2 for AWS IoT EduKit using the ESP32, visit Espressif's official documentation.
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
esp_err_t Core2ForAWS_Port_C_UART_Begin(uint32_t baud)
Configures the UART interface at the specified baud rate.
Definition: core2forAWS.c:549
int Core2ForAWS_Port_C_UART_Receive(uint8_t *message_buffer)
Reads messages in the UART2 receiver ring buffer.
Definition: core2forAWS.c:572
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] | message | A pointer to the message to be transmitted over UART2. |
| [in] | len | The size of the message that you want to transmit. |
- Returns
- The 0 or greater number of bytes pushed to the TX FIFO. A return value -1 represents an error in one of the provided parameters.