0
0
Embedded Cprogramming~10 mins

Polling vs interrupt-driven execution in Embedded C - Interactive Practice

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

Complete the code to check the button state using polling.

Embedded C
while(1) {
    if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == [1]) {
        // Button pressed action
    }
}
Drag options to blanks, or click blank then click option'
A2
B0
C1
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 for pressed state.
2fill in blank
medium

Complete the code to enable the interrupt for the button pin.

Embedded C
EXTI_InitTypeDef EXTI_InitStructure;

EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_[1];
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
Drag options to blanks, or click blank then click option'
AInterrupt
BPolling
CTimer
DDMA
Attempts:
3 left
💡 Hint
Common Mistakes
Using Polling mode instead of Interrupt mode.
3fill in blank
hard

Fix the error in the interrupt handler function name.

Embedded C
void [1](void) {
    if (EXTI_GetITStatus(EXTI_Line0) != RESET) {
        // Handle button press
        EXTI_ClearITPendingBit(EXTI_Line0);
    }
}
Drag options to blanks, or click blank then click option'
AEXTI_IRQHandler
BEXTI1_IRQHandler
CEXTI0_Handler
DEXTI0_IRQHandler
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong handler names like EXTI1_IRQHandler or EXTI0_Handler.
4fill in blank
hard

Fill both blanks to create a polling loop that waits for a button press and then toggles an LED.

Embedded C
while(1) {
    if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_[1]) == [2]) {
        GPIO_ToggleBits(GPIOC, GPIO_Pin_13);
    }
}
Drag options to blanks, or click blank then click option'
A0
B1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong pin number or wrong pressed state value.
5fill in blank
hard

Fill all three blanks to define an interrupt-driven setup: enable clock, configure GPIO pin as input, and enable NVIC interrupt.

Embedded C
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, [1]);

GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_[2];
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init(GPIOA, &GPIO_InitStructure);

NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = EXTI[3]_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
Drag options to blanks, or click blank then click option'
AENABLE
B5
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using DISABLE instead of ENABLE, wrong pin number, or wrong IRQ channel.