UART
UART
Postby eriksl » Tue Jun 09, 2015 1:47 am
Can someone please help me with the exact operation of the UART?
I am currently making something that needs the UART to be working interrupt/event driven. I am using the timeout ("RX_TOUT") interrupt to signal that the fifo can be read and fifo empty ("TXFIFO_EMPTY"). I set a threshold for the tout interrupt, I enable the tout interrupt, the fifo interrupt is enabled whenever there is data to be sent and then disabled.
All works, so I must be doing something right.
The problem is that if I send data to the uart quickly, only the first 126 bytes can be fetched. It doesn't matter what baudrate is used, so it's not a "too slow" issue. Apparently the fifo's are 128 bytes, so it probably has to do with that. But I don't understand. For the reception of data from uart I think it works like this:
*hardware*
1 receive fifo is empty
2 first byte of some data is received and put into the receive fifo
3 if fifo is not empty for "timeout threshold" time, generate timeout interrupt
4 goto 1
*software*
1 timeout interrupt triggered, callback is called
2 callback reads ALL data from the fifo until it's empty again
3 interrupt is cleared and interrupt is enabled again
I don't understand why the fifo apparently isn't completely emptied in time by my software. Apparently the fifo gets overrun. The callback should be called after just a few bytes in the fifo, that should be plenty of time to fetch all bytes from the fifo.
Maybe I don't understand the #defines correctly:
- UART_RX_TOUT_EN: enable receive fifo "timeout", if fifo is not empty for "threshold" uart byte times, raise an interrupt so the fifo can be emptied
- UART_RX_TOUT_THRHD: the threshold; I've used 2, 32, 64 and 120, it doesn't matter
- UART_RXFIFO_TOUT_INT_ENA: enable the interrupt
- UART_RXFIFO_FULL_THRHD: the threshold for the fifo being "full", there is no "ENABLE" function for this?
- UART_RXFIFO_FULL_INT_ENA: enable the interrupt (I am not using this)
What is exactly meant with the "threshold" values? For the "timeout", does it mean, smaller value is interrupt quicker (after lesser bytes) or the other way around? For the "full" threshold, is it actually used when the interrupt is not enabled? If so, what is it's meaning, is it used to the set the actual fifo size?
Last but not least, why is there no include file with the register definitions in the sdk?
Thanks.
I am currently making something that needs the UART to be working interrupt/event driven. I am using the timeout ("RX_TOUT") interrupt to signal that the fifo can be read and fifo empty ("TXFIFO_EMPTY"). I set a threshold for the tout interrupt, I enable the tout interrupt, the fifo interrupt is enabled whenever there is data to be sent and then disabled.
All works, so I must be doing something right.
The problem is that if I send data to the uart quickly, only the first 126 bytes can be fetched. It doesn't matter what baudrate is used, so it's not a "too slow" issue. Apparently the fifo's are 128 bytes, so it probably has to do with that. But I don't understand. For the reception of data from uart I think it works like this:
*hardware*
1 receive fifo is empty
2 first byte of some data is received and put into the receive fifo
3 if fifo is not empty for "timeout threshold" time, generate timeout interrupt
4 goto 1
*software*
1 timeout interrupt triggered, callback is called
2 callback reads ALL data from the fifo until it's empty again
3 interrupt is cleared and interrupt is enabled again
I don't understand why the fifo apparently isn't completely emptied in time by my software. Apparently the fifo gets overrun. The callback should be called after just a few bytes in the fifo, that should be plenty of time to fetch all bytes from the fifo.
Maybe I don't understand the #defines correctly:
- UART_RX_TOUT_EN: enable receive fifo "timeout", if fifo is not empty for "threshold" uart byte times, raise an interrupt so the fifo can be emptied
- UART_RX_TOUT_THRHD: the threshold; I've used 2, 32, 64 and 120, it doesn't matter
- UART_RXFIFO_TOUT_INT_ENA: enable the interrupt
- UART_RXFIFO_FULL_THRHD: the threshold for the fifo being "full", there is no "ENABLE" function for this?
- UART_RXFIFO_FULL_INT_ENA: enable the interrupt (I am not using this)
What is exactly meant with the "threshold" values? For the "timeout", does it mean, smaller value is interrupt quicker (after lesser bytes) or the other way around? For the "full" threshold, is it actually used when the interrupt is not enabled? If so, what is it's meaning, is it used to the set the actual fifo size?
Last but not least, why is there no include file with the register definitions in the sdk?
Thanks.
-
Joanna Hoo
- Posts: 2
- Joined: Mon Nov 24, 2014 10:11 am
Re: UART
Postby Joanna Hoo » Wed Jun 10, 2015 6:37 pm
Hi,
Please refer to viewtopic.php?f=21&t=414 and find the document named [8E-ESP8266__Interface_UART__EN_v0.2].
Hope this can help you.
Please refer to viewtopic.php?f=21&t=414 and find the document named [8E-ESP8266__Interface_UART__EN_v0.2].
Hope this can help you.
Re: UART
Postby eriksl » Wed Jun 10, 2015 9:19 pm
It helps a bit, but the wording isn't very informative. I googled about generic UART traits and already learned a lot, apparently the "uart receive fifo timeout" feature is common on buffered UART's. The thing I didn't realise earlier on, is that you need to enable and use both interrupts: uart timeout and uart full (with an appropriate threshold). If you leave out the second, an overflow will occur when data keeps on coming in beyond the 128 byte fifo, because there will be no "timeout". In that case you need to rely on the "fifo full" interrupt.
Who is online
Users browsing this forum: No registered users and 2 guests
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.