UART event size larger than bytes sent

Karlheinz
Posts: 3
Joined: Sat Sep 07, 2024 1:24 pm

UART event size larger than bytes sent

Postby Karlheinz » Sat Oct 05, 2024 8:30 am

I’m new to esp-idf api’s and try currently to learn the uart api. I played with the examples and get a working environment. I’m using two esp32 devkits connected by uart. One as a transmitter and on as receiver. The transmitter blinks a led in the sequence rgb and transmit the current color to the receiver. Then the receiver turns on its own led in the transmitted color. The receiver is based on the event example code. Works fine, without a large delay.

The transmitter writes 3 bytes to the uart without using any buffer:
  1. ESP_LOGI(TAG, "Write %d bytes: %d, %d, %d", uart_write_bytes(UART_PORT_NUM, rgb, 3), rgb[0], rgb[1], rgb[2]);
Receiver reading is done by event:
  1.                 case UART_DATA:
  2.                     uart_get_buffered_data_len(EX_UART_NUM, &buffered_size);
  3.                     ESP_LOGI(TAG, "[UART DATA]: %d, size: %d", event.size, buffered_size);
  4.                     uart_read_bytes(EX_UART_NUM, dtmp, event.size, portMAX_DELAY);
  5.                     blink_led(led_strip, 1, dtmp);
  6.                     uart_flush_input(EX_UART_NUM);
  7.                     break;
Of course I received the data which I sent (rgb[0] = dtmp[0], … ,rgb[3] = dtmp[3]). But “bufferd_size” is equal to “event.size” and booth has the value 64. I would expect 3 because I sent only 3 bytes. Could anyone give me an explanation of this behavior?

In addition I used a signal analyzer and saw only three bytes transmitted.

mikemoy
Posts: 627
Joined: Fri Jan 12, 2018 9:10 pm

Re: UART event size larger than bytes sent

Postby mikemoy » Sun Oct 06, 2024 10:48 pm

how did you define buffered_size ?

Who is online

Users browsing this forum: No registered users and 7 guests