To send data on the TX pin of the microcontroller, the transmitter must not be busy with another transmission of data. The UDRE (USART Data Register Empty) is a flag that tells us when the transmitter is ready.
To wait until the UDRE flag is set (transmitter is ready):
If more than one USART is available on the AVR:
while (! (UCSR0A & (1 << UDRE0)) );
If only one USART is available on the AVR:
while (! (UCSRA & (1 << UDRE)) );
To send the data, just assign the data to the UDR register.
If more than one USART is available on the AVR:
UDR0 = 0b11110000;
If only one USART is available on the AVR:
UDR = 0b11110000;
The 0b11110000is just an example of data. Data can be in other forms, like a character, decimal number, hexadecimal number, etc.
Comments and Additional Information
Have some code to share? Or additional information? Respond here:
You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.