What is the problem? The received data from uart pins of esp32 is different from normal putty communication.
What am I trying to do? what is my approach?
I am sending some data through UART (pins 33, 32) to a device.
Once I send command in putty, the responses that I get is either "ok" or "err" (based on the validity of the command), but the below code in esp32 is getting either "oC", "oJ", "erR" or nothing.
The code that I am using:
Code: Select all
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/uart.h"
#include "esp_log.h"
#define READ_BUF_SIZE (1024)
static const char *TAG = "esp";
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_port_t uart_1_init()
{
uart_port_t uart_num_1 = UART_NUM_1;
ESP_ERROR_CHECK(uart_param_config(uart_num_1, &uart_config));
uart_set_pin(uart_num_1, 33, 32, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
ESP_ERROR_CHECK(uart_driver_install(uart_num_1, READ_BUF_SIZE * 2, 0, 0, NULL, 0));
return uart_num_1;
}
static char data_rec[1024];
void app_main(void)
{
uart_port_t uart_num_1 = uart_1_init();
while (1)
{
uart_write_bytes(uart_num_1, "command", strlen((const char *)"command"));
uart_read_bytes(uart_num_1, data_rec, 1024, 100 / portTICK_PERIOD_MS);
printf("Data: %s \n", data_rec);
}
}
Code: Select all
cpu_start: Starting scheduler on P
Thanks