Embedded C Interview Questions and Answers
Basic Level
- What is Embedded C?
Embedded C is an extension of the C language used to program embedded systems such as
microcontrollers.
- How is Embedded C different from regular C?
Embedded C interacts directly with hardware using registers and bit-level operations.
- What are microcontrollers and microprocessors?
Microcontrollers are single-chip devices with CPU, RAM, ROM, and I/O. Microprocessors only
have a CPU and require external peripherals.
- What are the basic components of an embedded system?
Microcontroller, memory, input/output interfaces, communication interfaces, and software.
- Explain the role of volatile in Embedded C.
It tells the compiler not to optimize a variable because it can be changed by hardware or ISR.
- What is the significance of const in embedded programming?
Prevents accidental changes to values that should remain constant (e.g., config data or ROM
values).
- What are registers and how are they accessed in C?
Registers are memory-mapped hardware locations accessed using pointers in Embedded C.
- What is memory-mapped I/O?
Technique where I/O devices are mapped into the address space and accessed like normal
memory.
- What are the types of memory in a microcontroller?
Flash (program), SRAM (data), EEPROM (non-volatile data storage).
- What is ISR (Interrupt Service Routine)?
A special function executed automatically in response to an interrupt.
Intermediate Level
- Difference between polling and interrupt-driven I/O.
Polling checks device status in a loop. Interrupt-driven allows CPU to perform tasks and react to
events.
- How do you write an ISR in Embedded C?
Using compiler-specific syntax (e.g., `void __interrupt() ISR(void)` or with vector table setup).
- What is the function of a watchdog timer?
To reset the system in case of software malfunction or freeze.
- Explain the use of bitwise operators in Embedded C.
Used for setting, clearing, and toggling specific bits in registers or variables.
- How do you optimize code for memory in embedded systems?
Use smaller data types, avoid dynamic allocation, and optimize logic/loops.
- What is debouncing in embedded systems?
Removing noise from mechanical button presses using delay or software filtering.
- How do you manage power consumption in Embedded C applications?
Use sleep modes, optimize loops, shut down unused peripherals.
- How is delay implemented in microcontroller programming?
Using timer peripherals or software delay loops (less accurate).
- What is the difference between blocking and non-blocking code?
Blocking waits for operation to complete; non-blocking continues execution while waiting.
- What are the common communication protocols used in embedded systems?
SPI, I2C, UART, CAN, USB, etc.
Advanced Level
- What are critical sections and how do you protect them?
Code that must not be interrupted. Protected using disable/enable interrupts or mutex in RTOS.
- How do you handle race conditions in Embedded C?
Use atomic operations, critical sections, or synchronization primitives.
- What is the use of memory barriers or compiler fences?
To ensure memory operations occur in the correct order across CPU/compiler.
- Explain the role of linker scripts in embedded systems.
Define memory layout, segment locations (e.g., Flash, RAM) for program sections.
- What is stack overflow and how do you prevent it?
Occurs when stack exceeds its limit. Prevent using large global variables and monitoring usage.
- Describe how RTOS is used with Embedded C.
RTOS provides task management, inter-task communication, scheduling, and resource
management.
- What are the different scheduling algorithms in RTOS?
Round-robin, priority-based, rate-monotonic, and earliest-deadline-first.
- How does interrupt nesting work and how is it managed?
Higher priority interrupts can pre-empt current ISR. Managed by priority levels and stack use.
- What are startup files and their purpose?
Startup code initializes memory and sets up vector table before main() runs.
- How do you use DMA in embedded systems?
Configure DMA controller to transfer data between peripherals and memory without CPU
intervention.
Practical Questions
- Write a program to blink an LED using a delay loop.
Set GPIO as output, then toggle it in a loop with delay.
- Write code to toggle a GPIO pin.
PORT ^= (1 << PIN); // Toggle bit
- Implement a basic UART send/receive function in C.
void uart_send(char c) { while (!(UCSRA & (1<<UDRE))); UDR = c; }
- Simulate a software PWM signal using timers.
Use loop/timer to set pin high/low based on duty cycle.
- Write an ISR for a button press interrupt.
ISR(INT0_vect) { flag = 1; }
- Demonstrate how to set/clear a specific bit in a register.
Set: REG |= (1<<BIT);
Clear: REG &= ~(1<<BIT);
- Implement a simple state machine in C.
Use switch-case on state variable updated by events.