0
0
Embedded Cprogramming~10 mins

Why GPIO is the foundation of embedded in Embedded C - Test Your Understanding

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

Complete the code to set a GPIO pin as output.

Embedded C
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = [1];
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
Drag options to blanks, or click blank then click option'
AGPIO_MODE_OUTPUT_PP
BGPIO_MODE_INPUT
CGPIO_MODE_ANALOG
DGPIO_MODE_IT_RISING
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing input mode instead of output mode.
2fill in blank
medium

Complete the code to read the state of a GPIO pin.

Embedded C
int pin_state = HAL_GPIO_ReadPin(GPIOB, [1]);
Drag options to blanks, or click blank then click option'
AGPIO_PIN_3
BGPIO_PIN_0
CGPIO_PIN_12
DGPIO_PIN_7
Attempts:
3 left
💡 Hint
Common Mistakes
Using a pin number not defined or not connected.
3fill in blank
hard

Fix the error in the code to toggle a GPIO pin.

Embedded C
HAL_GPIO_TogglePin(GPIOC, [1]);
Drag options to blanks, or click blank then click option'
AGPIO_PIN_13
BGPIO_PIN_8
CGPIO_PIN_5
DGPIO_PIN_0
Attempts:
3 left
💡 Hint
Common Mistakes
Using a pin that is not configured as output.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps pin numbers to their states if the pin state is high.

Embedded C
pin_states = {pin: HAL_GPIO_ReadPin(GPIOA, pin) for pin in pins if HAL_GPIO_ReadPin(GPIOA, pin) [1] [2]
Drag options to blanks, or click blank then click option'
A==
BGPIO_PIN_5
CGPIO_PIN_SET
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator or wrong pin state constant.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps pin names in uppercase to their states if the state is low.

Embedded C
pin_status = { [1]: HAL_GPIO_ReadPin(GPIOB, [2]) for [3] in pins if HAL_GPIO_ReadPin(GPIOB, pin) == GPIO_PIN_RESET }
Drag options to blanks, or click blank then click option'
Apin.upper()
Bpin
Dpin_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names or wrong key formatting.