Embedded Systems Interview Questions With Answers
Embedded interviews check whether you understand what the hardware is doing under your C code: memory-mapped registers, interrupts, timing, and the limits of a small microcontroller. Here are fifteen common questions, with the answer an interviewer expects and worked numbers where the question is usually a calculation. Each number is recomputed in the site's tests.
C on a microcontroller
- Q1. What does volatile do? Answer: it tells the compiler a variable can change outside the code it can see (a hardware register, or a flag set in an interrupt), so every access must really read or write memory instead of reusing a cached value.
- Q2. Does volatile make a variable thread-safe? Answer: no. It stops caching, not interruption: a read-modify-write such as count++ on a shared variable still needs interrupts disabled or an atomic operation.
- Q3. How do you set, clear and toggle bit n of a register? Answer: reg |= (1u << n); reg &= ~(1u << n); reg ^= (1u << n). Use unsigned constants so shifting into the top bit is defined.
- Q4. What is the difference between the stack and the heap? Answer: the stack holds local variables and return addresses, allocated and freed automatically in order; the heap is managed with malloc and free. Many embedded projects avoid the heap entirely, because fragmentation and failed allocations are hard to rule out.
- Q5. What is endianness? Answer: the byte order of a multi-byte value in memory. Little-endian stores the least significant byte first (ARM Cortex-M by default, x86); big-endian stores the most significant first. It matters when you send structs over a bus or network.
Interrupts and timing
- Q6. What should an interrupt handler do? Answer: as little as possible: read the hardware, clear the flag, store data or set a flag, and return. Long work, blocking calls and printing belong in the main loop or a task.
- Q7. What is interrupt latency? Answer: the time from the hardware event to the first instruction of the handler: the current instruction finishing, saving context, and any time interrupts were disabled.
- Q8. A 16 MHz timer uses a /64 prescaler. How many counts is 1 ms? Answer: 16 MHz / 64 = 250 kHz, so 250 counts.
- Q9. What is a watchdog timer for? Answer: it resets the chip unless the software 'kicks' it regularly, so a hung program recovers. Kick it from the main loop only after checking that every task is alive, not from a timer interrupt.
Q10. UART baud rate error
A UART with 16x oversampling divides its clock by 16 × divider. For 115200 baud from 16 MHz, the ideal divider is 16 MHz / (16 × 115200) = 8.68. Rounding to 9 gives 111,111 baud, 3.5% slow. A UART tolerates only a few percent of total mismatch between the two ends, so this link may fail. With 8x oversampling the divider is 17.36, rounded to 17, giving 117,647 baud, 2.1% fast: better, and the reason many chips offer a double-speed mode. A crystal such as 14.7456 MHz divides to standard baud rates exactly.
Peripherals
- Q11. A 12-bit ADC with a 3.3 V reference: what is one step, and what code does 1.65 V give? Answer: 3.3 V / 4096 = 0.806 mV per step, and 1.65 V reads about 2048, half of full scale.
- Q12. What are SPI modes? Answer: four combinations of clock polarity (CPOL, the idle level of SCK) and clock phase (CPHA, whether data is sampled on the first or second edge). Master and slave must use the same mode; check the slave's datasheet.
- Q13. Why does I2C need pull-up resistors? Answer: devices only pull the lines low (open drain), so resistors pull them high. Too large a value makes rise times too slow for the bus speed; too small a value needs more current than the drivers can sink.
RTOS
- Q14. What is priority inversion? Answer: a high-priority task waits for a mutex held by a low-priority task, while a medium-priority task runs and keeps the low one from finishing. Priority inheritance (temporarily raising the holder's priority) fixes it.
- Q15. Mutex or semaphore? Answer: a mutex protects a shared resource and is owned (only the task that took it may give it back, which enables priority inheritance); a semaphore counts or signals events, for example from an interrupt to a task.
How to answer well
Tie each answer to the hardware: say what the compiler, the bus or the peripheral does, and do the arithmetic out loud. A worked number, such as '3.5% baud error is too much', shows you have debugged real hardware.
Related
Last verified
The timer, UART and ADC figures are computed in the site's tests (lib/batch9Numbers.test.js) on 16 November 2026.