Programming: Receiving Data with the UART/USART Communication
Share
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.