#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/uart.h"
#include "rom/ets_sys.h"
#define UART_NUM UART_NUM_0
#define BUF_SIZE (1024)
void uart_init() {
const 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, &uart_config);
uart_driver_install(UART_NUM, BUF_SIZE, 0, 0, NULL, 0);
}
void app_main() {
uart_init();
uint8_t data[BUF_SIZE];
while (1) {
int len = uart_read_bytes(UART_NUM, data, BUF_SIZE - 1, 20 / portTICK_PERIOD_MS);
if (len > 0) {
data[len] = '\0';
// Verifica se é um número ou texto
if (data[0] >= '0' && data[0] <= '9') {
// Se for número, imprime o valor recebido
printf("Recebido: %s (número)\n", data);
} else if ((data[0] >= 'A' && data[0] <= 'Z') || (data[0] >= 'a' && data[0] <= 'z')) {
// Se for letra, imprime o valor recebido
printf("Recebido: %s (texto)\n", data);
} else {
// Se for outro caractere, imprime o valor recebido
printf("Recebido: %s (outro)\n", data);
}
}
}
}