Before the receive data can be read, the receive data ready flag must tell us that the data is ready to take. If the RXC (Receive Complete) flag in the UCSRA (USART Control and Status Register A) must be on, so a while (! (UCSRA (1 << RXC)) ); is used to wait for this flag to be set.
If there is more than one USAR/UART, then RXC is RXC0 and UCSRA is UCSR0A.
To receive the data when the data is ready, just assign a variable the value in the URD register:
unsigned char receiveData = UDR;
UDR is UDR0 if there is more than one USART/UART.
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.