✓ 100% Free — 75 Questions

Embedded Systems Fundamentals

Section 1

Embedded Systems Basics

10 Questions
What is an embedded system?

An embedded system is a dedicated computer system designed to perform specific functions within a larger system. It combines hardware and software to control, monitor, or assist in the operation of machinery or equipment.

Key characteristics:

  • Single-function or limited-function design
  • Real-time operation requirements
  • Constrained resources (memory, power, CPU)
  • Tightly integrated hardware/software

Examples: ABS braking systems, washing machine controllers, cardiac pacemakers, router firmware.

Microcontroller vs Microprocessor — What's the difference?

Microprocessor: A CPU-only chip. Requires external RAM, ROM, I/O peripherals. High performance, high power. Used in computers and smartphones.

Microcontroller: CPU + RAM + ROM + I/O all on one chip. Self-contained, low power, low cost. Used in embedded systems.

Microcontroller = CPU + RAM + Flash + Timers + UART + GPIO (all-in-one)
Microprocessor  = CPU only → needs external components

Examples — MCU: STM32, ATmega328. MPU: Intel Core i7, ARM Cortex-A53.

What is bare-metal programming?

Bare-metal programming means writing code that runs directly on hardware without an operating system. The programmer has full control over every CPU register, peripheral, and memory address.

// Bare-metal: toggle LED directly via register
#define GPIOA_ODR  (*(volatile uint32_t*)0x40020014)
GPIOA_ODR |= (1 << 5);  // Set PA5 high

Advantages: Minimal latency, full determinism, tiny footprint.
Used in: Bootloaders, safety-critical systems, ultra-low-power devices.

What are the main constraints in embedded systems?

Embedded systems operate under tight constraints that distinguish them from general-purpose computers:

  • Memory: Kilobytes of RAM, not gigabytes
  • Power: Battery-operated or energy-harvesting systems
  • Processing: Low MHz CPUs without cache or FPU
  • Real-time: Hard deadlines must be met every time
  • Cost: BOM (bill of materials) must be minimal
  • Reliability: Must run for years without failure
What is a watchdog timer and why is it important?

A watchdog timer (WDT) is a hardware timer that resets the microcontroller if the software fails to "kick" (reload) it within a set interval. It detects software hangs or infinite loops.

// Kick watchdog to prevent reset
IWDG->KR = 0xAAAA;  // Reset countdown

// If this line is never reached → WDT resets MCU
while(1) {
    process_data();
    IWDG->KR = 0xAAAA;  // Must kick within timeout
}

Types: Independent WDT (IWDG) — runs on its own clock, Window WDT (WWDG) — must be kicked within a time window.

What is GPIO and how is it configured?

GPIO (General Purpose Input/Output) pins can be software-configured as digital input or output to interface with sensors, LEDs, buttons, and other peripherals.

// STM32 example: configure PA5 as output
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;  // Enable clock
GPIOA->MODER |= (1 << 10);             // Set PA5 as output
GPIOA->ODR   |= (1 << 5);             // Set PA5 HIGH

// Read input on PB0
GPIOB->MODER &= ~(3 << 0);            // Set PB0 as input
uint8_t val = (GPIOB->IDR >> 0) & 1;  // Read pin

Modes: Input (floating/pull-up/pull-down), Output (push-pull/open-drain), Alternate Function, Analog.

What is a real-time system? Explain hard vs soft real-time.

A real-time system must respond to inputs within defined time constraints (deadlines).

Hard Real-Time: Missing a deadline causes catastrophic failure. Examples: airbag deployment, pacemaker timing, fly-by-wire aircraft.

Soft Real-Time: Missing a deadline degrades performance but is acceptable. Examples: video streaming, audio playback, UI responsiveness.

Firm Real-Time: Deadlines missed make the result useless but not dangerous. Example: financial tick data.

What is memory-mapped I/O?

Memory-mapped I/O means peripheral registers are placed in the same address space as RAM and Flash. The CPU accesses peripherals using normal load/store instructions to specific addresses.

// Peripheral register at fixed address
#define USART1_DR  (*(volatile uint32_t*)0x40011004)

// Write byte to UART — same as writing to memory
USART1_DR = 'A';

This simplifies the ISA (no special I/O instructions needed) and is the dominant model in ARM Cortex-M devices.

What is an interrupt and how does interrupt handling work?

