Giter Site home page Giter Site logo

tangxifan / verilog_spi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from janschiefer/verilog_spi

0.0 0.0 0.0 18 KB

A simple Verilog SPI master / slave implementation featuring all 4 modes.

License: GNU Lesser General Public License v2.1

Verilog 89.03% Makefile 10.97%

verilog_spi's Introduction

verilog_spi - A simple verilog implementation of the SPI protocol.

I wanted to learn verilog, so I created an own SPI implementation.

Goals:

  • Easy to read, easy to understand.
  • Simple and flexible implementation.

Features:

  • SPI master / slave support
  • all 4 modes (CPOL/CHPA)
  • inverted data order support
  • custom word size support

No external IP used. Should synthesize for all FPGAs.

Tested on Lattice ICE40UP5k.

Makefile builds bitstream for WebFPGA with yosys, nextpnr, icepack and compress-bitstream (from WebFPGA toolchain). Extremely easy to modify for other FPGAs.

Usage:

Include these files in your own project:

  • spi_module.v
  • clock_divider.v (onlyif you do not have a own clock divider mechanism for the SPI clock)
  • pos_edge_det.v
  • neg_edge_det.v

Module parameters

parameter CPOL = 1'b0
parameter CPHA = 1'b0
parameter INVERT_DATA_ORDER = 1'b0
parameter SPI_MASTER = 1'b1
parameter SPI_WORD_LEN = 8 

Module instantiation

SPI master:

spi_module 
#( .SPI_MASTER (1'b1) )
spi_master
( .master_clock(Your master chip clock.),
.SCLK_OUT(WIRE_TO_SCLK_OUTPUT_PIN),
.SCLK_IN(output from clock divider fpr SPI clock.), 
.SS_OUT(WIRE_TO_SS_OUTPUT_PIN),
.SS_IN(),
.OUTPUT_SIGNAL(WIRE_TO_DATA_OUTPUT_PIN),
.processing_word(Status: Is a word being processed?), 
.process_next_word(Flag: Set to true to process the next word after the previous word has been processed.),
.data_word_send(Data bits to send.),
.INPUT_SIGNAL(WIRE_TO_DATA_INPUT_PIN),
.data_word_recv(Data bits received.),
.do_reset(Flag: Reset the module. Has to be set to 1 initially.),
.is_ready(Status: Module intialized and ready?) );

SPI slave:

spi_module 
#( .SPI_MASTER (1'b0) )
spi_slave
( .master_clock(Your master chip clock.),
.SCLK_OUT(),
.SCLK_IN(WIRE_TO_SCLK_INPUT_PIN), 
.SS_OUT(),
.SS_IN(WIRE_TO_SS_INPUT_PIN),
.OUTPUT_SIGNAL(WIRE_TO_DATA_OUTPUT_PIN),
.processing_word(Status: Is a word being processed?), 
.process_next_word(Flag: Set to true to process the next word after the previous word has been processed.),
.data_word_send(Data bits to send.),
.INPUT_SIGNAL(WIRE_TO_DATA_INPUT_PIN),
.data_word_recv(Data bits received.),
.do_reset(Flag: Reset the module. Has to be set to 1 initially.),
.is_ready(Status: Module intialized and ready?) );

THE SOFTWARE/HARDWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Happy synthesizing, Dr. med. Jan Schiefer.

verilog_spi's People

Contributors

janschiefer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.