Complete the code to redirect printf output to UART by defining the correct function name.
int [1](char ch, FILE *f) { // UART transmit code here return ch; }
The fputc function is used to redirect characters output by printf to UART.
Complete the code to send a character over UART inside the fputc function.
int fputc(char ch, FILE *f) {
while (![1]()); // Wait until UART ready
UART_DR = ch; // Send character
return ch;
}The function uart_tx_ready() checks if UART is ready to transmit a new character.
Fix the error in the UART initialization code to enable UART transmit interrupt.
void uart_init() {
UART_CR = 0x00;
UART_BRR = 9600;
UART_CR |= [1]; // Enable UART
UART_CR |= [2]; // Enable TX interrupt
}To enable UART transmitter, set UART_CR_TE. To enable TX interrupt, set UART_CR_TXEIE.
Fill both blanks to complete the UART transmit function that waits for transmit buffer empty and sends a character.
void uart_send_char(char ch) {
while (![1]());
[2] = ch;
}Wait for uart_tx_ready() to confirm UART is ready, then write character to UART_DR data register.
Fill all three blanks to create a dictionary comprehension that maps characters to their ASCII codes if code is greater than 64.
ascii_map = [1]: ord([2]) for [3] in 'ABCDEF' if ord([2]) > 64}
The variable ch is used as key and in ord() to get ASCII code for each character.