UART event size larger than bytes sent
Posted: 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:
Receiver reading is done by event:
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.
The transmitter writes 3 bytes to the uart without using any buffer:
- ESP_LOGI(TAG, "Write %d bytes: %d, %d, %d", uart_write_bytes(UART_PORT_NUM, rgb, 3), rgb[0], rgb[1], rgb[2]);
- case UART_DATA:
- uart_get_buffered_data_len(EX_UART_NUM, &buffered_size);
- ESP_LOGI(TAG, "[UART DATA]: %d, size: %d", event.size, buffered_size);
- uart_read_bytes(EX_UART_NUM, dtmp, event.size, portMAX_DELAY);
- blink_led(led_strip, 1, dtmp);
- uart_flush_input(EX_UART_NUM);
- break;
In addition I used a signal analyzer and saw only three bytes transmitted.