What You'll Learn
FSM Overview & State Diagram
The I2C Master Controller uses a 6-state finite state machine to manage all bus operations. Each state corresponds to a distinct phase of communication.
State Machine Properties
- Total states: 6 (IDLE, START_COND, STOP_COND, TX_DATA, RX_DATA, ACK_BIT)
- Clock domain: System clock (10 MHz in our design)
- Output control: SCL and SDA driven independently via open-drain logic
- Collision detection: Monitors for unexpected SDA changes
- Clock stretching: Holds SCL LOW until all slaves release it
Detailed State Descriptions
State 1: IDLE
Purpose: Bus is free; no transaction in progress.
| Signal | Value | Meaning |
|---|---|---|
| SCL | 1 (HIGH) | Released via pull-up |
| SDA | 1 (HIGH) | Released via pull-up |
| busy | 0 | No transaction |
| error | 0 | No errors detected |
Transitions:
- → START_COND: When
start_cond_reqasserted
State 2: START_COND
Purpose: Generate START condition (SDA falls while SCL HIGH).
Sequence:
- Wait for SCL to reach HIGH (SCL = 1 after release)
- Pull SDA LOW (sda_out = 0)
- Wait for SDA to stabilize LOW
- Transition to next state
State 3: TX_DATA
Purpose: Transmit 8-bit data byte (most significant bit first).
Bit Transmission Sequence (for each bit):
- Set up SDA (sda_out = bit_to_send)
- Release SCL (scl_out = 1) → Pull-up brings SCL HIGH
- Wait for SCL to stabilize HIGH (with clock stretching tolerance)
- Check for collision: if SDA changed unexpectedly → error = 1
- Pull SCL LOW (scl_out = 0)
- Move to next bit
error = 1.
State 4: RX_DATA
Purpose: Receive 8-bit data byte from slave.
Bit Reception Sequence (for each bit):
- Release SDA (sda_out = 1) → Slave can drive if bit = 0
- Release SCL (scl_out = 1) → Slave can hold it LOW for clock stretching
- Wait for SCL HIGH
- Sample SDA (sda_in) and store in receive buffer
- Pull SCL LOW (scl_out = 0)
- Move to next bit
State 5: ACK_BIT
Purpose: Generate or monitor the 9th bit (ACK/NACK).
Master Send ACK (slave expects more data):
- Pull SDA LOW (sda_out = 0)
- Release SCL → Slave reads ACK
Master Send NACK (slave should stop):
- Release SDA (sda_out = 1)
- Release SCL → Slave reads NACK
Transitions:
- → TX_DATA: Next byte to transmit
- → RX_DATA: Next byte to receive
- → STOP_COND: End of transaction
State 6: STOP_COND
Purpose: Generate STOP condition (SDA rises while SCL HIGH).
Sequence:
- Pull SCL LOW (scl_out = 0)
- Release SCL (scl_out = 1) → SCL goes HIGH
- Wait for SCL stabilization
- Release SDA (sda_out = 1) → SDA rises to HIGH
- Return to IDLE
Edge Detection & Synchronization
Since SCL and SDA are asynchronous inputs (pulled via external resistors), we must synchronize them before using in the FSM.
Double-Flop Synchronizer
Rising/Falling Edge Detection
Open-Drain Output Logic
The key to I2C's wired-AND property is open-drain outputs:
Collision Detection Logic
If master releases SDA but reads it as LOW, another device is driving it:
SCL Clock Generation
SCL frequency is derived from system clock using a divider counter:
SystemVerilog Implementation
Here's a simplified FSM excerpt showing state transitions:
case statements with clear state naming (enums in SV).
Avoid mixing synchronous and asynchronous logic in the same always block.
Keep FSM state transitions event-driven (edge detection preferred over level sensing).
Key Takeaways
- The I2C Master uses a 6-state FSM to manage all bus phases.
- Edge detection via double-flop synchronizers prevents metastability.
- Open-drain logic enables wired-AND behavior and collision detection.
- SCL clock generation uses dividers to derive I2C speed from system clock.
- Each state has clear entry/exit conditions for deterministic behavior.
- Collision detection monitors for unexpected line changes during transmission.
- Clock stretching tolerance allows slaves to hold SCL LOW indefinitely.
Part 1: Protocol Fundamentals →
Part 2: Master Controller FSM (You are here)
Part 3: Slave Responder & Pull-up Logic
Part 4: Testbench Design & Test Cases
Part 5: Interview Prep & Optimization

Comments
Post a Comment