Skip to main content

I2C Slave Responder & Pull-up Logic

I2C Slave Responder & Pull-up Logic


Implementing the Slave Side

Part 3 of 5: SystemVerilog I2C Master Design

Slave vs. Master Responsibilities

In I2C, the master initiates and controls timing, while the slave responds. Let's break down who does what:

Task Master Slave
Generate START condition ✓ —
Generate SCL clock pulses ✓ Can stretch by holding LOW
Transmit address byte ✓ Monitor & match address
Generate STOP condition ✓ —
Send data bits (write) ✓ Sample & store
Receive data bits (read) Sample & store ✓ Drive SDA
Generate ACK/NACK Receives ACK after write ✓ Sends ACK after receive
Passive Responder: In our testbench, the slave is a passive simulator that responds to master-generated clock. Real silicon slaves use state machines to handle clock stretching and multi-byte transactions independently.

Address Matching Logic

After START, the master sends an 8-bit address byte. The slave must listen to bits [7:1] and compare against its programmed address.

Address Matching State Machine

Phase 1: Receive 7 bits

  • Master sends bits [7:1] of address
  • Slave samples SDA on each SCL rising edge
  • Shifts bits into a receive register

Phase 2: Compare

  • After 7th bit, compare received address with programmed slave_addr
  • If match: set address_match = 1
  • If no match: slave ignores rest of transaction

Phase 3: R/W Bit (8th bit)

  • Master sends R/W flag (0 = write, 1 = read)
  • Slave stores this to determine transaction type

SystemVerilog Address Matching

always @(posedge scl_in) begin if (address_phase) begin if (bit_counter < 7) begin // Collect 7 address bits rx_addr[7-bit_counter] <= sda_in; bit_counter <= bit_counter + 1; end else if (bit_counter == 7) begin // 8th bit = R/W flag rw_bit <= sda_in; // Compare address if (rx_addr[7:1] == slave_addr) begin address_match <= 1'b1; end bit_counter <= 0; address_phase <= 1'b0; end end end

ACK Bit Generation

After receiving 8 bits, the slave must pull SDA LOW during the 9th clock pulse to signal ACK.

Timing Requirements for ACK

Bits: 1-8 (data/addr) 9 (ACK) SCL: _|‾‾|_|‾‾|_|‾‾|_ ... |_|‾‾|_ SDA: data_bits |delay| ACK |---| t_SU:ACK

Setup Time (tSU:ACK): SDA must go LOW before SCL rises for the 9th bit. Minimum = 250 ns (in real hardware).

ACK Generation Logic

always @(posedge scl_in) begin if (bit_counter == 8) begin // Just received 8th bit, now send ACK on 9th clock ack_pending <= 1'b1; end else if (bit_counter == 9 && ack_pending) begin // Send ACK sda_out <= 1'b0; // Pull SDA LOW ack_pending <= 1'b0; end else if (scl_falling) begin // Release SDA after SCL falls sda_out <= 1'b1; end end
Timing Pitfall: ACK must be generated before SCL rises for bit 9. Generating it after SCL is already HIGH will violate setup time, and the master won't see it.

Pull-up Resistor Simulation

In synthesis, I2C lines use real pull-up resistors. In simulation, we model them as continuous assignments:

// Model external pull-ups (in testbench) assign scl_in = (scl_out == 1'b0 || scl_held_low) ? 1'b0 : 1'b1; assign sda_in = (sda_out == 1'b0 || sda_held_low) ? 1'b0 : 1'b1;

Why This Model?

  • Wired-AND behavior: If any device pulls the line LOW, it stays LOW.
  • No explicit resistor: We don't need to simulate RC charging curves; a simple "open-drain OR gate" is sufficient.
  • Fast simulation: No analog computations; purely digital logic.

Extended Pull-up Model (with Slew Rate)

For timing-critical designs, you can add a simple slew-rate model:

real scl_voltage = 3.3; real scl_rise_time = 100e-9; // 100 ns rise time always @(posedge clk) begin if (scl_out == 1'b0) begin scl_voltage <= 0; // Hard pull end else if (scl_voltage < 3.3) begin scl_voltage <= scl_voltage + 3.3 / (scl_rise_time / 1e-8); end end // Threshold detection assign scl_logic = (scl_voltage > 1.65) ? 1'b1 : 1'b0;
For Testbenches: Start with the simple model. Only add slew-rate modeling if timing-based bugs appear in simulation.

SDA Data Bit Driving

When the master sends a READ command, the slave drives data bits onto SDA while the master controls SCL.

Read Transaction Timing

Master: SCL: _|‾|_|‾|_|‾|_ (controls clock) Slave (read): SDA: ‾‾\__/‾‾\__/‾ (drives data) bit_0 bit_1

Slave Read-Mode Logic

