RTL Studio Open IDE

Interface Protocols

SPI Mode-0 Host (8-Bit Frames)

SPI host/controller operating in CPOL=0 CPHA=0 with 8-bit shift frames.

About this block

Simulate it in the Verilog IDE

Hardverilogsimsyn

SPI Mode-0 Host (8-Bit Frames) 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.

A lightweight, parameterizable SPI host controller implementing Mode 0 (CPOL=0, CPHA=0). This IP core facilitates 8-bit data transfers between a master and slave device, generating the necessary SCK signal from a system clock.

This IP provides a robust, synchronous SPI host interface suitable for basic peripheral communication. It features a parameterizable clock divider for flexible speed control, a clear state machine architecture, and includes a self-checking testbench for immediate verification. The design is optimized for simplicity and reliability in low-to-medium throughput applications.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for SPI Mode-0 Host (8-Bit Frames).
  2. Read the Verilog module in the editor. The catalog line for this block: SPI host/controller operating in CPOL=0 CPHA=0 with 8-bit shift frames.
  3. Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
  4. 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

  • SPI Mode 0 Support: Implements standard SPI Mode 0 (Idle Low, Sample on Rising Edge).
  • 8-Bit Data Width: Transfers 8-bit data words MSB-first.
  • Parameterizable Clock: Configurable CLK_DIV parameter to adjust SCK frequency relative to clk.
  • Synchronous Design: Uses a synchronous state machine for reliable timing and easy integration.
  • Verified: Includes a comprehensive self-checking testbench with waveform dump support.

Ports

Port NameDirectionWidthDescription
clkInput1System clock input
rst_nInput1Active-low asynchronous reset
startInput1Start transfer pulse (single cycle)
tx_dataInput8Data to transmit
doneOutput1Transfer complete flag (high during DONE state)
rx_dataOutput8Received data
sckOutput1SPI clock output
mosiOutput1Master Out Slave In
misoInput1Master In Slave Out

Architecture

The design is composed of three main blocks:

  1. Clock Divider: Generates the SPI bit clock (sck) from the system clock (clk) based on the CLK_DIV parameter.
  2. State Machine: Controls the transfer sequence through three states: IDLE, SHIFT, and DONE_S.
  3. Shift Register Logic: Handles data loading, shifting out on mosi, and sampling from miso.

### Data Flow

  • Data is loaded into the shift register when start is asserted.
  • Bits are shifted out MSB-first on mosi.
  • Bits are sampled from miso on the rising edge of sck.
  • The done signal asserts when the transfer is complete.

Verification

The included testbench (tb_simple_spi_host.v) verifies functional correctness.

### Test Cases

Test CaseTX DataMISO DataExpected RXResult
TC10x550x550x55PASS
TC20xAA0xAA0xAAPASS
TC30x000x000x00PASS
TC40xFF0xFF0xFFPASS
TC50xAB0xAB0xABPASS
TC60x000xFF0xFFPASS
TC70xFF0x000x00PASS

### Running Simulation

  1. Run the simulation in your preferred EDA tool.
  2. Check the log output for INFO: PASS.
  3. Inspect sim/dump.vcd using the waveform viewer for timing analysis.

### Expected Log Output

Integration

  • Chip Select: This IP does not handle chip select (CS); you must manage CS externally to ensure the slave is selected during the transfer.
  • Timing Constraints: Ensure setup and hold times for the external miso signal relative to sck are met by the slave device.
  • Reset Synchronization: The rst_n is asynchronous. Ensure your system reset logic synchronizes rst_n if crossing clock domains.
  • Start Signal: The start signal should be a single-cycle pulse. If held high, the controller may initiate multiple transfers depending on implementation details; it is recommended to de-assert start immediately after assertion.

More in Interface Protocols

All Interface Protocols blocks