An interrupt is a hardware or software signal that causes the CPU to pause its current task and execute an Interrupt Service Routine (ISR).

// ISR for external interrupt on PA0 (STM32)
void EXTI0_IRQHandler(void) {
    if (EXTI->PR & (1 << 0)) {
        button_pressed = 1;     // Set flag
        EXTI->PR |= (1 << 0);  // Clear pending bit
    }
}

// Main loop checks the flag
while(1) {
    if (button_pressed) {
        toggle_led();
        button_pressed = 0;
    }
}

Interrupt flow: Trigger → CPU saves context (PC, registers) → Jumps to ISR → Returns → Restores context → Continues main program.

What is DMA and why is it used in embedded systems?

DMA (Direct Memory Access) allows peripherals to transfer data to/from memory without CPU intervention, freeing the CPU for other tasks.

// Without DMA: CPU reads each ADC byte manually
for(int i = 0; i < 1024; i++)
    buffer[i] = ADC1->DR;  // CPU busy-waiting

// With DMA: hardware fills buffer automatically
DMA2_Stream0->M0AR = (uint32_t)buffer;
DMA2_Stream0->NDTR = 1024;
DMA2_Stream0->CR  |= DMA_SxCR_EN;  // CPU free to do other work

Common uses: ADC sampling, UART/SPI bulk transfers, audio streaming, memory copies.

Section 2

ARM Microcontrollers

10 Questions
Overview of ARM Cortex-M microcontroller families

ARM Cortex-M is a family of 32-bit RISC cores optimized for microcontrollers:

  • Cortex-M0/M0+: Ultra-low power, minimal logic, IoT sensors
  • Cortex-M3: Full Thumb-2, hardware divider, good for general MCU use
  • Cortex-M4: DSP extensions + optional FPU — industrial control
  • Cortex-M7: Dual-issue pipeline, cache, high-performance MCU
  • Cortex-M33: TrustZone security, IoT connectivity

All share the same Thumb-2 instruction set and NVIC interrupt controller architecture.

What is the ARM Cortex-M memory map?

Cortex-M defines a fixed 4GB address space divided into regions:

0x00000000 – 0x1FFFFFFF  Code (Flash)          512 MB
0x20000000 – 0x3FFFFFFF  SRAM                   512 MB
0x40000000 – 0x5FFFFFFF  Peripherals (APB/AHB)  512 MB
0x60000000 – 0x9FFFFFFF  External RAM           1 GB
0xA0000000 – 0xDFFFFFFF  External Device        1 GB
0xE0000000 – 0xFFFFFFFF  System (SCS, DWT, ITM) 512 MB

The fixed map ensures portable driver code across all Cortex-M devices.

What is NVIC and how do you configure interrupt priorities?

NVIC (Nested Vectored Interrupt Controller) manages up to 240 external interrupts with configurable priorities. Lower number = higher priority.

// Enable interrupt with priority using CMSIS
NVIC_SetPriority(USART1_IRQn, 2);   // Priority 2
NVIC_EnableIRQ(USART1_IRQn);        // Enable it

// Cortex-M supports nested interrupts:
// A higher-priority ISR can preempt a lower-priority one

Priority levels are determined by the number of priority bits implemented (typically 4 bits = 16 levels on STM32).

What is the role of the System Tick (SysTick) timer?

SysTick is a 24-bit decrementing counter built into every Cortex-M core. It generates a periodic interrupt used as the OS tick for RTOS task scheduling and HAL delay functions.

// Configure SysTick for 1ms tick at 72MHz
SysTick_Config(72000);  // 72MHz / 72000 = 1kHz = 1ms

// SysTick_Handler called every 1ms
void SysTick_Handler(void) {
    system_tick++;          // Increment tick counter
    // RTOS: check if task switch needed
}
Explain ARM Cortex-M exception types and the vector table

The vector table is an array of function pointers stored at the start of Flash (0x00000000). Each entry is the address of an exception/interrupt handler.

// Simplified vector table (startup.s)
__Vectors:
    .word  _estack          // Initial stack pointer
    .word  Reset_Handler    // Reset
    .word  NMI_Handler      // Non-maskable interrupt
    .word  HardFault_Handler
    .word  MemManage_Handler
    .word  BusFault_Handler
    .word  UsageFault_Handler
    // ... IRQ0 onwards

System exceptions: Reset, NMI, HardFault, MemManage, BusFault, UsageFault, SVCall, PendSV, SysTick.

