What is an interrupt, and how is it different from polling?
What the interviewer wants to hear
- Hardware signal that pauses normal code to run an ISR
- Polling repeatedly checks a status in a loop
- Interrupts are efficient and responsive; polling is simple but wastes CPU
- Interrupt priorities and nesting
- ISRs should be short
Model answer
An interrupt is a signal, usually from hardware like a timer, GPIO pin or UART, that makes the CPU pause its current code, save its state and jump to an interrupt service routine through the vector table. When the ISR finishes, the CPU continues where it left off. Polling is the alternative: the main loop keeps checking a status flag, for example "has a byte arrived?". Polling is simple and predictable, but it wastes CPU time and power and may react late if the loop is busy. Interrupts respond quickly and let the CPU do other work or sleep until something happens. On Cortex-M, the NVIC handles priorities, so a high-priority interrupt can preempt a lower one. ISRs should be short: copy the data, set a flag or notify a task, and let the main code do the heavy processing.
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?
- 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 GPIO modes does a typical microcontroller pin support, and when would you use each?
- 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?