Newbies in AVR are always confused by these two interrupts (I’m not an exception here). What’s the difference between these two interrupts ? After googling for a while, I found avrfreaks forum discussion about the difference between the two (here).
To summarize the discussion:
Timing Diagram of UDRE vs TXC
Example for transmitting 2 bytes, loading on UDRE
Action Flags Comment Startup UDRE=1 TXC=0 Load UDR UDRE=0 TXC=0 Software loads UDR UDR->SR UDRE=1 TXC=0 Hardware loads Shift Register LOAD UDR UDRE=0 TXC=0 Software loads UDR after first byte finishes shifting UDR->SR UDRE=1 TXC=0 Hardware Loads Shift Register after second byte finishes shifting nothing UDRE=1 TXC=1
UDRE is normally used. TXC is normally not used, except for these situations:
- Half duplex communication, such as RS485: where the application needs to know whether all of the bits has been transmitted or not, before releasing the bus.
- Power saving mode: where the application needs to know whether the transmission has done, before switching to deeper power saving mode (where the UART peripheral is not available anymore).