Challenge - 5 Problems
UART Transmission Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this UART transmit function?
Consider the following embedded C code snippet that transmits a byte over UART. What will be the value of the UART data register (UDR) after calling
uart_transmit(0x55);?Embedded C
volatile unsigned char UDR = 0; volatile unsigned char UCSRA = 0x20; // UDRE bit set (ready) void uart_transmit(unsigned char data) { while (!(UCSRA & 0x20)) { // wait until UDRE bit is set } UDR = data; } int main() { uart_transmit(0x55); return 0; }
Attempts:
2 left
💡 Hint
Check what the function assigns to UDR after the ready bit is confirmed.
✗ Incorrect
The function waits until the UDRE bit (bit 5, value 0x20) in UCSRA is set, indicating the UART data register is ready. Then it assigns the data byte 0x55 to UDR. So UDR becomes 0x55.
🧠 Conceptual
intermediate1:30remaining
Which statement correctly describes the UDRE bit in UART communication?
In UART communication, what does the UDRE (UART Data Register Empty) bit indicate?
Attempts:
2 left
💡 Hint
Think about when you can safely write a new byte to the UART data register.
✗ Incorrect
The UDRE bit is set when the UART data register is empty and ready to accept new data for transmission.
🔧 Debug
advanced2:30remaining
Why does this UART transmit code cause a hang?
This code is intended to transmit a byte over UART, but it causes the program to hang (infinite loop). What is the reason?
Embedded C
volatile unsigned char UCSRA = 0x00; // UDRE bit is 0 (not ready) volatile unsigned char UDR = 0; void uart_transmit(unsigned char data) { while (!(UCSRA & 0x20)) { // wait until UDRE bit is set } UDR = data; } int main() { uart_transmit(0xAA); return 0; }
Attempts:
2 left
💡 Hint
Look at the initial value of UCSRA and the condition in the while loop.
✗ Incorrect
The UDRE bit (bit 5) in UCSRA is 0 initially and never changes, so the condition !(UCSRA & 0x20) is always true, causing an infinite loop.
📝 Syntax
advanced2:00remaining
Which option correctly transmits a byte over UART?
Select the code snippet that correctly waits for the UART data register to be ready and then transmits the byte
data.Attempts:
2 left
💡 Hint
UDRE bit is bit 5 (value 0x20). You want to wait until it is set.
✗ Incorrect
The UDRE bit is bit 5 (1 << 5 = 0x20). The code waits while UDRE is 0, then writes data to UDR. Option A correctly uses this logic.
🚀 Application
expert3:00remaining
How many bytes are transmitted by this UART send function call?
Given the following code, how many bytes will be transmitted when
uart_send_string("Hi"); is called?Embedded C
volatile unsigned char UCSRA = 0x20; // UDRE bit set volatile unsigned char UDR = 0; void uart_transmit(unsigned char data) { while (!(UCSRA & 0x20)) {} UDR = data; } void uart_send_string(const char *str) { while (*str) { uart_transmit(*str++); } } int main() { uart_send_string("Hi"); return 0; }
Attempts:
2 left
💡 Hint
Count the characters in the string and how the loop processes them.
✗ Incorrect
The string "Hi" has 2 characters. The loop calls uart_transmit twice, once for 'H' and once for 'i'. So 2 bytes are transmitted.