What is the difference between Thumb and Thumb-2 instruction sets?

ARM (32-bit): Full instruction set, best performance, large code size.

Thumb (16-bit): Compressed subset of ARM instructions. ~30% smaller code. Used on older ARM7/ARM9.

Thumb-2: Mix of 16-bit and 32-bit instructions. Near full ARM performance with ~25% code-size saving. All Cortex-M cores use Thumb-2 exclusively — no mode switching needed.

What are the ARM Cortex-M privilege levels?

Cortex-M has two privilege levels and two stack pointers for OS isolation:

Privileged mode: Full access to all registers and system resources. Used by OS kernel and exception handlers.

Unprivileged (User) mode: Restricted access. Used by application tasks. Cannot access system control registers.

Stack pointers: MSP (Main Stack Pointer) used by kernel/exceptions, PSP (Process Stack Pointer) used by tasks. This allows the OS to detect stack overflows per task.

What is the MPU (Memory Protection Unit) in ARM Cortex-M?

The MPU divides memory into up to 8 regions (16 on Cortex-M33) with configurable access permissions. It prevents tasks from accessing each other's memory or the kernel's memory.

// Configure MPU region 0: SRAM, 32KB, Read/Write, no exec
MPU->RNR  = 0;
MPU->RBAR = 0x20000000;
MPU->RASR = MPU_RASR_ENABLE
          | (0x0E << MPU_RASR_SIZE_Pos)   // 32KB
          | (3 << MPU_RASR_AP_Pos)        // Full R/W
          | MPU_RASR_XN_Msk;             // No execute
MPU->CTRL = MPU_CTRL_ENABLE_Msk;
How does the ARM reset sequence work?

On reset, Cortex-M hardware automatically:

  1. Reads initial Stack Pointer from address 0x00000000
  2. Reads Reset Handler address from 0x00000004
  3. Jumps to Reset_Handler in Thumb mode
void Reset_Handler(void) {
    // 1. Copy .data section from Flash to SRAM
    // 2. Zero-fill .bss section
    // 3. Call SystemInit() — configure PLL/clocks
    // 4. Call main()
    SystemInit();
    main();
    while(1);  // Should never reach here
}
What is clock configuration and why does it matter?

Clock configuration determines the operating speed of the CPU, buses, and peripherals. Incorrect clock setup is one of the most common sources of bugs in embedded systems.

// STM32: configure PLL to 72MHz from 8MHz HSE
RCC->CR    |= RCC_CR_HSEON;          // Enable HSE crystal
while(!(RCC->CR & RCC_CR_HSERDY));  // Wait for stable
RCC->CFGR  |= RCC_CFGR_PLLSRC_HSE; // PLL source = HSE
RCC->CFGR  |= RCC_CFGR_PLLMULL9;   // 8MHz × 9 = 72MHz
RCC->CR    |= RCC_CR_PLLON;
while(!(RCC->CR & RCC_CR_PLLRDY));
RCC->CFGR  |= RCC_CFGR_SW_PLL;     // Switch to PLL
Section 3

Communication Protocols

10 Questions
UART Protocol — Serial Communication Basics

UART (Universal Asynchronous Receiver/Transmitter) is a simple 2-wire serial protocol (TX/RX). Asynchronous — no shared clock; both sides must agree on baud rate.

// UART frame: [START][D0][D1]...[D7][PARITY][STOP]
// 1 start bit + 8 data bits + 1 stop bit = 10 bits per byte

// At 9600 baud: 9600 bits/sec → ~960 bytes/sec
// Common baud rates: 9600, 115200, 921600

// STM32 send byte
while(!(USART1->SR & USART_SR_TXE));  // Wait TX empty
USART1->DR = 'A';                      // Send byte

Pros: Simple, only 2 wires. Cons: Point-to-point only, slow, no built-in error detection beyond parity.

Compare UART, SPI, and I2C protocols
Feature UART SPI I2C
Wires242
Speed~1 Mbps50+ Mbps3.4 Mbps
Devices21 master, n slaves127 slaves
ClockAsyncSyncSync

Use SPI for high-speed (displays, flash memory). Use I2C for multiple sensors on 2 wires. Use UART for debug console or point-to-point communication.

What is the difference between polling and interrupts?

Polling: CPU continuously checks a flag or status register in a loop. Simple but wastes CPU cycles.

