Electronic – the UART TX interrupt for

microcontrolleruart

I know that the RX interrupt is obviously used to save polling, but why the TX one too?

Best Answer

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:

  1. Enable the TX interrupt.
  2. The user code starts transmission by sending only the first byte in the buffer.
  3. At the end of TX (of the first byte), an interrupt will be generated.
  4. In the TX ISR (Interrupt Service Routine), the code must send the next byte in the buffer and update the buffer index.
  5. At the end of this transmission, a new interrupt occurs, and so on, until the entire content of buffer is sent "automatically".
  6. Disable the TX interrupt.

The exact behavior depends on the microcontroller. That is a general description.