always @(posedge clk) begin if (rw_bit == 1'b1) begin // READ transaction - slave drives data if (scl_falling) begin // Setup data while SCL is LOW sda_out <= data_to_send[7 - bit_counter]; end end end

Sequence for Slave-Driven Bit

  1. SCL falls: Slave sets up SDA for next bit (setup time)
  2. SCL rises: Master samples SDA and reads bit
  3. SCL falls again: Slave prepares next bit
No Clock Stretching from Slave in Read: In our simple testbench slave, the slave doesn't hold SCL. In real designs, a slave might hold SCL LOW if it needs processing time between bits.

Slave Responder SystemVerilog

Here's a complete slave module skeleton:

module i2c_slave_responder ( input clk, input rst_n, // I2C bus input scl_in, input sda_in, output reg sda_out, // Configuration input [6:0] slave_addr, input [7:0] data_to_send, // Status output reg address_match, output [7:0] data_received ); // Synchronizers (double-flop) reg [1:0] scl_sync, sda_sync; wire scl_stable = scl_sync[1]; wire sda_stable = sda_sync[1]; // State machine reg [3:0] bit_counter; reg [7:0] rx_addr; reg rw_bit; reg address_phase; reg ack_pending; always @(posedge clk or negedge rst_n) begin if (~rst_n) begin address_match <= 1'b0; sda_out <= 1'b1; address_phase <= 1'b1; end else begin // Address matching on SCL rising edge if (scl_rising) begin if (address_phase) begin rx_addr[7-bit_counter] <= sda_stable; if (bit_counter == 7) begin rw_bit <= sda_stable; address_match <= (rx_addr == {slave_addr, 1'b0}); address_phase <= 1'b0; end bit_counter <= bit_counter + 1; end end // ACK generation if (ack_pending) begin sda_out <= 1'b0; // Pull SDA for ACK ack_pending <= 1'b0; end else if (scl_falling) begin sda_out <= 1'b1; // Release after SCL falls end end end endmodule

Key Takeaways

Key Takeaways

  • Master controls timing; slave responds passively (in standard mode).
  • Address matching happens on first 7 bits after START; slave ignores rest if no match.
  • ACK/NACK is generated by pulling SDA LOW during the 9th clock pulse (ACK) or releasing it (NACK).
  • Pull-up simulation uses wired-AND logic: if ANY device pulls LOW, the line is LOW.
  • Data bit timing: Slave sets up data on SCL falling edge; master samples on SCL rising edge.
  • Double-flop synchronizers prevent metastability when sampling async bus lines.
  • Open-drain outputs ensure multiple slaves and masters can share the bus safely.

What's Next?

In Part 4, we'll design a comprehensive testbench with 10 test cases covering START/STOP, address matching, data transmission, ACK/NACK, and error scenarios.

Ready to test it all? See you in Part 4!

About the author: Upalparna is a VLSI engineer and design verification specialist with expertise in functional verification, UVM testbenches, and protocol design. She runs The Silicon Stack, a VLSI education platform, and teaches embedded systems and semiconductor design.

Questions or feedback? Drop a comment below or connect on LinkedIn.

Series Navigation:
Part 1: Protocol Fundamentals →
Part 2: Master Controller FSM →
Part 3: Slave Responder & Pull-up Logic (You are here)
Part 4: Testbench Design & Test Cases
Part 5: Interview Prep & Optimization

 

Comments

Popular posts from this blog

Module 1 — SystemVerilog Basics

VLSI Verification  •  SystemVerilog Series Module 1 — SystemVerilog Basics A complete, example-driven walkthrough of SystemVerilog fundamentals: data types, variables vs nets, arrays of every flavor, strings, enums, structs, unions, and typedef — the building blocks every verification engineer needs before UVM. 🧩 Beginner → Intermediate ⏱ ~25 min read 💻 Code Examples Included 📑 Table of Contents Introduction to SystemVerilog Verilog vs SystemVerilog Data Types: 2-State vs 4-State Logic Variables and Nets Arrays: Packed vs Unpacked Dynamic Arrays Queues Associative Arrays Strings Enumerations Structures Unions Typedef 1 Introduction to SystemVerilog SystemVerilog (IEEE 1800) is a unified hardware description and verification language (HDVL). It extends Verilog (IEEE 1364) with powerful constructs for design (interfaces, always_comb/always_ff, enhanced d...

Clock Domain Crossing (CDC): A Complete Beginner's Guide to Metastability, Synchronizers & Safe Data Transfer

Clock Domain Crossing (CDC): A Complete Beginner's Guide to Metastability, Synchronizers & Safe Data Transfer Modern System-on-Chip (SoC) designs rarely operate with a single clock. Instead, different modules such as CPUs, GPUs, memory controllers, communication interfaces, and peripherals often run at different clock frequencies or even use completely independent clock sources . When data moves from one clock domain to another, timing uncertainty can cause serious problems such as metastability , data corruption , and unpredictable system behaviour . This challenge is known as Clock Domain Crossing (CDC) . CDC is one of the most important topics in ASIC Design , RTL Design , ASIC Verification , FPGA Design , and SoC Architecture . Every modern chip—from smartphones to automotive processors—uses CDC techniques to ensure reliable communication between multiple clock domains. In this article, we'll explore CDC fundamentals, metastability, synchronization techniques, asynchro...

GPU Memory System & Interconnect: How Data Travels Inside a Modern GPU

GPU Memory System & Interconnect: How Data Travels Inside a Modern GPU Modern GPUs deliver incredible computing power by processing thousands of operations simultaneously. While compute cores often receive the spotlight, the real performance of a GPU depends heavily on how efficiently data moves between memory and compute units. A GPU memory system is designed to provide extremely high bandwidth while keeping latency as low as possible. This is achieved through a collection of specialized hardware components working together, including the Memory Controller, HBM/GDDR memory, Crossbar, Network-on-Chip (NoC), DMA Engine, PCIe Interface, and NVLink. In this article, we'll explore each component in detail and understand how they collectively enable high-performance parallel computing. Why Does GPU Memory Matter? Every GPU application—from gaming and graphics rendering to AI model training and scientific simulations—requires continuous movement of enormous amounts of data. For examp...

AXI Verification Interview Questions and Real-World Debugging

AMBA Protocol Series · Part 10 of 10 AXI Verification Interview Questions and Real-World Debugging Common protocol violations, how to read them off a waveform, and a curated set of interview questions with concise, correct answers — the capstone of the core 10-day series. AMBA Protocol Series: From APB & AHB to AXI — A Complete Guide for VLSI Engineers This wraps up the core 10-day series. Everything here draws directly on Days 1–9 — if any answer below feels unfamiliar, that's a good signal for which earlier post to revisit. (If you want to go further, see the 20-day extended list at the end of this post.) In This Article Common Protocol Violations Debugging From a Waveform Interview Questions and Answers Series Recap Extending the Series 1. Common Protocol Violations VALID deasserted before handshake — a source drops VALID before READY ever went high (violates the Day 8 stabi...

Timing Basics in Static Timing Analysis (STA): Delay Models, Sequential Timing, and Wire Delays

Timing Basics in Static Timing Analysis (STA) Static Timing Analysis (STA) is one of the most important verification techniques used in modern VLSI design. Before a chip is manufactured, engineers must verify that every signal reaches its destination within the required clock period. Even if a design passes functional simulation, it may still fail after fabrication because of timing violations. Unlike simulation, Static Timing Analysis mathematically analyzes every timing path without applying input test vectors. This makes STA significantly faster and capable of analyzing millions of timing paths efficiently. Table of Contents What is Static Timing Analysis? Why STA is Required Propagation Delay Contamination Delay Cell Delay Models Combinational Gate Delay Sequential Timing Setup Time Hold Time Wire Delay RC Delay Model PVT Corners Worked Examples Interview Questions Key Takeaways What is Static Timing Analysis? Static Ti...

Cache Basics and Cache Mapping Techniques

  Cache Basics and Cache Mapping Techniques  Modern processors execute billions of instructions every second. However, processor speed has increased much faster than main memory (RAM) speed. This difference, known as the memory wall , creates a performance bottleneck because the CPU often has to wait for data from slower memory. To solve this problem, computer systems use cache memory —a small, high-speed memory located between the CPU and the main memory. In this article, we will understand the fundamentals of cache memory, the principle of locality, cache organization, and the three major cache mapping techniques. What is Cache Memory? Cache memory is a small, high-speed memory that stores copies of frequently accessed data from the main memory. Since accessing cache is much faster than accessing RAM, the CPU first checks whether the required data is available in the cache. If the data is found in the cache, it is called a cache hit . Otherwise, the CPU fetches the dat...

CMOS Power & Scaling Explained: Dynamic Power, Leakage Power, Short-Circuit Power & Technology Scaling

  CMOS Power & Scaling Explained: Dynamic Power, Leakage Power, Short-Circuit Power & Technology Scaling Day 6 | CMOS Design Fundamentals | The Silicon Stack As integrated circuits continue to become smaller, faster, and more powerful, power consumption has emerged as one of the biggest challenges in modern VLSI design. While early digital circuits primarily focused on functionality and speed, today's processors, AI accelerators, smartphones, and IoT devices must deliver high performance while operating within strict power and thermal limits. A modern System-on-Chip (SoC) may contain billions of CMOS transistors , each switching billions of times per second. Even a tiny amount of power consumed by each transistor adds up to significant energy consumption across the entire chip. Excessive power not only drains batteries but also generates heat, reduces reliability, and limits performance. Understanding where CMOS power comes from and how it can be reduced is therefore ...