Challenge - 5 Problems
UART Interrupt 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 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; }
Attempts:
2 left
💡 Hint
The ISR reads the UART data register and stores it in the buffer at the current index.
✗ Incorrect
The ISR triggers when a byte is received. It reads the byte from UDR and stores it in rx_buffer at rx_index, then increments rx_index. Since UDR holds 0x41, rx_buffer[0] becomes 'A'.
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
Interrupt flags must be cleared to avoid repeated triggers.
✗ Incorrect
If the interrupt flag is not cleared, the interrupt controller thinks the interrupt is still pending, so the ISR keeps running repeatedly, which can freeze the system or cause high CPU load.
🔧 Debug
advanced2: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 } }
Attempts:
2 left
💡 Hint
Check if the interrupt is enabled to trigger the ISR.
✗ Incorrect
The code disables the UDRE interrupt after sending all bytes, but it never enables it to start transmission. Without enabling UDRIE0, the ISR never triggers after the first byte.
📝 Syntax
advanced1: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?
Attempts:
2 left
💡 Hint
ISR functions use a special macro, not normal function syntax.
✗ Incorrect
In AVR embedded C, ISR functions must be declared with the ISR() macro. Declaring as a normal void function with the vector name is invalid syntax.
🚀 Application
expert2: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 }
Attempts:
2 left
💡 Hint
Buffer size limits how many bytes can be stored.
✗ Incorrect
The ISR stores bytes only if rx_index is less than 5. After 5 bytes, it discards any further bytes. So only 5 bytes are stored.