// Polling: CPU stuck here until data arrives
while(!(USART1->SR & USART_SR_RXNE));
char c = USART1->DR;

Interrupt-driven: CPU is notified by hardware when an event occurs. CPU is free for other tasks between events.

// Interrupt: CPU does other work, ISR fires on data
void USART1_IRQHandler(void) {
    if(USART1->SR & USART_SR_RXNE)
        rx_buffer[rx_head++] = USART1->DR;
}

Rule: Use polling for short, predictable waits. Use interrupts for unpredictable or latency-sensitive events.

How does SPI communication work?

SPI (Serial Peripheral Interface) is a 4-wire synchronous protocol: MOSI, MISO, SCLK, CS. Full-duplex — master and slave transmit simultaneously.

// SPI transfer: send 0xAB and receive response
CS_LOW();                        // Select slave
SPI1->DR = 0xAB;                // Send byte
while(!(SPI1->SR & SPI_SR_RXNE)); // Wait
uint8_t rx = SPI1->DR;          // Read received byte
CS_HIGH();                       // Deselect

CPOL/CPHA: Determines clock polarity (idle high/low) and phase (sample on rising/falling edge). Must match between master and slave. 4 modes: Mode 0,1,2,3.

How does I2C communication work?

I2C uses 2 open-drain lines (SDA data, SCL clock) with pull-up resistors. Each slave has a 7-bit address. Master initiates all transfers.

// I2C write to sensor at address 0x68
I2C_Start();
I2C_SendAddr(0x68, WRITE);    // Slave address + write bit
I2C_SendByte(0x6B);           // Register address (PWR_MGMT)
I2C_SendByte(0x00);           // Data: wake up MPU6050
I2C_Stop();

Speeds: Standard (100 kHz), Fast (400 kHz), Fast-plus (1 MHz), High-speed (3.4 MHz).

ACK/NACK: Receiver pulls SDA low after each byte to acknowledge. NACK ends the transaction.

What is CAN bus and where is it used?

CAN (Controller Area Network) is a robust differential serial bus designed for automotive and industrial environments. Multiple nodes share a 2-wire bus (CANH/CANL).

// CAN frame structure
| SOF | ID (11/29-bit) | RTR | DLC | Data (0-8 bytes) | CRC | ACK | EOF |

// CAN is multi-master: any node can transmit
// Built-in arbitration: lower ID wins bus contention
// Error detection: CRC, bit stuffing, ACK checking

Speeds: Up to 1 Mbps (Classical CAN), up to 5 Mbps (CAN FD).

Used in: ECUs in cars, factory automation, medical devices, aerospace.

What is the purpose of pull-up resistors in I2C?

I2C lines are open-drain — devices can only pull the line LOW, not HIGH. Pull-up resistors connect SDA and SCL to VCC so the line defaults to HIGH when no device is pulling it low.

VCC ──┬────── SDA ─── MCU / Sensor pins
     [R]           (open-drain, can pull LOW)
      │
     GND (when device pulls SDA low)

Typical values: 4.7kΩ for 100kHz, 2.2kΩ for 400kHz. Too high = slow rise time (comm errors). Too low = high current draw.

What is RS-232 vs RS-485?

RS-232: Single-ended, point-to-point serial. Voltage levels ±3V to ±15V. Max distance ~15m at 9600 baud. Used in legacy debug interfaces.

RS-485: Differential signaling. Up to 32 nodes on one bus, up to 1200m distance, up to 10 Mbps. Used in industrial Modbus networks, building automation, DMX lighting.

// RS-485: both TX and RX share same 2 wires (A/B)
// Direction control via DE/RE pin
HAL_GPIO_WritePin(DE_GPIO, DE_PIN, GPIO_PIN_SET);  // Enable TX
HAL_UART_Transmit(&huart1, data, len, 100);
HAL_GPIO_WritePin(DE_GPIO, DE_PIN, GPIO_PIN_RESET); // Enable RX
What is PWM and how is it generated in embedded systems?

PWM (Pulse Width Modulation) generates a digital signal with variable duty cycle to simulate analog output — used for motor speed, LED brightness, servo control.

// Duty cycle = (ON time / Period) × 100%
// 50% duty cycle at 1kHz → average 1.65V from 3.3V output

