UART rx length problem
Posted: Tue Apr 14, 2020 1:15 pm
Hi,
I am trying to understand how to use uart_get_buffered_data_len().
My test code:
If I use the "Get RX length" part, the code get stuck forever in the while loop, but if I comment it out it works, ie there will be one rx byte read in the "Get RX byte" part.
Do I need to use uart_get_buffered_data_len() in some special way?
I am trying to understand how to use uart_get_buffered_data_len().
My test code:
- uint8_t data[10];
- int len;
- const int uart_buffer_size = (1024 * 2);
- QueueHandle_t uart_queue;
- uart_config_t uart_config =
- {
- .baud_rate = 9600,
- .data_bits = UART_DATA_8_BITS,
- .parity = UART_PARITY_DISABLE,
- .stop_bits = UART_STOP_BITS_1,
- .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
- .rx_flow_ctrl_thresh = 122,
- };
- ESP_ERROR_CHECK(uart_param_config(UART2, &uart_config));
- ESP_ERROR_CHECK(uart_set_pin(UART2, 17, 16, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
- ESP_ERROR_CHECK(uart_driver_install(UART2, uart_buffer_size, 0, 10, &uart_queue, 0));
- [
- ... code, which send TX bytes. RX and TX pins connected together.
- ]
- // Get RX length
- len = 0;
- while (len == 0)
- {
- ESP_ERROR_CHECK(uart_get_buffered_data_len(UART2, (size_t*)&len));
- }
- // Get RX byte
- len = 0;
- while (length != 1)
- {
- len = uart_read_bytes(UART2, data, 1, 1);
- }
Do I need to use uart_get_buffered_data_len() in some special way?