What GPIO modes does a typical microcontroller pin support, and when would you use each?
What the interviewer wants to hear
- Input with pull-up, pull-down or floating
- Push-pull output for driving LEDs and logic
- Open-drain output for shared lines like I2C
- Alternate function to connect the pin to a peripheral
- Analog mode for ADC/DAC and lowest power
Model answer
Most MCU pins can be digital inputs, digital outputs, alternate function or analog. As an input I choose a pull-up or pull-down so the pin never floats, for example a pull-up for a button to ground. For outputs, push-pull drives the line both high and low, which suits LEDs and chip selects, while open-drain only pulls low and needs an external pull-up, which lets several devices share a line like I2C or an interrupt line. Alternate function hands the pin to a peripheral such as UART, SPI, a timer or PWM output. Analog mode connects the pin to the ADC or DAC and disables the digital input buffer, which is also the lowest-power setting for unused pins. I also set output speed and drive strength, because fast edges cause noise and EMI.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Embedded Systems Engineer questions
- What is the difference between a microcontroller and a microprocessor?
- What is an interrupt, and how is it different from polling?
- Compare UART, SPI and I2C. When would you use each?
- Explain volatile and const in embedded C. Can a variable be both?
- When would you use bare-metal firmware versus an RTOS?
- What is PWM, how is it generated on a microcontroller, and what is it used for?
- What is a bootloader in an embedded device, and why would a product need one?
- What is endianness, and how do you deal with it when exchanging data between devices?
- How do you approach reading a datasheet for a new sensor or microcontroller?