// STM32: 50% PWM on TIM2 CH1 at 1kHz (72MHz clock)
TIM2->PSC = 72 - 1;    // Prescaler: 72MHz/72 = 1MHz
TIM2->ARR = 1000 - 1;  // Period: 1MHz/1000 = 1kHz
TIM2->CCR1 = 500;       // Compare: 500/1000 = 50%
TIM2->CCER |= TIM_CCER_CC1E;  // Enable output

Applications: DC motor speed, servo angle (1–2ms pulse), BLDC motor control, audio generation, SMPS converters.

What is ADC and how does sampling rate affect signal quality?

ADC (Analog-to-Digital Converter) converts a continuous analog voltage into a digital value. Resolution (bits) determines precision; sampling rate determines frequency response.

// 12-bit ADC, 3.3V reference:
// Resolution = 3.3V / 4096 = ~0.8mV per step

// STM32 ADC read
ADC1->CR2 |= ADC_CR2_SWSTART;           // Start conversion
while(!(ADC1->SR & ADC_SR_EOC));        // Wait
uint16_t val = ADC1->DR;               // 0–4095
float voltage = val * 3.3f / 4095.0f;  // Convert to volts

Nyquist theorem: Sample at ≥ 2× the highest signal frequency. Sampling an audio signal at 44.1kHz captures frequencies up to 22.05kHz.

🔌

I2C Protocol - Deep Dive (25 Questions)

FREE
What is I2C, and how does it work?

I2C (Inter-Integrated Circuit) is a two-wire serial communication protocol developed by Philips Semiconductors for communicating between integrated circuits. It uses a clock signal (SCL) and a data signal (SDA) for communication and allows multiple devices to be connected to the same bus. Each device is identified by a unique address, and data is transferred in packets of 8 bits with ACK or NACK bits.

What are the advantages of using I2C over other communication protocols?

Some advantages of using I2C over other communication protocols include:

  • Simplicity - Easy to implement with just 2 wires
  • Low power consumption
  • Low cost
  • Ability to support multiple devices on the same bus
What are the limitations of I2C?

Some limitations of I2C include:

  • Slow speed compared to other communication protocols like SPI
  • Limited range due to its two-wire nature
  • Potential for signal integrity issues if the bus is not properly terminated
How many devices can be connected to an I2C bus?

The number of devices that can be connected to an I2C bus depends on the available address space. In standard mode, there are 128 possible 7-bit addresses, while in fast mode, there are 2048 possible 10-bit addresses.

What are some advanced features of I2C?

Some advanced features of I2C include:

  • Clock stretching - Allows a slave device to hold the clock line low to pause communication temporarily
  • Multi-master support - Allows multiple master devices to share control of the bus
  • Arbitration - Used to resolve conflicts if two or more masters attempt to control the bus at the same time

These features are used to improve the reliability and efficiency of I2C communication in complex systems.

What is the difference between I2C standard mode and fast mode?

I2C standard mode operates at a maximum frequency of 100 kHz, while fast mode operates at a maximum frequency of 400 kHz. Fast mode allows for faster data transfer rates but requires stronger pull-up resistors due to the higher data rate.

How is clock synchronization maintained in I2C communication?

Clock synchronization in I2C is maintained through a combination of the clock signal and the ACK/NACK bits. The master device generates the clock signal and controls the timing of data transfer, while the slave devices respond to the clock signal and send ACK or NACK bits to indicate successful or failed data transfer.

What are some common applications of I2C?

I2C is commonly used in a variety of applications, including:

  • Sensors (temperature, humidity, motion)
  • Displays (OLED, LCD)
  • EEPROMs (memory devices)
  • Other peripheral devices
  • System management applications such as power management and temperature monitoring
How do I2C devices communicate with each other?

I2C devices communicate with each other through a master-slave relationship. The master device initiates communication and sends commands or requests to the slave devices. The slave devices respond to the commands or requests by sending data back to the master device.

How does I2C compare to other communication protocols such as SPI and UART?

I2C is slower than SPI but uses fewer pins, making it useful for applications with limited board space. UART is a point-to-point communication protocol, while I2C supports multiple devices on the same bus. Each protocol has its own advantages and limitations, and the choice of protocol depends on the specific application requirements.

How is data transferred over the I2C bus, and what is the format of an I2C message?

Data is transferred over the I2C bus in packets of 8 bits. An I2C message typically consists of:

  • Start condition
  • Slave address (with read/write bit)
  • Data bytes
  • Stop condition

