SPI Core Specifications: Author: Richard Herveille
SPI Core Specifications: Author: Richard Herveille
OpenCores
1/7/2003
Revision History
Rev. 0.1 Date 07/01/02 Author Richard Herveille Description First Draft
www.opencores.org
OpenCores
1/7/2003
Table of contents
INTRODUCTION........................................................................................................1 IO PORTS.....................................................................................................................2 REGISTERS .................................................................................................................4 OPERATION................................................................................................................8 ARCHITECTURE .....................................................................................................10
www.opencores.org
OpenCores
1/7/2003
1
Introduction
The OpenCores simple Serial Peripheral Interface core is an enhanced version of the Serial Peripheral Interface found on Motorola's M68HC11 family of CPUs. The Serial Peripheral Interface is a serial, synchronous communication protocol that requires a minimum of 3 wires. Enhancements to the original interface include a wider supported operating frequency range, 4 entries deep read and write FIFOs, and programmable transfer count dependent interrupt generation. The high compatibility with the M68HC11 SPI port ensures that existing software can use this core without major modifications. New software can use existing examples as a starting point. The core features an 8 bit wishbone interface. FEATURES:
Compatible with Motorolas SPI specifications Enhanced M68HC11 Serial Peripheral Interface 4 entries deep read FIFO 4 entries deep write FIFO Interrupt generation after 1, 2, 3, or 4 transferred bytes 8 bit WISHBONE RevB.3 Classic interface Operates from a wide range of input clock frequencies Static synchronous design Fully synthesizable
www.opencores.org
1 of 40
OpenCores
1/7/2003
2
IO ports
2.1 WISHBONE Interface Connections
Port clk_i rst_i inta_o cyc_i stb_i adr_i we_i dat_i dat_o ack_o Width 1 1 1 1 1 2 1 8 8 1 Direction Input Input Output Input Input Input Input Input Output Output Description Master clock input Asynchronous active low reset Interrupt request signal Valid bus cycle Strobe/Core select Lower address bus bits Write enable Data input Data output Normal bus termination
2.1.1 clk_i All internal WISHBONE logic is registered to the rising edge of the [clk_i] clock input. 2.1.2 rst_i The active low asynchronous reset input [rst_i] forces the core to restart. All internal registers are preset and all state-machines are set to an initial state. 2.1.3 inta_o The interrupt request output is asserted when the core needs service from the host system. 2.1.4 cyc_i When asserted, the cycle input [cyc_i] indicates that a valid bus cycle is in progress. The logical AND function of [cyc_i] and [stb_i] indicates a valid transfer cycle to/from the core. 2.1.5 stb_i The strobe input [stb_i] is asserted when the core is being addressed. The core only responds to WISHBONE cycles when [stb_i] is asserted, except for the [rst_i], which always receive a response. 2.1.6 adr_i The address array input [adr_i] is used to pass a binary coded address to the core. The most significant bit is at the higher number of the array.
www.opencores.org
2 of 40
OpenCores
1/7/2003
2.1.7 we_i When asserted, the write enable input [we_i] indicates that the current bus cycle is a write cycle. When negated, it indicates that the current bus cycle is a read cycle. 2.1.8 dat_i The data array input [dat_i] is used to pass binary data from the current WISHBONE Master to the core. All data transfers are 8 bit wide. 2.1.9 dat_o The data array output [dat_o] is used to pass binary data from the core to the current WISHBONE Master. All data transfers are 8 bit wide. 2.1.10 ack_o When asserted, the acknowledge output [ack_o] indicates the normal termination of a valid bus cycle.
2.2.1 sck_o SCK [sck_o] is generated by the master device and synchronizes data movement in and out of the device through the MOSI [mosi_o] and MISO [miso_o] lines. The SPI clock is generated by dividing the WISHBONE clock [clk_i]. The division factor is software programmable. 2.2.2 mosi_o The Master Out Slave In line is a unidirectional serial data signal. It is an output from a master device and an input to a slave device. 2.5.3 miso_i The Master In Slave Out line is a unidirectional serial data signal. It is an output from a slave device and an input to a master device.
M68HC11 compatibility The M68HC11 features a Slave Select signal. To reduce resource usage, this core does not. Use a GPIO core, like the OpenCores simple_gpio core, to generate the Slave Select signal(s), if this functionality is required.
www.opencores.org
3 of 40
OpenCores
1/7/2003
3
Registers
3.1 Registers List
Name SPCR SPSR SPDR SPER adr_i[1:0] 0x00 0x01 0x02 0x03 Width 8 8 8 8 Access R/W R/W R/W R/W Description Control Register Status Register Data Register Extensions Register
3.2.1 SPIE Serial Peripheral Interrupt Enable When the Serial Peripheral Interrupt Enable is set (1) and the Serial Peripheral Interrupt Flag in the status register is set, the host is interrupted. Setting this bit while the SPIF flag is set generates an interrupt. 0 = SPI interrupts disabled 1 = SPI interrupts enabled 3.2.2 SPE Serial Peripheral Enable When the Serial Peripheral Enable bit is set (1), the core is enabled. When it is cleared (0), the core is disabled. The core only transfers data when the core is enabled. 0 = SPI core disabled 1 = SPI core enabled 3.2.3 MSTR Master Mode Select When the Master Mode Select bit is set (1), the core is a master device. When it is cleared (0), it is a slave device. Currently only master mode is supported. This bit is set, and can not be cleared. 0 = Slave mode 1 = Master mode
www.opencores.org
4 of 40
OpenCores
1/7/2003
3.2.4 CPOL Clock Polarity The Clock Polarity bit, together with the Clock Phase bit, determines the transfer mode. Refer to the SPI Transfers section for more information 3.2.5 CPHA Clock Phase The Clock Phase bit, together with the Clock Polarity bit, determines the transfer mode. Refer to the SPI Transfers section for more information. 3.2.6 SPR SPI Clock Rate Select These bits select the SPI clock [sck_o] rate. Refer to the ESPR bits in the Extension Register for more information.
3.3.1 SPIF Serial Peripheral Interrupt Flag The Serial Peripheral Interrupt Flag is set upon completion of a transfer block. If SPIF is asserted (1) and SPIE is set, an interrupt is generated. To clear the interrupt write the status register with the SPIF bit set (1). 3.3.2 WCOL Write Collision The Write Collision flag is set when the Serial Peripheral Data register is written to, while the Write FIFO is full. To clear the Write Collision flag write the status register with the WCOL bit set (1). 3.3.3 WFFULL Write FIFO Full The Write FIFO Full and Write FIFO empty bits show the status of the write FIFO. 3.3.4 WFEMPTY Write FIFO Empty The Write FIFO Full and Write FIFO empty bits show the status of the write FIFO. 3.3.5 RFFULL Read FIFO Full The Read FIFO Full and Read FIFO empty bits show the status of the read FIFO. 3.3.6 RFEMPTY Read FIFO Empty The Read FIFO Full and Read FIFO empty bits show the status of the read FIFO.
www.opencores.org
5 of 40
OpenCores
1/7/2003
3.5.1 ICNT Interrupt Count The Interrupt Count bits determine the transfer block size. The SPIF bit is set after ICNT transfers. Thus it is possible to reduce kernel overhead due to reduced interrupt service calls. ICNT 00 01 10 11 Description SPIF is set after every completed transfer SPIF is set after every two completed transfers SPIF is set after every three completed transfers SPIF is set after every four completed transfers
www.opencores.org
6 of 40
OpenCores
1/7/2003
3.5.2 ESPR Extended SPI Clock Rate Select The Extended SPI Clock Rate Select bits add two bits to the SPI Clock Rate Select bits. When ESPR = 00 the original M68HC11 coding is used. ESPR 00 00 00 00 01 01 01 01 10 10 10 10 11 SPR 00 01 10 11 00 01 10 11 00 01 10 11 xx Divide WISHBONE clock by 2 4 16 32 8 64 128 256 512 1024 2048 4096 Reserved
NOTE Do not use the reserved 11xx values; using those leads to unpredictable results.
www.opencores.org
7 of 40
OpenCores
1/7/2003
4
Operation
4.1 SPI Transfers
During an SPI transfer, data is simultaneously transmitted and received. The serial clock line [SCK] synchronizes shifting and sampling of the information on the two serial data lines. The master places the information onto the MOSI line a half-cycle before the clock edge that the slave device uses to latch the data. Four possible timing relationships can be chosen by using the Clock Polarity [CPOL] and Clock Phase [CPHA] bits in the Serial Peripheral Control Register [SPCR]. Both master and slave devices must operate with the same timing.
SCK (CPOL=0) SCK (CPOL=1) MOSI(CPHA=0) MOSI(CPHA=1)
MSB MSB LSB LSB
www.opencores.org
8 of 40
OpenCores
1/7/2003
while it is full overwrites the oldest data byte. Writing to the Serial Peripheral Data Register [SPDR] while the Write Buffer if full sets the WCOL bit, however the damage is already done; the next byte to be transferred is not the oldest data byte, but the latest (newest).
WP
3 2 1 0
WP RP
3 2 1 4
RP
Note that a maximum sequence of 4 bytes can be stored in the Read Buffer before the oldest data byte gets overwritten. It is therefore necessary to empty (read) the Read Buffer every 4 received bytes.
www.opencores.org
9 of 40
OpenCores
1/7/2003
5
Architecture
SPCR WISHBONE Interface SPER SPSR SPDR Timing Generator Control Statemachine Shift Register sck_o
miso_i
mosi_o
www.opencores.org
10 of 40