FPGA Implementation of SPI Bus Communication Based
FPGA Implementation of SPI Bus Communication Based
Abstract. The SPI bus is a synchronous serial interface data bus with full duplex, few signal
lines, simple protocol, and fast transmission speed. Based on these characteristics, parallel
high-speed computing with FPGA is used to meet device expansion and experiment in
high-rate environments. This paper introduces the structure and working principle of SPI
communication bus, analyzes its timing structure and four working modes, and uses this state
machine method to realize its SPI bus communication function on FPGA. The module circuit
of SPI is written by Verilog hardware description language, and the waveform is simulated in
vivado simulator. After the simulation waveform analysis, the feasibility of the state machine
method is verified.
1. Introduction
SPI, the Serial Peripheral Interface, is a synchronous serial interface technology introduced by
Motorola. The SPI bus is physically implemented by a module called a Synchronous Serial Port on a
microprocessor control unit (MCU) connected to a peripheral microcontroller (PIC micro) [1], which
allows MCU performs high-speed data communication with various peripheral devices in full-duplex
synchronous serial mode.
Among many serial buses, SPI mid-line has great advantages compared with other common buses
such as I2C bus, CAN bus, USB, etc. For example, the data transmission speed of SPI bus can reach
several Mbps, which is faster than other serial buses obviously [2-3]. SPI is mainly used in EEPROM,
Flash, Real Time Clock (RTC), Digital to Analog Converter (ADC), Digital Signal Processor (DSP)
and Digital Signal Decoder [4].
In this paper, we introduce the structure and working principle of SPI communication bus, analyze
its timing structure and four working modes, and uses this state machine method to realize its SPI bus
communication function on FPGA. The module circuit of SPI is written by Verilog hardware
description language, and the waveform is simulated in vivado simulator.
2. SPI protocol
Content from this work may be used under the terms of the Creative Commons Attribution 3.0 licence. Any further distribution
of this work must maintain attribution to the author(s) and the title of the work, journal citation and DOI.
Published under licence by IOP Publishing Ltd 1
ISPECE 2019 IOP Publishing
Journal of Physics: Conference Series 1449 (2020) 012027 doi:10.1088/1742-6596/1449/1/012027
provided by the master device to the slave device through the SCK pin. The slave device itself cannot
be generated. Or control the clock, the Slave device does not work without the clock [5].
SCL
MOSI
Master Slave
MISO
CS
2
ISPECE 2019 IOP Publishing
Journal of Physics: Conference Series 1449 (2020) 012027 doi:10.1088/1742-6596/1449/1/012027
CPHA=0
SCLK1 CPCL=0
CPHA=1
SCLK2 CPCL=0
CPHA=0
SCLK3 CPCL=1
CPHA=1
SCLK4 CPCL=1
3
ISPECE 2019 IOP Publishing
Journal of Physics: Conference Series 1449 (2020) 012027 doi:10.1088/1742-6596/1449/1/012027
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
SCLK
CS
bo bo bo bo
MOSI 0 1 2 3
bo
4
bo
5
bo
6
bo
7
bi bi bi bi bi bi bi bi
MISO 0 1 2 3 4 5 6 7
SCK=1 SCK=0
mosi=data_in
R_tx_done=1'b1 TX_DATA1
R_tx_state+1'b1
TX_DATA2
4
ISPECE 2019 IOP Publishing
Journal of Physics: Conference Series 1449 (2020) 012027 doi:10.1088/1742-6596/1449/1/012027
The figure above shows the state machine block diagram of the transmission process. After a byte
data is transmitted, a transmission completion flag O_tx_done is generated and the CS/SS signal is
pulled high to complete a transmission. By observing the above state, it can be found that the state in
which the state number is odd is actually the same, so when the code is written, in order to streamline
the code, the state with the odd state number can be integrated.
Receive: When the FPGA receives one byte (8-bit) of data from the slave through the SPI bus, the
FPGA first sets the CS/SS chip select signal to 0, indicating that it is ready to start receiving data. The
whole process of receiving data can also be divided. It is 16 states, but unlike the sending process, in
order to ensure that the received data is accurate, it must be sampled in the middle of the data.
After receiving one byte of data, a reception completion flag O_rx_done is generated and the
CS/SS signal is pulled high to complete the reception of the data. By observing the above state, it can
be found that the state in which the state number is even is actually the same, so when the code is
written, in order to streamline the code, the state with the even number of states can be integrated. And
this is just the opposite of the state of the sending process.
5. Conclusion
SPI has full-duplex, low signal lines, simple protocol, fast transmission speed, etc., which makes it
widely used in the field of data transmission. This simple and easy-to-use feature, more and more
chips integrate this communication. Agreement. This paper first introduces the communication
protocol of SPI, designs a SPI host module conforming to the SPI bus specification with Verilog
hardware description language, and performs functional simulation. The SPI host module has the
correct function, stable operation and strong scalability. Due to the wide range of applications of the
SPI bus and the advantages of FPGA reconfigurability, the module can be easily extended with
hardware as needed to increase its functionality.
References
[1] F. Leens, (2009) An Introduction to I2C and SPI Protocols. In: IEEE Instrumentation &
Measurement Magazine. Beijing. pp. 8-13.
5
ISPECE 2019 IOP Publishing
Journal of Physics: Conference Series 1449 (2020) 012027 doi:10.1088/1742-6596/1449/1/012027
[2] S. Wang, (2010) Design and Implementation of Serial Peripheral Interface SPI Based on FPGA.
Control & Automation, pp.117-119.
[3] W.L.Li, D.P. Y. (2007) Implementation of Asynchronous Serial Port and Synchronous Serial Port
Conversion Using FPGA. Electronic Engineer, pp.52-53.
[4] S.Zhang, W.Li. (2014) Modular design method of FPGA. Journal of Electronic Measurement and
Instrument, pp. 560-565.
[5] F.J.Sun, C.X.Yu.(2005) Verilog Implementation of SPI Serial Bus Interface. Modern Electronic
Technique, pp. 105-106,109.
[6] W.Mai, W.Liu. (2007) Design and Implementation of SPI Interface Based on FPGA and MSP430.
Instrumentation Users, pp. 100-102.
[7] W.C.Zhu, S. ,Zhang, H.L.Jiang. (2017) Design of high speed data communication interface based
on ARM and FPGA. Journal of Guilin University of Electronic Technology, pp. 293-297.