Uart reading issue
Posted: Mon Dec 11, 2017 6:16 am
Hello,
I'm having a problem with reading from the UART from the ESP-WROOM32.
The problem is, that the recieved data does not come in the right order, after the rx buffer(ringbuffer?) is full, for the first time. I send a continious stream, whith a 10 Bit pattern (0x02, counter(0x00-0xFF), 0x00, 0x02, 0x04, 0x06, 0x10, 0x11, 0x12, 0x13). The recieved data looks something like this, after the rx buffer is full(Note: I used new lines to gourp parts of the stream, which come in the correct order):
02df0002040610111213, 02e00002040610111213, 02e10002040610111213, 02e20002040610111213, 02e30002040610111213, 02e40002040610111213, 02e50002040610111213,
0002040610111213,
02da0002040610111213,
02db00020406101110111213,
02e90002040610111213, 02ea0002040610111213, 02eb0002040610111213, 02ec0002040610111213, 02ed0002040610111213, 02ee0002040610111213, 02ef0002040610111213, 02f00002040610111213, 02f10002040610111213,
0002040610111213,
02e60002040610111213, 02e700020406101110111213,
02f50002040610111213, 02f60002040610111213, 02f70002040610111213, 02f80002040610111213, 02f90002040610111213, 02fa0002040610111213, 02fb0002040610111213, 02fc0002040610111213, 02fd0002040610111213
The odd thing is, that if I flush the rx buffer (with uart_flush) the error still occures. Infact if I did read less than, the rx buffer holds, and i call uart_flush, the error will occure, even if the rx bufferwas not a single time full.
The code I use is pretty simple and mostly copied from the examples:
I have found a few other reports of the same/similar problems, but without a soulution, which worked for me:
viewtopic.php?t=2804
Sorry for the bad english and probalbly stupid question.
Regards
I'm having a problem with reading from the UART from the ESP-WROOM32.
The problem is, that the recieved data does not come in the right order, after the rx buffer(ringbuffer?) is full, for the first time. I send a continious stream, whith a 10 Bit pattern (0x02, counter(0x00-0xFF), 0x00, 0x02, 0x04, 0x06, 0x10, 0x11, 0x12, 0x13). The recieved data looks something like this, after the rx buffer is full(Note: I used new lines to gourp parts of the stream, which come in the correct order):
02df0002040610111213, 02e00002040610111213, 02e10002040610111213, 02e20002040610111213, 02e30002040610111213, 02e40002040610111213, 02e50002040610111213,
0002040610111213,
02da0002040610111213,
02db00020406101110111213,
02e90002040610111213, 02ea0002040610111213, 02eb0002040610111213, 02ec0002040610111213, 02ed0002040610111213, 02ee0002040610111213, 02ef0002040610111213, 02f00002040610111213, 02f10002040610111213,
0002040610111213,
02e60002040610111213, 02e700020406101110111213,
02f50002040610111213, 02f60002040610111213, 02f70002040610111213, 02f80002040610111213, 02f90002040610111213, 02fa0002040610111213, 02fb0002040610111213, 02fc0002040610111213, 02fd0002040610111213
The odd thing is, that if I flush the rx buffer (with uart_flush) the error still occures. Infact if I did read less than, the rx buffer holds, and i call uart_flush, the error will occure, even if the rx bufferwas not a single time full.
The code I use is pretty simple and mostly copied from the examples:
Code: Select all
const uint32_t buffer_len = 256;
static const uart_port_t UART_PORT_NR = UART_NUM_1; //tried with UART1 and UART2
Init()
{
uart_config_t uart_config = uart_config_t
{
.baud_rate = 5000000, //5MHz
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_EVEN,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.rx_flow_ctrl_thresh = 40,
.use_ref_tick = false,
};
//Configure UART1 parameters
uart_param_config(UART_PORT_NR, &uart_config);
//Install UART driver, no queue, no TX buffer, buffer_len * 4 for debug -> delay reading error
uart_driver_install(UART_PORT_NR, buffer_len * 4, 0, 0, NULL, 0);
//Set UART pins
uart_set_pin(UART_PORT_NR, 17, 16, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
}
Read(uint8_t* buffer)
{
return uart_read_bytes(UART_PORT_NR, &buffer[0], buffer_len, 5000);
}
viewtopic.php?t=2804
Sorry for the bad english and probalbly stupid question.
Regards