I know that the RX interrupt is obviously used to save polling, but why the TX one too?
Sign up
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
|
|
The main goal of the TX interrupt (really an END OF TX) is to send the content of a buffer (multiple bytes) automatically. When implemented in a proper way:
The exact behavior depends on the microcontroller. That is a general description. |
|||||
|
|
The TX interrupt is mainly for longer datagrams. You can initiate the transfer for a buffer of known length (bytecount). Now you can push your buffer pointer as often as there are bytes to send, when the TX interrupt occurs. This ensures the "as quick as possible" transfer of your buffer, without the need to poll any "TransferComplete"-Flag/Statusbit. |
|||
|
|
|
The TX interrupt fires when there is space in the transmit buffer. For devices that don't have a transmit buffer (i.e. where you write one byte, which is transferred immediately), the interrupt is asserted when the transmit register can be written with the next byte. For devices with a buffer, the interrupt is asserted at an implementation-defined time. For some, it is when the buffer is half empty, for some it is when transmission of the last byte has started and the buffer is completely empty. |
|||
|
|
|
Some UARTS have an internal buffer that is larger than one, the 16xxx series for one. The procedure here was
This decreases the CPU load by offloading some processing to the UART thus enabling slower CPU's to keep up and service other task instead of getting interrupted all the time. |
|||
|
|
|
Another use case is when you connect the UART to another communication interface like RS485. The controller has to release the bus driver as soon as the last bit has been shifted out of the TX buffer. This is easy to handle in the TX interrupt, but would be cumbersome to implement without, since you would have to wait an exact time after writing the last byte to the output buffer which would also vary with baud rate. |
|||||||||||||
|