0
0
Embedded Cprogramming~10 mins

Common embedded bugs and fixes 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 correctly initialize the pointer.

Embedded C
int value = 10;
int *ptr = [1];
Drag options to blanks, or click blank then click option'
A&value
B*value
Cvalue
Dptr
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name directly instead of its address.
Dereferencing the variable instead of taking its address.
2fill in blank
medium

Complete the code to correctly check if a bit is set in a register.

Embedded C
if ((reg & [1]) != 0) {
    // bit is set
}
Drag options to blanks, or click blank then click option'
A0x01
B1
C0x00
Dreg
Attempts:
3 left
💡 Hint
Common Mistakes
Using the register itself as a mask.
Using zero as a mask which always results false.
3fill in blank
hard

Fix the error in the interrupt service routine declaration.

Embedded C
void [1] ISR_Handler(void) {
    // ISR code
}
Drag options to blanks, or click blank then click option'
Astatic
Binterrupt
Cvoid
D__interrupt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'interrupt' instead of '__interrupt'.
Omitting the interrupt keyword entirely.
4fill in blank
hard

Fill both blanks to correctly define a volatile pointer to a hardware register.

Embedded C
volatile [1] *[2] = (volatile [1] *)0x40021000;
Drag options to blanks, or click blank then click option'
Auint32_t
Breg
Cint
Dptr
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' instead of 'uint32_t' which may have wrong size.
Using non-volatile types which can cause optimization issues.
5fill in blank
hard

Fill all three blanks to correctly implement a delay loop using a volatile counter.

Embedded C
void delay(void) {
    volatile int [1] = [2];
    while ([1] > 0) {
        [1]--;
    }
}
Drag options to blanks, or click blank then click option'
Acounter
B10000
Ci
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-volatile variable which the compiler may optimize away.
Initializing the counter to zero which causes no delay.