Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

SPI master and SPI slave for FPGA written in VHDL

License

NotificationsYou must be signed in to change notification settings

jakubcabal/spi-fpga

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TheSPI master andSPI slave are simple controllers for communication between FPGA and various peripherals via the SPI interface. The SPI master and SPI slave have been implemented using VHDL 93 and are applicable to any FPGA.

The SPI master and SPI slave controllers support only SPI mode 0 (CPOL=0, CPHA=0)!

The SPI master and SPI slave controllers were simulated and tested in hardware. I use the GHDL tool for CI: automated VHDL simulations in the GitHub Actions environment (setup-ghdl-ci). If you have a question or an improvement tip, send me an e-mail or create an issue.

SPI master

Generics:

CLK_FREQ    :natural:=50e6;-- set system clock frequency in HzSCLK_FREQ   :natural:=5e6;-- set SPI clock frequency in Hz (condition: SCLK_FREQ <= CLK_FREQ/10)WORD_SIZE   :natural:=8;-- size of transfer word in bits, must be power of twoSLAVE_COUNT :natural:=1-- count of SPI slaves

Ports:

CLK      :instd_logic;-- system clockRST      :instd_logic;-- high active synchronous reset-- SPI MASTER INTERFACESCLK     :outstd_logic;-- SPI clockCS_N     :outstd_logic_vector(SLAVE_COUNT-1downto0);-- SPI chip select, active in lowMOSI     :outstd_logic;-- SPI serial data from master to slaveMISO     :instd_logic;-- SPI serial data from slave to master-- INPUT USER INTERFACEDIN      :instd_logic_vector(WORD_SIZE-1downto0);-- data for transmission to SPI slaveDIN_ADDR :instd_logic_vector(natural(ceil(log2(real(SLAVE_COUNT))))-1downto0);-- SPI slave addressDIN_LAST :instd_logic;-- when DIN_LAST = 1, last data word, after transmit will be asserted CS_NDIN_VLD  :instd_logic;-- when DIN_VLD = 1, data for transmission are validDIN_RDY  :outstd_logic;-- when DIN_RDY = 1, SPI master is ready to accept valid data for transmission-- OUTPUT USER INTERFACEDOUT     :outstd_logic_vector(WORD_SIZE-1downto0);-- received data from SPI slaveDOUT_VLD :outstd_logic-- when DOUT_VLD = 1, received data are valid

Resource usage:

LEFFM9KFmax
34230330.1 MHz

Implementation was performed using Quartus Prime Lite Edition 20.1.0 for Intel Cyclone 10 FPGA (10CL025YU256C8G) with default generics.

Simulation:

A simulation is prepared in thesim/ folder. You can use the prepared TCL script to run simulation in ModelSim.

vsim -do spi_master_tb_msim_run.tcl

Or it is possible to run the simulation using theGHDL tool. Linux users can use the prepared bash script to run the simulation in GHDL:

./spi_master_tb_ghdl_run.sh

SPI slave

Generics:

WORD_SIZE :natural:=8;-- size of transfer word in bits, must be power of two

Ports:

CLK      :instd_logic;-- system clockRST      :instd_logic;-- high active synchronous reset-- SPI SLAVE INTERFACESCLK     :instd_logic;-- SPI clockCS_N     :instd_logic;-- SPI chip select, active in lowMOSI     :instd_logic;-- SPI serial data from master to slaveMISO     :outstd_logic;-- SPI serial data from slave to master-- USER INTERFACEDIN      :instd_logic_vector(WORD_SIZE-1downto0);-- data for transmission to SPI masterDIN_VLD  :instd_logic;-- when DIN_VLD = 1, data for transmission are validDIN_RDY  :outstd_logic;-- when DIN_RDY = 1, SPI slave is ready to accept valid data for transmissionDOUT     :outstd_logic_vector(WORD_SIZE-1downto0);-- received data from SPI masterDOUT_VLD :outstd_logic-- when DOUT_VLD = 1, received data are valid

Resource usage:

LEFFM9KFmax
29210324.5 MHz

Implementation was performed using Quartus Prime Lite Edition 20.1.0 for Intel Cyclone 10 FPGA (10CL025YU256C8G) with default generics.

Simulation:

A simulation is prepared in thesim/ folder. You can use the prepared TCL script to run simulation in ModelSim.

vsim -do spi_slave_tb_msim_run.tcl

Or it is possible to run the simulation using theGHDL tool. Linux users can use the prepared bash script to run the simulation in GHDL:

./spi_slave_tb_ghdl_run.sh

Examples:

Spirit Level:

TheSpirit Level example design shows one possible use of the SPI Master controller. The example design is prepared forFPGA board CYC1000 with Intel Cyclone 10 FPGA (10CL025YU256C8G) anddigital accelerometer (LIS3DH). Here you can findthe documentation of the CYC1000 board. In this design, the SPI Master controller is used to configure and read data from the accelerometer. The LEDs on the board show the values from the accelerometer in the form of a spirit level. You can watch the Spirit Level examplevideo on YouTube.

Spirit Level example video

SPI loopback:

TheSPI loopback example design allows testing transfers between SPI master and SPI slave over external wires. The example design is prepared for FPGA boardEP4CE6 Starter Board with Altera FPGA Cyclone IV (EP4CE6E22C8), few buttons and a seven-segment display (four digit). You can watch the SPI loopback examplevideo on YouTube.

Video of SPI loopback example design

Display description (from right on board in video):

Digit0 = value on SPI slave inputDigit1 = value on SPI slave outputDigit2 = value on SPI master inputDigit3 = value on SPI master output

Buttons description (from right on board in video):

BTN_ACTION (in mode0) = setup value on SPI slave inputBTN_ACTION (in mode1) = write (set valid) of SPI slave input valueBTN_ACTION (in mode2) = setup value on SPI master inputBTN_ACTION (in mode3) = write (set valid) of SPI slave input value and start transfer between SPI master and SPI slaveBTN_MODE = switch between modes (mode0 = light decimal point on digit0,...)BTN_RESET = reset FPGA design

License:

This whole repository (include SPI master and SPI slave controllers) is available under the MIT license. Please readLICENSE file.


[8]ページ先頭

©2009-2025 Movatter.jp