wb_spimaster - A Wishbone SPI Master Engine for FPGAs
This is the project homepage for wb_spimaster, an SPI master engine for the Wishbone bus, written in VHDL.
Last updated: $Date: 2013/01/05 20:45:48 $.
The wb_spimaster module is a configurable SPI master engine which can be controlled from the Wishbone bus interface. It allows the user to configure several SPI parameters.
The SPI master engine is made up of a shift engine component which controls the SPI bus. The Wishbone interface is provided by a front-end entity to that shift engine.
Using the wb_spimaster component in your VHDL design is as easy as declaring and instantiating any other component. Below is the VHDL entity declaration of the component.
The design is customizable through a few generics, which are described in the following table.
|dat_sz||Width of Wishbone data bus. This also determines the size of the engine's registers. The module will probably not work if this generic is set to a value < 8.|
|slv_bits||Determines how many SPI slaves are supported by the module. The module will support (2 ^ slv_bits) SPI slaves. Example: If the generic is set to 3, the module will support up to eight SPI slaves. The module cannot support more slaves than the value of the dat_sz generic.|
The module supports Wishbone classic read and write cycles. It will generate a response within one clock cycle. The response output, i.e. ack or err is asserted as long as the module's stb input is active. Because the module generates a response within one cycle, it does never drive the stall output. Nevertheless, it should support Wishbone classic pipelined read and write cycles, too, but that hasn't been tested so far.
The module exposes four registers which are described in the table below.
|0x00||Rx/Tx Data||Data written to this register will be transferred out of the SPI engine during the next transfer. Data shifted into the SPI engine during the last transfer can be read from this register.|
|0x01||Control||SPI engine control registers. The meanings of the bits are described in the table below.|
|0x02||nSEL||Value of the engine's SPI nSEL output pins.|
|0x03||Divider||SPI clock divider. The SPI clock is derived from the logic clock and divided by this factor, i.e. setting this register to a value of 8 will cause the SPI clock to run at 1/8 of the logic clock frequency.|
The module's control register allows the user to adjust SPI parameters and control the transfer.
|0..2||Count||Determines how many bits will be shifted on the next SPI transfer.|
|4||CPOL||Controls the SPI clock polarity (CPOL).|
|5||CPHA||Controls the SPI clock phase (CPHA).|
|7||Start/Busy||Setting this bit starts an SPI transfer. While the SPI transfer is in progress, this bit will read back active. Once the SPI transfer has completed, the bit is cleared. Attempts to set this bit while already set, i.e. an SPI transfer is in progress, will cause an err response on the Wishbone bus.|
Below are the links to the VHDL file(s).
Here are a few links related to this project.
- Wikipedia Article on the Wishbone Bus.
- The Wishbone Bus Specification, Rev. B4
- Wikipedia Article on the Serial Peripheral Interface Bus.
Contact the author Philip Schulz by Email.