0
0
Embedded Cprogramming~10 mins

ISR best practices (keep it short) 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 declare an ISR function correctly.

Embedded C
void [1](void) {
    // ISR code here
}
Drag options to blanks, or click blank then click option'
Ainterrupt
BISR
CISR_Handler
Dmain
Attempts:
3 left
💡 Hint
Common Mistakes
Using normal function names like 'main' or 'interrupt' without proper ISR declaration.
2fill in blank
medium

Complete the code to keep the ISR short by only setting a flag.

Embedded C
volatile int flag = 0;

void ISR(void) {
    [1] = 1;
}
Drag options to blanks, or click blank then click option'
Aflag
Bresult
Ctemp
Dcounter
Attempts:
3 left
💡 Hint
Common Mistakes
Modifying non-volatile variables inside ISR.
3fill in blank
hard

Fix the error in the ISR by disabling nested interrupts.

Embedded C
void ISR(void) {
    [1]();
    // ISR code
}
Drag options to blanks, or click blank then click option'
Aenable_nested_interrupts
Benable_interrupts
Cdisable_interrupts
Dclear_interrupt_flag
Attempts:
3 left
💡 Hint
Common Mistakes
Enabling interrupts inside ISR causing nested calls.
4fill in blank
hard

Fill both blanks to safely update a shared variable in ISR and main code.

Embedded C
volatile int count = 0;

void ISR(void) {
    [1]();
    count++;
    [2]();
}
Drag options to blanks, or click blank then click option'
Adisable_interrupts
Benable_interrupts
Cclear_interrupt_flag
Dreset_counter
Attempts:
3 left
💡 Hint
Common Mistakes
Not disabling interrupts leading to data corruption.
5fill in blank
hard

Fill all three blanks to implement a flag check and clear in main loop and ISR.

Embedded C
volatile int flag = 0;

void ISR(void) {
    [1] = 1;
}

int main(void) {
    while(1) {
        if ([2] == 1) {
            // handle event
            [3] = 0;
        }
    }
}
Drag options to blanks, or click blank then click option'
Aflag
Bevent
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causing logic errors.