Embedded Systems & Firmware
When using a microcontroller GPIO (general-purpose input/output) pin, what must be configured first?
- AWhether the pin is used as an input or an output (its direction)
- BThe color of the pin
- CThe name of the programmer who wrote the code
Show answer and explanation
Answer: A. Whether the pin is used as an input or an output (its direction)
A GPIO pin can be used as either an input or an output under software control. Configured as an output through the direction register, the value written to the output register becomes the pin voltage; configured as an input, the pin voltage can be read from the input register. Most microcontrollers also let you set pull-ups, the output type (push-pull or open-drain) and whether the pin serves another peripheral.
- A. Correct. It is set in a direction register.
- B. Pin color is irrelevant.
- C. The programmer's name is irrelevant.