The master device initiates the communication by sending a start condition and then sends the slave address with the read/write bit to indicate the direction of data transfer. Data bytes are then transferred between the master and slave devices, with each byte followed by an ACK or NACK bit. The communication is terminated with a stop condition.

How does I2C support different clock speeds and data rates?

I2C supports different clock speeds and data rates through different operating modes, such as:

  • Standard mode (100 kHz)
  • Fast mode (400 kHz)
  • High-speed mode (3.4 MHz)

Additionally, I2C devices may support clock stretching, which allows the slave device to hold the clock line low to slow down the data transfer rate.

How do I2C devices handle errors and retries during communication?

I2C devices may use various error detection and correction techniques, such as CRC checking, to ensure the integrity of the data being transferred. If an error occurs, the devices may attempt to retry the communication, or the master device may send a NACK bit to indicate that the communication has failed.

What are some common issues that can arise when using I2C, and how can they be resolved?

Common issues with I2C include:

  • Noise and signal integrity issues
  • Addressing conflicts
  • Clock synchronization problems

These issues can be resolved by:

  • Using appropriate pull-up resistors
  • Terminating the bus properly
  • Selecting unique device addresses
  • Carefully controlling the timing and frequency of data transfer
What is the difference between I2C and SMBus?

SMBus (System Management Bus) is a subset of I2C that defines a specific set of protocols and features for system management applications. SMBus devices are compatible with I2C devices, but SMBus includes additional features such as extended addressing and more robust error checking.

How does clock stretching work in I2C communication?

Clock stretching is a feature of I2C that allows a slave device to hold the clock line low to slow down the data transfer rate. This can be used by the slave device to prevent the master from sending data too quickly, giving the slave device more time to process the data. The master device must wait for the clock line to go high again before continuing the communication.

What is the maximum number of devices that can be connected to an I2C bus?

The maximum number of devices that can be connected to an I2C bus depends on the address space available. I2C uses 7-bit or 10-bit device addresses, which means that a maximum of 128 or 1024 devices can be connected to the bus, respectively. However, in practice, the number of devices on the bus is usually limited by factors such as signal integrity and available board space.

What is the difference between an I2C master and an I2C slave?

An I2C master is a device that initiates communication on the bus and controls the timing of data transfer. A slave device responds to commands or requests from the master device and sends data back to the master device. Some devices, such as Microcontrollers, can operate as both a master and a slave on an I2C bus.

What is clock stretching and why is it used in I2C communication?

Clock stretching is a feature of I2C that allows a slave device to hold the clock line low to slow down the data transfer rate. This can be used by the slave device to prevent the master from sending data too quickly, giving the slave device more time to process the data. Clock stretching is particularly useful in applications where the slave device is slower than the master device or when the slave device needs more time to perform a task.

What are some of the advantages and disadvantages of using I2C communication in embedded systems?

Advantages:

  • Simplicity
  • Low pin count
  • Support for multiple devices on the same bus

Disadvantages:

  • May be slower than other communication protocols
  • Addressing conflicts can be a problem in complex systems
  • Signal integrity issues can occur
What is bus arbitration in I2C communication?

Bus arbitration is the process by which multiple devices on an I2C bus compete for control of the bus. If two or more devices try to communicate at the same time, a conflict can occur. The I2C bus has a built-in arbitration mechanism to resolve these conflicts and ensure that only one device is communicating on the bus at any given time.

How does I2C bus arbitration work?

I2C bus arbitration works by having each device on the bus monitor the bus for activity. If two or more devices try to communicate at the same time, a collision occurs and the devices compare the data that they have sent to determine which device has priority. The device that sent the highest priority data wins the arbitration and continues communicating on the bus. The other device(s) will stop communicating and wait for another opportunity to communicate.

What is priority in I2C bus arbitration?

Priority in I2C bus arbitration refers to the ability of a device to continue communicating on the bus if a conflict occurs. Devices with higher priority are able to continue communication while devices with lower priority are forced to stop communicating and wait for another opportunity to communicate. The priority of a device is determined by the content of the data that it is trying to send, with lower priority devices having to wait for higher priority devices to finish communicating.

How are priorities assigned in I2C bus arbitration?

Priorities in I2C bus arbitration are assigned based on the content of the data being sent by each device. The content of the data is divided into two categories:

  • Address - Has higher priority
  • Data payload - Has lower priority

