Full SPI Master (Configurable mode)

Advanced
Sign in →
00:00
01General Operation

The module implements a configurable SPI master supporting all 4 SPI modes (0 to 3) via CPOL and CPHA parameters derived from the g_MODE_SPI generic.

A transaction is triggered by i_spi_com_rqst. The module handles TX serialization (MSB first), RX deserialization, SPI clock generation and slave selection. TX and RX sizes are independent and configurable per transaction.

Generics:

GenericTypeDefaultDescription
g_MODE_SPInatural3SPI mode (0 to 3). Bits (1) and (0) of its 2-bit conversion give CPOL and CPHA
g_CK_PER_HF_SPIpositive3System clock cycles per SPI clock half-period
g_SHIFT_SPI_CLKpositive2Shift of o_sck relative to internal clock (in ticks). Must be < g_CK_PER_HF_SPI - 1
g_NB_SLAVEpositive1Number of SPI slaves
g_DATA_2RC_SIZEpositive32Max receive data size (bits)
g_DATA_2SD_SIZEpositive32Max transmit data size (bits)

The SPI clock is derived from the system clock by division, with a half-period of g_CK_PER_HF_SPI cycles. The SPI mode determines clock polarity and phase. The output clock o_sck is shifted by g_SHIFT_SPI_CLK cycles relative to the internal clock.

The transaction starts on i_spi_com_rqst. The module selects the slave, serializes TX data, deserializes RX data and signals completion via o_data_rec_valid. During transmission, o_spi_busy='1'.

02Interface
SignalDirectionWidthDescription
i_clkInput1System clock
i_rstInput1Active-high synchronous reset
o_sckOutput1SPI clock (shifted by g_SHIFT_SPI_CLK ticks)
o_ss_nOutputg_NB_SLAVEActive-low Slave Select
i_misoInput1Master In Slave Out
o_mosiOutput1Master Out Slave In ('Z' when idle)
o_data_rec_validOutput11-cycle pulse: received data valid
o_data_receivedOutputg_DATA_2RC_SIZEReceived data
o_frame_full_okOutput11-cycle pulse: frame complete
i_spi_com_rqstInputg_NB_SLAVECommunication request (1 bit per slave, 1-cycle pulse)
i_data_2sendInputg_DATA_2SD_SIZEData to transmit
i_data_2send_sizeInputf_log2(g_DATA_2SD_SIZE)Number of bits to transmit
i_data_2rec_sizeInputf_log2(g_DATA_2RC_SIZE)Number of bits to receive