0
0
Embedded Cprogramming~10 mins

Nested interrupts in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable global interrupts.

Embedded C
#include <avr/interrupt.h>

int main() {
    sei(); // Enable global interrupts
    [1];
    while(1) {}
    return 0;
}
Drag options to blanks, or click blank then click option'
Aenable_interrupts()
Bcli()
Cinterrupt_enable()
Dsei()
Attempts:
3 left
💡 Hint
Common Mistakes
Using cli() which disables interrupts instead of enabling them.
Using non-standard function names.
2fill in blank
medium

Complete the code to define an interrupt service routine (ISR) for TIMER1 overflow.

Embedded C
#include <avr/interrupt.h>

ISR([1]) {
    // ISR code here
}
Drag options to blanks, or click blank then click option'
AINT0_vect
BTIMER0_OVF_vect
CTIMER1_OVF_vect
DADC_vect
Attempts:
3 left
💡 Hint
Common Mistakes
Using TIMER0_OVF_vect which is for TIMER0.
Using unrelated interrupt vectors.
3fill in blank
hard

Fix the error in the ISR declaration to allow nested interrupts by enabling global interrupts inside the ISR.

Embedded C
ISR(TIMER2_OVF_vect) {
    [1](); // Enable nested interrupts
    // ISR code
}
Drag options to blanks, or click blank then click option'
Acli
Bsei
Cenable_global_interrupts
Dinterrupt_enable
Attempts:
3 left
💡 Hint
Common Mistakes
Using cli() which disables interrupts.
Using non-standard function names.
4fill in blank
hard

Fill both blanks to create a nested interrupt safe ISR that enables global interrupts and clears the interrupt flag.

Embedded C
ISR(ADC_vect) {
    [1](); // Enable nested interrupts
    ADCSRA [2] (1 << ADIF); // Clear interrupt flag
}
Drag options to blanks, or click blank then click option'
Asei
B|=
C&=
Dcli
Attempts:
3 left
💡 Hint
Common Mistakes
Using cli() instead of sei() to enable interrupts.
Using &= which clears bits instead of setting them.
5fill in blank
hard

Fill all three blanks to implement a nested interrupt safe ISR that enables global interrupts, clears the interrupt flag, and increments a counter.

Embedded C
volatile uint8_t count = 0;

ISR(INT0_vect) {
    [1](); // Enable nested interrupts
    EIFR [2] (1 << INTF0); // Clear interrupt flag
    [3]++; // Increment counter
}
Drag options to blanks, or click blank then click option'
Asei
B|=
Ccount
Dcli
Attempts:
3 left
💡 Hint
Common Mistakes
Using cli() instead of sei() to enable interrupts.
Using &= instead of |= to clear the flag.
Incrementing a wrong or undefined variable.