Checking for USART TX buffer empty

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

on an ATmega48 I want to check if the TX buffer is empty. My program is an autobaud-program which needs to change the baudrate settings. Checking UDR flag is not enough because the transmitter itself can still be busy. Checking TXC flag only works if it has been cleared before writing the UDR register - but unfotunately I do not have the transmitting function under my control.

Is there any chance to check the transmitter without relying on the TXC flag having been cleared before start of transmission?
My current workaround is to actively call a delay before changing the baudrate.

Thanks,
HJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not sure why you don't have control of the tx function, or why you can't change it the way you want, but I think these are your options-

always wait 2 frames

if udre0 set, wait 1 frame, else wait 2 frames

read pinTX until high for 1 frame length

change the tx function to the way you want to