Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to send a character over UART using printf.
Embedded C
#include <stdio.h> int main() { char c = 'A'; printf([1]); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %d prints the ASCII code, not the character.
Using %s expects a string, not a character.
✗ Incorrect
Use "%c" to print a single character with printf.
2fill in blank
mediumComplete the code to initialize UART for printf debugging.
Embedded C
void UART_Init() {
// Set baud rate
UBRR0 = [1];
// Enable transmitter
UCSR0B = (1 << TXEN0);
// Set frame format: 8 data bits, 1 stop bit
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting UBRR0 directly to baud rate value causes wrong speed.
Confusing baud rate with register value.
✗ Incorrect
UBRR0 value 103 sets baud rate to 9600 for 16MHz clock.
3fill in blank
hardFix the error in the UART transmit function to send a character correctly.
Embedded C
void UART_Transmit(char data) {
while (!(UCSR0A & (1 << [1]))) {
; // wait for empty transmit buffer
}
UDR0 = data;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Waiting for RXC0 waits for receive complete, not transmit buffer.
Using TXC0 waits for transmit complete, not buffer empty.
✗ Incorrect
UDRE0 bit indicates the transmit buffer is empty and ready for new data.
4fill in blank
hardFill both blanks to print a number in decimal and padded uppercase hex using printf for debugging.
Embedded C
int val = 255; printf("val = %d (0x%02[1])\n", val, [2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'x' prints lowercase hex letters.
Passing literal value '255' instead of variable 'val'.
✗ Incorrect
Use 'X' for uppercase padded hex (%02X), and 'val' as the argument.
5fill in blank
hardFill all three blanks to create a FILE stream that redirects printf to UART.
Embedded C
[1] uartout = FDEV_SETUP_STREAM(UART_Transmit, NULL, [2]); int main() { [3] = &uartout; printf("Debug: UART printf ready!\n"); return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using stdin instead of stdout redirects input, not output.
Missing 'static' or wrong type for the stream declaration.
✗ Incorrect
'static FILE' declares the output stream, '_FDEV_SETUP_WRITE' for write-only, 'stdout = &uartout' redirects printf.