0
0
Embedded Cprogramming~10 mins

Receiving a byte over UART in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read a byte from UART data register.

Embedded C
uint8_t received_byte = [1];
Drag options to blanks, or click blank then click option'
AUART_DR
BUART_SR
CUART_CR
DUART_BRR
Attempts:
3 left
💡 Hint
Common Mistakes
Using UART_SR (status register) instead of UART_DR.
Trying to read from UART_CR (control register).
2fill in blank
medium

Complete the code to wait until a byte is received (RXNE flag set).

Embedded C
while (!([1] & (1 << RXNE_FLAG))) {}
Drag options to blanks, or click blank then click option'
AUART_DR
BUART_SR
CUART_CR
DUART_BRR
Attempts:
3 left
💡 Hint
Common Mistakes
Checking RXNE flag in UART_DR instead of UART_SR.
Using UART_CR or UART_BRR which do not hold status flags.
3fill in blank
hard

Fix the error in the code to correctly receive a byte over UART.

Embedded C
uint8_t data;
while (!(UART_SR & (1 << [1]))) {}
data = UART_DR;
Drag options to blanks, or click blank then click option'
ATXE_FLAG
BORE_FLAG
CRXNE_FLAG
DCTS_FLAG
Attempts:
3 left
💡 Hint
Common Mistakes
Using TXE_FLAG which is for transmit, not receive.
Using CTS_FLAG or ORE_FLAG which are unrelated here.
4fill in blank
hard

Fill both blanks to initialize the array with the RXNE flag bit positions for each UART port and access it in the loop.

Embedded C
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]]);
}
Drag options to blanks, or click blank then click option'
A5, 5, 5
B6, 7, 8
C5, 6, 7
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using different bit numbers for UART ports.
Not using the loop index to access the array.
5fill in blank
hard

Fill all three blanks to receive a byte only if RXNE flag is set, else set data to 0.

Embedded C
uint8_t data = (UART_SR & (1 << [1])) ? UART_[2] : [3];
Drag options to blanks, or click blank then click option'
ARXNE_FLAG
BDR
C0
DTXE_FLAG
Attempts:
3 left
💡 Hint
Common Mistakes
Using TXE_FLAG instead of RXNE_FLAG.
Setting data to UART_DR unconditionally.