Interface Protocols
I2C NACK Sticky Flag Detector
Detects I2C NACK conditions during the ACK phase and latches a sticky flag until reset.
About this block
Simulate it in the Verilog IDE
I2C NACK Sticky Flag Detector 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 I2C NACK conditions during the ACK phase of a byte transfer.
It provides two outputs: an immediate detection flag (nack_detected) and a sticky flag (nack_sticky_flag) that latches the NACK event until explicitly reset.
This module is designed for integration into I2C controllers or bus monitors to handle error conditions robustly.
- Detection: Asserts
nack_detectedwhen SDA is high (NACK) at the end of a byte transfer. - Latching: Asserts
nack_sticky_flagto latch the NACK condition. This flag remains asserted until a synchronous reset clears it.
- Normal ACK: If
is_ack_phaseis high,byte_completeis high, andsdais low, both flags remain low (or clear if previously set). - NACK Event: If
is_ack_phaseis high,byte_completeis high, andsdais high,nack_detectedgoes high immediately.nack_sticky_flagalso goes high and stays high. - Reset: An active-low
rst_nclears bothnack_detectedandnack_sticky_flagto 0.
- Choose Open in IDE. RTL Studio loads the packaged workspace for I2C NACK Sticky Flag Detector.
- Read the Verilog module in the editor. The catalog line for this block: Detects I2C NACK conditions during the ACK phase and latches a sticky flag until reset.
- 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.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
| clk | Input | 1 | Clock input |
| rst_n | Input | 1 | Active-low synchronous reset |
| sda | Input | 1 | I2C SDA line status |
| byte_complete | Input | 1 | Indicates end of 9th clock cycle |
| is_ack_phase | Input | 1 | Indicates current phase is ACK |
| nack_sticky_flag | Output | 1 | Latched NACK indicator |
| nack_detected | Output | 1 | Immediate NACK detection |
Verification
The testbench covers the following scenarios:
| Test Case | Description | Expected Result |
|---|---|---|
| TC1 | ACK Case - SDA Low during ACK phase | nack_detected is 0 |
| TC2 | NACK Case - SDA High during ACK phase | nack_detected is 1, nack_sticky_flag is 1 |
| TC3 | Sticky Flag Persistence | nack_sticky_flag remains 1 after inputs clear |
| TC4 | Reset Clears Sticky Flag | Both flags clear to 0 on reset |
### Running the Simulation
- Ensure you have a Verilog simulator installed (e.g., Icarus Verilog, ModelSim, or Vivado).
- Navigate to the project root directory.
- Run the simulation script or command provided in the
Makefileor simulation instructions. - Check the Log panel for the following output:
- TC1 PASS - ACK case correct - TC2 PASS - NACK case correct - TC2 Sticky PASS - TC3 PASS - Sticky flag persisted - TC4 PASS - Reset cleared sticky flag - TC4 Detected Clear PASS - Simulation ends with INFO: PASS.
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 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)