UART Receiving Random Data
Posted: Tue Aug 27, 2019 5:13 am
Hi,
I am writing an application on esp32 dev board where data will be received on Uart, which will be shared to the further tasks.
Wrote driver for UART1 using IO17 for TXD and IO16 for RXD in dev board.
Below is the task for uart for receiving data :
static void rx_task()
{
static const char *RX_TASK_TAG = "RX_TASK";
ESP_LOGI(RX_TASK_TAG,"rx task started \n");
esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO);
uint8_t* data = (uint8_t*) malloc(RX_BUF_SIZE+1);
while (1)
{
const int rxBytes = uart_read_bytes(UART_NUM_1, data, (RX_BUF_SIZE-1), 1000 / portTICK_RATE_MS);
if(rxBytes > 0)
{
data[rxBytes] = 0;
if(rfid_queue != 0)
{
xQueueSendToBack(rfid_queue, data, ( TickType_t ) 10 );
ESP_LOG_BUFFER_HEXDUMP("Http Queue", data, rxBytes, ESP_LOG_INFO);
}
ESP_LOGI(RX_TASK_TAG, "Read %d bytes: '%s'", rxBytes, data);
}
}
free(data);
}
My problem is that uart is receiving some random data continuously from the external device attached through uart. Also, I have connected that device to pc, it was not receiving any such data as esp32 was. Could you suggest something on this ?
Thanks
Ritu.
I am writing an application on esp32 dev board where data will be received on Uart, which will be shared to the further tasks.
Wrote driver for UART1 using IO17 for TXD and IO16 for RXD in dev board.
Below is the task for uart for receiving data :
static void rx_task()
{
static const char *RX_TASK_TAG = "RX_TASK";
ESP_LOGI(RX_TASK_TAG,"rx task started \n");
esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO);
uint8_t* data = (uint8_t*) malloc(RX_BUF_SIZE+1);
while (1)
{
const int rxBytes = uart_read_bytes(UART_NUM_1, data, (RX_BUF_SIZE-1), 1000 / portTICK_RATE_MS);
if(rxBytes > 0)
{
data[rxBytes] = 0;
if(rfid_queue != 0)
{
xQueueSendToBack(rfid_queue, data, ( TickType_t ) 10 );
ESP_LOG_BUFFER_HEXDUMP("Http Queue", data, rxBytes, ESP_LOG_INFO);
}
ESP_LOGI(RX_TASK_TAG, "Read %d bytes: '%s'", rxBytes, data);
}
}
free(data);
}
My problem is that uart is receiving some random data continuously from the external device attached through uart. Also, I have connected that device to pc, it was not receiving any such data as esp32 was. Could you suggest something on this ?
Thanks
Ritu.