Hi all -
I'm trying to get the ESP32 to read input from a UART. I began with the uart_events example from the IDF.
When I send a message to the ESP32, it reads about 65 bytes (the exact number varies a bit) and the read returns. I then get subsequent read events of 5 to 9 bytes each, but the data is not what I sent (appears to be garbage). I'm also getting a "uart rx break" event.
The docs are a bit sparse in this area...what is a UART break? Does this seem like a configuration issue? I find it hard to believe the ESP32 UART can't swallow a message of a few hundred bytes without incident, so I'm inclined to think it's something I'm doing wrong.
Thanks...
UART I/O issue
Re: UART I/O issue
A little more information: I modified my event handler (for experimentation) as follows:
I get this output:
Code: Select all
if (xQueueReceive(m_uartQueue, (void *) &event, (portTickType)portMAX_DELAY))
{
bzero(ioBuff, BUF_SIZE);
ESP_LOGI(TAG, "uart[%d] event:", CD_UART_NBR);
switch(event.type)
{
// Event of UART receving data; need to handle fast.
case UART_DATA:
uart_get_buffered_data_len(CD_UART_NBR, &bufSize);
ESP_LOGI(TAG, "%d bytes in SIO input buffer.", bufSize);
// nbrBytesRead = (size_t) uart_read_bytes(CD_UART_NBR, ioBuff, bufSize, portMAX_DELAY);
nbrBytesRead = (size_t) uart_read_bytes(CD_UART_NBR, ioBuff, 64, 0);
ESP_LOGI(TAG, "%d bytes read in from SIO input buffer.", nbrBytesRead);
uart_get_buffered_data_len(CD_UART_NBR, &bufSize);
nbrBytesRead = (size_t) uart_read_bytes(CD_UART_NBR, ioBuff, bufSize, 0);
ESP_LOGI(TAG, "%d bytes in SIO input buffer.", bufSize);
for (unsigned int i = 0; i < bufSize; ++i)
{
ESP_LOGI(TAG, "byte %d is %02x.", i, ioBuff[i]);
}
The message being sent is 85 bytes, all printable ASCII characters. I'm at a loss for why the UART can't read that in one piece.I (104433) UART: uart[1] event:
I (104433) UART: 65 bytes in SIO input buffer.
I (104433) UART: 64 bytes read in from SIO input buffer.
I (104443) UART: 3 bytes in SIO input buffer.
I (104443) UART: byte 0 is 00.
I (104453) UART: byte 1 is 00.
I (104453) UART: byte 2 is 00.
Re: UART I/O issue
Would it be possible to post the complete fragment of logic showing all the UART processing including queue creation and other parts? Maybe post that as a GIT GIST fragment or some other link?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: UART I/O issue
Hi, Neil - I hope I did this correctly (never used GISTs before):
https://gist.github.com/mzimmers/9ed4ea ... 17dba748d3
Thanks...
https://gist.github.com/mzimmers/9ed4ea ... 17dba748d3
Thanks...
Re: UART I/O issue
I'm making progress on this, but I now seem to be running into a hard limit of 120 bytes for a single read operation.
I'm using the uart event queue as demonstrated in the uart_events example, and my reads always stop at 120 bytes. If the message is in fact longer, a second UART_DATA event is delivered, and the rest of the message comes through at this time.
Does anyone know why this is happening? I suppose it could be either a queue limitation, which seems doubtful, or a buffer size limitation in the UART driver.
Here's some of the relevant code:
bufSize and nbrBytesRead both return as 120, though the input is larger.
Thanks...
I'm using the uart event queue as demonstrated in the uart_events example, and my reads always stop at 120 bytes. If the message is in fact longer, a second UART_DATA event is delivered, and the rest of the message comes through at this time.
Does anyone know why this is happening? I suppose it could be either a queue limitation, which seems doubtful, or a buffer size limitation in the UART driver.
Here's some of the relevant code:
Code: Select all
err = uart_driver_install(CD_UART_NBR, BUF_SIZE, 0, 20, &m_uartQueue, 0);
if (xQueueReceive(m_uartQueue, (void *) &event, (portTickType)portMAX_DELAY))
{
unsigned i = uxQueueMessagesWaiting(m_uartQueue);
switch(event.type)
{
// Event of UART receving data; need to handle fast.
case UART_DATA:
uart_get_buffered_data_len(CD_UART_NBR, &bufSize);
nbrBytesRead = (size_t) uart_read_bytes(CD_UART_NBR, ioBuff, bufSize, portMAX_DELAY);
Thanks...
Who is online
Users browsing this forum: No registered users and 142 guests