UART receive failure after 120 bytes

Posts: 18
Joined: Mon Aug 07, 2017 7:53 am

UART receive failure after 120 bytes

Postby mpulis » Thu Jun 14, 2018 7:09 am


I've set up a UART communications channel using UART 1 on the ESP-WROOM32.

I've set up a thread running which constantly checks fro any UART events from the xQueueReceive() function. If the packet length being received is less or equal to 120 bytes, then no problem is encountered.

If the length of the packet being received exceeds 120 bytes, then I've met some unexpected behavior. The first part of the received packet is truncated at 120 bytes (which I've been led to believe is a hardware-defined limitation) but I'm not always receiving the rest of the message.

So, for example, if I'm being sent a 150 byte packet, I expect to receive a packet of 120 and a packet of 30 bytes. Instead, the second packet is arriving arbitrarily with some missing bytes, most of the times being truncated to 8 bytes. I've attached an example of such below, with 2 packets (120+30) being received correctly while the 3rd is cut off at the 8-byte mark.

My settings for the UART channel are as follows:
Data Bits: 8; Stop Bits: 1; Parity: Even; No HW Flow Ctrl, RX_flow_control_thresh: default

I've tried this out at different baud rates (38400 and 19200) but the same problem persists.

A posted snippet of my code can be found below. I've only copied what I believe to be the relevant section.

Code: Select all

void serialTask(void *pvParameters)
	int uart_num = (int) pvParameters;
	uart_event_t event;
	size_t buffered_size;
	uint8_t data=0;
	uint32_t datalen;
	uint8_t i;
	datalen = 0;
	uart_get_buffered_data_len(UARTNUM, &datalen);
	size_t size = 1024;			
   	uint8_t* dtmp = (uint8_t*)malloc(size);
	for (;;) 
	    //Waiting for UART event.
		if (xQueueReceive(UARTqueue, (void *)&event, (portTickType)portMAX_DELAY))
			switch (event.type) 
				case UART_DATA:
					ESP_LOGE(TAG, "serialTask: uart data break\n");
					int len = uart_read_bytes(uart_num, dtmp, event.size, 10);
             				ESP_LOGI(TAG, "uart read: %d", len);
Serial.PNG (19.84 KiB) Viewed 372 times

Return to “General Discussion”

Who is online

Users browsing this forum: Bing [Bot] and 20 guests