Devices with lower addresses have higher priority than devices with higher addresses.

What happens if two devices have the same priority in I2C bus arbitration?

If two devices have the same priority in I2C bus arbitration, a collision occurs and the devices compare the data that they have sent to determine which device has priority. The device that sent the highest priority data wins the arbitration and continues communicating on the bus.

⚙️

SPI Protocol - Deep Dive (20 Questions)

FREE
What does SPI stand for and what is it used for?

SPI stands for Serial Peripheral Interface. It is a synchronous serial communication interface used for short-distance communication between devices. SPI is often used in embedded systems, especially for connecting sensors, memory devices, and other peripheral devices to a microcontroller or other host device.

What are the main differences between SPI and I2C communication?

The main differences between SPI and I2C communication are:

  • Duplex: SPI is a full-duplex interface (data in both directions simultaneously), while I2C is a half-duplex interface
  • Lines: SPI uses separate clock and data lines, while I2C uses a shared clock and data line
  • Device limit: SPI has no limit on the number of devices that can be connected to the bus, while I2C has a limit based on the number of available device addresses
What are the basic signals used in SPI communication?

The basic signals used in SPI communication are:

  • MOSI (Master Out Slave In) - the data line from the master to the slave
  • MISO (Master In Slave Out) - the data line from the slave to the master
  • SCLK (Serial Clock) - the clock line that synchronizes the data transfer
  • SS (Slave Select) - a line that allows the master to select which slave device to communicate with
What is the role of the SS line in SPI communication?

The SS (Slave Select) line in SPI communication is used to select which slave device the master wants to communicate with. The master asserts the SS line to indicate to the selected slave device that it should listen for incoming data on the MOSI line and prepare to send data on the MISO line. When the communication is complete, the master deasserts the SS line to indicate that the selected slave device should release the bus.

What is the maximum speed of SPI communication and how is it determined?

The maximum speed of SPI communication depends on the specific hardware implementation and the distance between devices. SPI communication can typically operate at speeds up to several megabits per second. The speed is determined by the clock frequency (SCLK) and the amount of time required for each device to send and receive data. In practice, the maximum speed is limited by factors such as signal integrity and the capacitance of the bus.

What is the difference between SPI mode 0 and mode 3?

In SPI communication, there are four different modes that define the polarity and phase of the clock signal. Mode 0 and mode 3 are two of these modes. The main difference between mode 0 and mode 3 is the polarity of the clock signal when the data is not being transmitted:

  • Mode 0: Clock signal is low when it is idle
  • Mode 3: Clock signal is high when it is idle
What is the role of the polarity and phase in SPI communication?

The polarity and phase of the clock signal in SPI communication define the timing relationship between the clock signal and the data signals:

  • Polarity determines whether the clock signal is high or low when it is idle
  • Phase determines whether the data is sampled on the rising edge or falling edge of the clock signal

By changing the polarity and phase, different modes of SPI communication can be achieved.

What is the difference between SPI and UART communication?

SPI and UART are both serial communication interfaces, but they are used for different purposes:

  • SPI is typically used for short-distance communication between devices
  • UART is used for communication over longer distances
  • SPI uses a separate clock line to synchronize data transfer
  • UART uses a single data line with separate start and stop bits to delimit each data packet
How does SPI handle multiple slave devices on the same bus?

SPI allows multiple slave devices to be connected to the same bus by using separate SS (Slave Select) lines for each device. The master device selects which slave device to communicate with by asserting the appropriate SS line. Only the selected slave device will respond to the master's commands, while the other devices will ignore the communication.

What is the difference between SPI and CAN communication?

SPI and CAN are both serial communication interfaces, but they are used for different purposes:

  • SPI is typically used for short-distance communication between devices
  • CAN is used for communication over longer distances in industrial and automotive applications
  • CAN has built-in error detection and correction mechanisms, while SPI does not
  • CAN allows multiple devices to communicate on the same bus without the need for a master-slave relationship, while SPI requires a master device to control the communication
Can SPI communication be used for full-duplex communication?

Yes, SPI communication can be used for full-duplex communication, meaning that data can be transmitted in both directions simultaneously. This is because SPI uses separate data lines for transmission and reception.

What is the maximum length of an SPI bus and how is it determined?

The maximum length of an SPI bus depends on several factors, such as:

  • Signal integrity of the bus
  • Capacitance of the bus
  • Voltage levels used

