uart_read_bytes hangs after event

danpf1
Posts: 13
Joined: Mon May 10, 2021 2:59 pm

uart_read_bytes hangs after event

Postby danpf1 » Fri Dec 15, 2023 2:10 pm

I'm using the ESP IDF UART driver. I receive an event with event.size=9 bytes (for example). Then I try to uart_read_bytes for 9 bytes and the code still takes 1000ms sometimes. Is this expected? I would assume that once the event is there and has the number of bytes, those bytes would be ready in the FIFO immediately. Is that not a correct assumption?

Relevant code is:

Code: Select all

if (xQueueReceive(uart_queue, (void *)&event, (TickType_t)portMAX_DELAY)) {
  switch (event.type) {
        // Event of UART receiving data      
        case UART_DATA:
          // Sometimes this takes > 1sec to read 9 bytes. 
          bytesRead = uart_read_bytes(SPROC_UART_PORT_NUM, readBuffer, event.size, portMAX_DELAY);         
          break;

MicroController
Posts: 1605
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: uart_read_bytes hangs after event

Postby MicroController » Fri Dec 15, 2023 9:27 pm

Your assumption is (mostly) correct.
However, the behavior you observe not being consistent with the assumption's implications indicates there may be some kind of other problem.

Check that a) you're reading from the right UART and b) if there is any other code which would consume (more than event.size) bytes from the FIFO resulting in less than event.size bytes remaining, causing uart_read_bytes to block unexpectedly.

danpf1
Posts: 13
Joined: Mon May 10, 2021 2:59 pm

Re: uart_read_bytes hangs after event

Postby danpf1 » Fri Dec 15, 2023 9:34 pm

Thanks! I don't see any other code that would be grabbing the bytes. I added code to get the size of the available bytes inside the event before I attempt to uart_read_bytes.

Code: Select all

          uart_get_buffered_data_len(UART_PORT_NUM, &bytesReady);
And bytesReady is 1 byte less than the event.size. I'm not sure why this would be. I don't seem to be losing bytes anywhere.

I appreciate your help!
Dan

Who is online

Users browsing this forum: Google [Bot] and 70 guests