Complete the code to check the button state using polling.
while(1) { if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == [1]) { // Button pressed action } }
The button is considered pressed when the input pin reads 1 (high).
Complete the code to enable the interrupt for the button pin.
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);The EXTI mode must be set to Interrupt to enable interrupt-driven execution.
Fix the error in the interrupt handler function name.
void [1](void) { if (EXTI_GetITStatus(EXTI_Line0) != RESET) { // Handle button press EXTI_ClearITPendingBit(EXTI_Line0); } }
The correct interrupt handler name for EXTI line 0 is EXTI0_IRQHandler.
Fill both blanks to create a polling loop that waits for a button press and then toggles an LED.
while(1) { if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_[1]) == [2]) { GPIO_ToggleBits(GPIOC, GPIO_Pin_13); } }
The button is connected to pin 0 and is pressed when the input reads 1.
Fill all three blanks to define an interrupt-driven setup: enable clock, configure GPIO pin as input, and enable NVIC interrupt.
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);
Clock must be enabled (ENABLE), GPIO pin 0 is configured as input, and NVIC interrupt for EXTI0 is enabled.