0
0
Embedded Cprogramming~20 mins

UART interrupt-driven communication in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
UART Interrupt Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this UART ISR code snippet?
Consider this UART interrupt service routine (ISR) snippet that reads a received byte and stores it in a buffer. What will be the value of rx_buffer[0] after the ISR runs once with UDR holding 0x41 (ASCII 'A')?
Embedded C
volatile char rx_buffer[10];
volatile int rx_index = 0;

ISR(USART_RX_vect) {
    rx_buffer[rx_index++] = UDR;
}
A0x00 (null character)
B'A' (0x41)
CUndefined value (buffer not updated)
DISR causes a compile error
Attempts:
2 left
💡 Hint
The ISR reads the UART data register and stores it in the buffer at the current index.
🧠 Conceptual
intermediate
1:30remaining
What happens if UART RX interrupt is not cleared properly?
In UART interrupt-driven communication, what is the most likely effect if the interrupt flag is not cleared inside the ISR?
AThe ISR will be called repeatedly, causing a system hang or high CPU usage.
BThe UART will stop receiving data permanently.
CThe UART will automatically clear the flag, so no effect occurs.
DThe microcontroller will reset immediately.
Attempts:
2 left
💡 Hint
Interrupt flags must be cleared to avoid repeated triggers.
🔧 Debug
advanced
2:30remaining
Why does this UART TX interrupt code fail to send all bytes?
This code tries to send a string via UART using TX interrupts. However, only the first character is sent. What is the bug?
Embedded C
volatile char tx_buffer[] = "HELLO";
volatile int tx_index = 0;

ISR(USART_UDRE_vect) {
    if (tx_index < sizeof(tx_buffer) - 1) {
        UDR = tx_buffer[tx_index];
        tx_index++;
    } else {
        UCSR0B &= ~(1 << UDRIE0); // Disable UDRE interrupt
    }
}
AThe interrupt enable bit UDRIE0 is not set before starting transmission.
BUsing sizeof(tx_buffer) includes the null terminator, causing an extra byte to send.
Ctx_index is not reset to zero after transmission completes.
DUDR register is read instead of written inside ISR.
Attempts:
2 left
💡 Hint
Check if the interrupt is enabled to trigger the ISR.
📝 Syntax
advanced
1:30remaining
Which option causes a syntax error in UART ISR declaration?
Which of these UART ISR declarations is syntactically incorrect in embedded C for AVR microcontrollers?
AISR(USART_RX_vect) { /* code */ }
BISR(USART_TX_vect) { /* code */ }
CISR(USART_UDRE_vect) { /* code */ }
Dvoid USART_RX_vect(void) { /* code */ }
Attempts:
2 left
💡 Hint
ISR functions use a special macro, not normal function syntax.
🚀 Application
expert
2:30remaining
How many bytes are stored after this UART RX interrupt-driven reception?
Given this UART RX ISR code that stores received bytes into a buffer of size 5, how many bytes will be stored if 7 bytes arrive without reading the buffer?
Embedded C
volatile char rx_buffer[5];
volatile int rx_index = 0;

ISR(USART_RX_vect) {
    if (rx_index < 5) {
        rx_buffer[rx_index++] = UDR;
    }
    // else bytes are discarded
}
A0 bytes stored; buffer not updated
B7 bytes stored; buffer auto-expands
C5 bytes stored; last 2 bytes discarded
DISR causes buffer overflow and crash
Attempts:
2 left
💡 Hint
Buffer size limits how many bytes can be stored.