SPI Main (Master) Core

Runtime-configurable SPI main for any FPGA.

Overview

The SPI Main core drives an SPI bus from FPGA logic. SPI mode (CPOL, CPHA) and the SCLK divider are set at runtime, so one build serves devices with different bus settings. Word width is a generic: 8, 16 or 32 bits. Several words can be sent under one chip select. The MISO input is double-registered before use.

Features

  • All four SPI modes; CPOL and CPHA set at runtime
  • 16-bit clock divider: SCLK = fclk / (2·(div+1))
  • MSB first
  • Word width 8, 16 or 32 bits, selected by generic
  • Multi-word frames under one chip select
  • Double-registered MISO input
  • Single clock domain; synchronous active-high reset; std_logic-only ports; no vendor primitives
  • Self-checking testbenches included

Block diagram

SPI Main core block diagramHost configuration (CPOL, CPHA, divider), transmit word and start enter a control state machine, which returns the received word and busy/done status. The state machine drives a 16-bit clock divider producing SCLK, a transmit shift register producing MOSI, a receive shift register fed from MISO through a two flip-flop synchroniser, and the chip select output CS_N.spi_mainCPOL, CPHA, div[15:0]tx word [W-1:0]startrx word [W-1:0]busy / doneControl FSMframe, CS,bit countClock divider16-bitTX shift registerW bits, MSB firstRX shift registerW bits2-FFsyncSCLKMOSIMISOCS_N
Fig. 1 SPI Main core, functional view. clk and rst reach every block and are not drawn. W = word width generic.

Specifications

ParameterValue
HDLVHDL, synthesizable
Clock domains1 (fclk)
ResetSynchronous, active-high
SPI modes0, 1, 2, 3; CPOL/CPHA at runtime
Bit orderMSB first
Word width8, 16 or 32 bits (generic)
SCLK divider16-bit; SCLK = fclk / (2·(div+1))
FramesMulti-word under one chip select
MISO inputDouble-registered
Port typesstd_logic only
Vendor primitivesNone
VerificationSelf-checking testbenches

Interface

PortDirWidthDescription
clkin1System clock, fclk
rstin1Synchronous reset, active-high
cpolin1Clock polarity
cphain1Clock phase
clk_divin16SCLK divider value
startin1Start a transfer
tx_datainWWord to send
rx_dataoutWWord received
busyout1Transfer in progress
sclkout1SPI clock
cs_nout1Chip select, active low
mosiout1Main out, subordinate in
misoin1Main in, subordinate out
Port list for orientation; the datasheet is authoritative. W = word width generic.

Performance

TransferSCLK ratio@ fclk = 40 MHz@ fclk = 100 MHz
Writefclk/220 MHz50 MHz
Read-backfclk/66.67 MHz16.7 MHz
Verified in simulation. Maximum SCLK on hardware also depends on board, I/O timing and the connected device.

Resource utilisation

DeviceLUTsFFsFmax
AMD 7 SeriesPublished after synthesis — ask sales
Altera CyclonePublished after synthesis — ask sales
Lattice ECP5Published after synthesis — ask sales

Supported targets

Vendor-neutral VHDL with no vendor primitives or constraints. The source licence targets any family listed under supported FPGA vendors, including NI LabVIEW FPGA targets through the IP Integration Node. An evaluation netlist is built for one named device and toolchain version.

Deliverables

ItemEvaluationSource licence
Delivered asNetlist for one named device + toolchainVHDL source + testbenches
DocumentationDatasheetDatasheet, integration guide, testbench guide
UseEvaluation only, [terms to fill in]Production, [terms to fill in]
Full terms: Licensing & evaluation.

Documentation

DocumentFormatAvailability
SPI Main (Master) Core — DatasheetPDFPublic
Integration guidePDFWith source licence
Testbench guidePDFWith source licence