Couldn't receive more than 120 bytes from UART interrupt

embeddedcoder
Posts: 2
Joined: Thu Jun 24, 2021 5:40 pm

Couldn't receive more than 120 bytes from UART interrupt

Postby embeddedcoder » Thu Jun 24, 2021 6:25 pm

Hello,

I am using ESP-IDF version 4.2. I am referring UART event example for the development of my project.

The example link is available below.
https://github.com/espressif/esp-idf/bl ... ple_main.c

As per my project requirement, I want to get 256 bytes from UART using xQueueReceive API and expecting 256 values from event.size. But it can receive only 120 bytes. When I was checking uart driver code, found that UART_FIFO_LEN is 128 bytes and UART_FULL_THRESH_DEFAULT is 120 bytes. Can we update this value?

Please help me to resolve this issue. I think multiple developers might facing the same issue. I am using UART_NUM_2 and GPIO21 and GPIO22 using for Tx and Rx pin respectively.

Regards,
Neel

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Couldn't receive more than 120 bytes from UART interrupt

Postby WiFive » Fri Jun 25, 2021 3:01 am

You can wait until more bytes are available before calling uart_read_bytes if you want to leave them in the RX buffer

embeddedcoder
Posts: 2
Joined: Thu Jun 24, 2021 5:40 pm

Re: Couldn't receive more than 120 bytes from UART interrupt

Postby embeddedcoder » Sat Jun 26, 2021 9:32 am

Hello friend,

This is a small but very useful solution. I could resolve the issue.

Please find below the code snippet and let me know if you have any suggestions.
  1. int ring_buff_len;
  2. int len;
  3. int timeout = 1000; // in msec
  4.  
  5. if(xQueueReceive(uart0_queue, (void * )&event, timeout / portTICK_RATE_MS)) {
  6.             bzero(dtmp, RD_BUF_SIZE);
  7.             switch(event.type) {
  8.                 //Event of UART receving data
  9.                 case UART_DATA:
  10.                     vTaskDelay(10 / portTICK_RATE_MS); // 10 msec sleep
  11.                     uart_get_buffered_data_len(EX_UART_NUM, (size_t *) &ring_buff_len);
  12.                     len = uart_read_bytes(EX_UART_NUM, dtmp, ring_buff_len, 0);
  13.                     break;
  14.            }
  15. }
Regards,
Neel

Who is online

Users browsing this forum: zelenecul and 138 guests