Interface Protocols
Lightweight I²C Master Controller (Standard Mode)
A lightweight I²C master controller supporting Standard Mode (100 kHz) with configurable clock parameters and basic transaction control.
About this block
Simulate it in the Verilog IDE
Lightweight I²C Master Controller (Standard Mode) is a Verilog reference block in the Interface Protocols catalog. UART, SPI, I2C, and other serial or peripheral protocol interfaces. Marked Hard: a larger reference. Simulate the packaged testbench before you change the RTL.
This IP provides a lightweight I²C master controller supporting Standard Mode (100 kHz). It implements a state-machine-based approach for generating I²C start, address, data, and ACK/NACK conditions. The design is parameterizable for system clock frequency and target I²C clock speed.
It supports both write and read transaction sequences with basic ACK monitoring. The controller is designed for easy integration into embedded systems requiring simple I²C communication without the overhead of a full I²C peripheral.
This lightweight I²C master controller is ideal for simple embedded systems requiring Standard Mode communication. It offers a straightforward interface for initiating transactions and monitoring status flags. The parameterizable clock division allows integration with various system clock frequencies. Integrators should ensure proper pull-up resistors are connected to the SDA and SCL lines for correct operation. For detailed internal implementation, refer to the source code comments.
- Choose Open in IDE. RTL Studio loads the packaged workspace for Lightweight I²C Master Controller (Standard Mode).
- Read the Verilog module in the editor. The catalog line for this block: A lightweight I²C master controller supporting Standard Mode (100 kHz) with configurable clock parameters and basic transaction control.
- 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
- Standard Mode Support: Operates at 100 kHz I²C clock speed.
- Parameterizable: Configurable system clock (
CLK_FREQ) and I²C clock (I2C_FREQ) via Verilog parameters. - Protocol Handling: Automatically generates Start, Stop, Address, Data, and ACK/NACK conditions.
- Simple Interface: Separate control interface for transaction initiation (
start_req) and status reporting (transaction_done,ack_received). - Tri-State Management: Internally manages SDA tri-state buffers based on the I²C protocol state.
- Synthesis Ready: Simple, clean Verilog implementation suitable for FPGA and ASIC synthesis.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
clk | Input | 1 | System clock input |
rst_n | Input | 1 | Active-low asynchronous reset |
start_req | Input | 1 | Request to start a new transaction. Must be asserted for at least one clock cycle. |
slave_addr | Input | 7 | 7-bit slave address |
rw_bit | Input | 1 | 0 for Write, 1 for Read |
data_valid | Input | 1 | Valid data on tx_data for write operations. Asserted when data is ready. |
tx_data | Input | 8 | Data byte to transmit during write operations. |
rx_data | Output | 8 | Data byte received during read operations. Valid when rx_valid is asserted. |
rx_valid | Output | 1 | Indicates that rx_data is valid. Asserted when a byte is successfully received. |
ack_received | Output | 1 | Indicates if an ACK was received from the slave (0=ACK, 1=NACK). |
transaction_done | Output | 1 | Indicates transaction completion. Asserted when the transaction finishes. |
scl | Output | 1 | I²C Serial Clock line |
> Note on Read Operations: This lightweight controller supports single-byte read transactions. For multi-byte reads, the user must manage the transaction sequencing by re-asserting start_req after transaction_done is detected. The IP handles the internal tri-state switching for SDA automatically.
Architecture
The controller operates through a finite state machine that manages the I²C bus protocol. It handles clock stretching detection (basic) and generates the necessary waveforms.
Integration
### 1. Parameter Configuration Configure the clock frequencies in your instantiation or top-level module:
### 2. Hardware Requirements
- Pull-up Resistors: I²C lines (SDA and SCL) must have external pull-up resistors (typically 4.7kΩ) connected to VCC. The controller outputs tri-state signals.
- Clock Domain: Ensure
clkis stable and meets setup/hold times for the control signals.
### 3. Transaction Flow
- Assert
start_reqalong withslave_addr,rw_bit, andtx_data(if writing). - Assert
data_validiftx_datacontains valid data for a write operation. - Wait for
transaction_doneto assert. - Check
ack_receivedto verify if the slave acknowledged the transaction. - Deassert
start_reqto prepare for the next transaction.
#### Multi-Byte Transaction Example For multi-byte writes:
- Start transaction with first byte.
- Wait for
transaction_done. - If more bytes to send, assert
start_reqagain with the sameslave_addrandrw_bit, and provide the nexttx_dataanddata_valid.
Verification
The design includes a testbench (tb_i2c_master_lite.v) that validates basic write and read transactions. Simulation is performed using Icarus Verilog.
### Test Results
- TC1 (Write Transaction): PASS
- TC2 (Read Transaction): PASS
### Simulation Setup
- Install Icarus Verilog.
- Run the simulation:
iverilog -o sim tb_i2c_master_lite.v i2c_master_lite.v && vvp sim - View the VCD waveform using a compatible viewer (e.g., GTKWave, RtlStudio).
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 Bus Idle Timeout
- I2C Clock Stretch Detector
- I2C NACK Sticky Flag Detector
- I2C Start/Stop Detector
- JTAG TAP Controller
- 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)