Programming: Transmitting Data Using the UART/USART

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.
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.