In general, SPI is intended for short-distance communication between devices, typically within a few meters. However, with careful design and appropriate signal conditioning, longer distances may be achievable.

Can SPI communication be used in a multi-master environment?

SPI communication is typically used in a master-slave environment, where a single master device controls communication with one or more slave devices. However, it is possible to implement SPI communication in a multi-master environment with careful coordination between the master devices. In such a scenario, each master device must be able to release the bus when it is not using it, and a mechanism for arbitration may be needed to resolve conflicts between multiple masters attempting to access the bus simultaneously.

What are some advantages of using SPI communication?

Some advantages of using SPI communication include:

  • Fast communication speeds: SPI can operate at high speeds, making it suitable for applications that require rapid data transfer
  • Low overhead: Because SPI uses separate lines for data and clock signals, there is minimal overhead associated with the communication protocol
  • Easy to implement: The simplicity of the SPI protocol makes it easy to implement in hardware and software
  • Flexible configuration: The different modes of SPI communication allow for flexibility in configuring the timing and polarity of the communication
What are some disadvantages of using SPI communication?

Some disadvantages of using SPI communication include:

  • Limited distance: SPI is typically used for short-distance communication between devices, and is not suitable for communication over long distances
  • Limited number of devices: Although SPI allows multiple devices to be connected to the same bus, the number of devices is limited by the number of available SS (Slave Select) lines
  • Lack of error detection: Unlike other serial communication protocols such as CAN, SPI does not have built-in error detection and correction mechanisms, which may make it less suitable for applications that require high reliability
What is the clock polarity and phase in SPI communication and how are they set?

The clock polarity (CPOL) and clock phase (CPHA) define the timing relationship between the clock signal and the data signals in SPI communication.

  • CPOL determines the idle state of the clock signal (i.e., whether it is high or low when not transmitting data)
  • CPHA determines whether the data is sampled on the leading (first) or trailing (second) edge of the clock signal

These settings are usually configured by the master device, which sends the appropriate control signals to the slave device(s) to set the CPOL and CPHA.

Can SPI communication be used for communication between two microcontrollers?

Yes, SPI communication can be used for communication between two microcontrollers, as long as one is configured as the master and the other as the slave. In this scenario, the master device controls the communication and sends commands and data to the slave device.

What is the role of the Slave Select (SS) line in SPI communication?

The Slave Select (SS) line in SPI communication is used to select which slave device should respond to the master's commands. When the master device asserts the appropriate SS line, the corresponding slave device will respond to the communication, while other devices on the bus will ignore the communication. The SS line is typically an active-low signal, meaning that it is low when the device is selected and high when it is not selected.

What are some common applications of SPI communication?

Some common applications of SPI communication include:

  • Interfacing with sensors and other peripheral devices
  • Memory and storage devices such as Flash memory and SD cards
  • Communication with displays and other graphical output devices
  • Audio and video processing
  • Industrial control systems and automation
What is the difference between SPI and I2C communication (Summary)?

SPI and I2C are both serial communication interfaces, but they have different characteristics and are suited to different applications:

  • Bus topology: SPI typically uses a point-to-point topology with one master and one or more slave devices, while I2C uses a bus topology that can support multiple master and slave devices
  • Communication speed: SPI can operate at higher speeds than I2C, making it suitable for applications that require rapid data transfer
  • Overhead: SPI has lower overhead than I2C, as it uses separate lines for data and clock signals, while I2C uses a single bidirectional data line
  • Device support: I2C is more widely supported by a range of devices, while SPI is generally used for communication with sensors and other peripheral devices
🔒 Premium Course

Unlock 400+ Interview
Questions

Deep-dive coverage of C programming, Operating Systems, Linux System Programming, Kernel Development, RTOS, and Advanced ARM — all in one place.

Part 1: C & Data Structures 50 questions — Pointers, memory, algorithms
Part 2: Operating Systems 50 questions — Scheduling, deadlocks, sync
Part 3: Linux System Programming 50 questions — Processes, IPC, sockets
Part 4: Embedded & ARM 50+ questions — Cortex, power, optimization
Part 5: Kernel & Device Drivers 50 questions — LKM, sync, interrupts
Part 7: RTOS & Real-Time 30 questions — Scheduling, memory, sync
₹199

One-time payment  ·  Lifetime access  ·  No subscription

Unlock Premium Course