Complete the code to read a byte from UART data register.
uint8_t received_byte = [1];The UART data register (UART_DR) holds the received byte. Reading from it gets the byte.
Complete the code to wait until a byte is received (RXNE flag set).
while (!([1] & (1 << RXNE_FLAG))) {}
The RXNE (Receive Not Empty) flag is in the UART status register (UART_SR). We wait until this flag is set.
Fix the error in the code to correctly receive a byte over UART.
uint8_t data; while (!(UART_SR & (1 << [1]))) {} data = UART_DR;
The RXNE_FLAG indicates that the receive data register is not empty and ready to be read.
Fill both blanks to initialize the array with the RXNE flag bit positions for each UART port and access it in the loop.
const int uart_rxne_flags[] = { [1] };
const char* uart_ports[] = {"UART1", "UART2", "UART3"};
for (int i = 0; i < 3; i++) {
printf("%s RXNE flag bit: %d\n", uart_ports[i], uart_rxne_flags[[2]]);
}The RXNE flag bit is bit 5 for all UART ports. The loop index i accesses the array.
Fill all three blanks to receive a byte only if RXNE flag is set, else set data to 0.
uint8_t data = (UART_SR & (1 << [1])) ? UART_[2] : [3];
This code uses a conditional expression: if RXNE flag is set, read UART_DR, else set data to 0.