Interface Protocols
I2C Bus Idle Timeout
Detects I2C bus idle conditions based on SCL and SDA levels with configurable threshold.
About this block
Simulate it in the Verilog IDE
I2C Bus Idle Timeout is a Verilog reference block in the Interface Protocols catalog. UART, SPI, I2C, and other serial or peripheral protocol interfaces. Marked Medium: more state or a wider datapath, still one workspace in the IDE.
This IP core detects when an I2C bus remains idle for a configurable number of clock cycles. It monitors the SCL and SDA lines for the I2C idle state (both high) and asserts a flag when the idle duration exceeds a user-defined threshold.
The design is fully synchronous, synthesizable, and verified using Icarus Verilog.
This IP core provides a robust mechanism for detecting I2C bus idle conditions using a configurable saturating counter. It is designed for easy integration into larger systems, offering clear ports for clock, reset, I2C lines, and configuration. The design is fully verified with a testbench that covers reset, counting, activity detection, and re-accumulation scenarios.
- Choose Open in IDE. RTL Studio loads the packaged workspace for I2C Bus Idle Timeout.
- Read the Verilog module in the editor. The catalog line for this block: Detects I2C bus idle conditions based on SCL and SDA levels with configurable threshold.
- Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
- Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.
RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.
Features
- Idle Detection: Monitors SCL and SDA lines for the I2C idle condition (SCL=1, SDA=1).
- Configurable Threshold: Allows setting the idle timeout via a 4-bit input (
threshold_i). - Saturating Counter: Prevents counter overflow by saturating at the threshold value.
- Activity Reset: Immediately resets the counter and idle flag upon any bus activity (SCL=0 or SDA=0).
- Synthesizable: Designed for standard CMOS synthesis flows.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
clk | input | 1 | System clock input |
rst_n | input | 1 | Active-low asynchronous reset |
scl_i | input | 1 | I2C Serial Clock line |
sda_i | input | 1 | I2C Serial Data line |
threshold_i | input | [3:0] | Idle cycle threshold (0-15) |
idle_o | output | 1 | High when idle count >= threshold |
count_o | output | [3:0] | Current idle cycle count |
Architecture
The module uses a synchronous counter to track consecutive cycles where both SCL and SDA are high.
- Reset: On
rst_nlow,count_oandidle_oare reset to 0. - Idle Condition: If
scl_iandsda_iare both high, the counter increments. - Saturation: If
count_oreachesthreshold_i, it stays saturated at that value. - Activity: If either
scl_iorsda_igoes low, the counter resets to 0 andidle_odeasserts. - Output:
idle_oasserts high whencount_o>=threshold_i.
Verification
### Prerequisites
Install [Icarus Verilog](https://iverilog.icarus.com/).
### Running Simulation
### Expected Output
- Reset Behavior: Ensures outputs are zero after reset.
- Count Accumulation: Verifies counter increments during idle.
- Activity Reset: Confirms counter resets on bus activity.
- Re-accumulation: Checks counter resumes counting after activity stops.
More in Interface Protocols
- 1-Bit GPIO Pin Driver (Combinational) — L1 Upgrade — L2 Upgrade
- 32-Bit MMIO GPIO (DI Read, Byte-Strobed DO) — L2 Upgrade
- 8-Bit GPIO Output Register
- 8-Bit GPIO Set/Clear Register
- 8-Bit GPIO with Direction and Rising-Edge IRQ
- I2C Arbitration Lost Detector
- I2C Clock Stretch Detector
- I2C NACK Sticky Flag Detector
- I2C Start/Stop Detector
- JTAG TAP Controller
- Lightweight I²C Master Controller (Standard Mode)
- Lightweight I²C Slave Controller (Standard Mode)
- SPI Master Lite
- SPI Mode-0 Host (8-Bit Frames)
- SPI Mode-3 Slave (CPOL=1, CPHA=1) 8-Bit
- SPI Slave Controller (Mode 0)