0
0
Embedded Cprogramming~10 mins

Printf redirect to 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 redirect printf output to UART by defining the correct function name.

Embedded C
int [1](char ch, FILE *f) {
    // UART transmit code here
    return ch;
}
Drag options to blanks, or click blank then click option'
Afputc
Bprintf
Cuart_send
Dputchar
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'printf' or 'putchar' instead of 'fputc' for redirection.
2fill in blank
medium

Complete the code to send a character over UART inside the fputc function.

Embedded C
int fputc(char ch, FILE *f) {
    while (![1]()); // Wait until UART ready
    UART_DR = ch; // Send character
    return ch;
}
Drag options to blanks, or click blank then click option'
Auart_error
Buart_rx_ready
Cuart_tx_ready
Duart_busy
Attempts:
3 left
💡 Hint
Common Mistakes
Using receive ready or busy flags instead of transmit ready.
3fill in blank
hard

Fix the error in the UART initialization code to enable UART transmit interrupt.

Embedded C
void uart_init() {
    UART_CR = 0x00;
    UART_BRR = 9600;
    UART_CR |= [1]; // Enable UART
    UART_CR |= [2]; // Enable TX interrupt
}
Drag options to blanks, or click blank then click option'
AUART_CR_RXNEIE
BUART_CR_RE
CUART_CR_TXEIE
DUART_CR_TE
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing receiver enable with transmitter enable.
4fill in blank
hard

Fill both blanks to complete the UART transmit function that waits for transmit buffer empty and sends a character.

Embedded C
void uart_send_char(char ch) {
    while (![1]());
    [2] = ch;
}
Drag options to blanks, or click blank then click option'
Auart_tx_ready
BUART_DR
Cuart_rx_ready
DUART_SR
Attempts:
3 left
💡 Hint
Common Mistakes
Using receive ready flag or status register incorrectly.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps characters to their ASCII codes if code is greater than 64.

Embedded C
ascii_map = [1]: ord([2]) for [3] in 'ABCDEF' if ord([2]) > 64}
Drag options to blanks, or click blank then click option'
Ach
Dchar
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.