Implementation of 8-Bit SPI Protocol Using System Verilog and UVM
Implementation of 8-Bit SPI Protocol Using System Verilog and UVM
Abstract: Currently, the design and verification of peripheral devices [1 – 3]. Data exchange in SPI occurs
efficient communication protocols are essential in between a master device and one or more slave devices.
embedded systems. This paper focuses on the When data is transmitted by a device, incoming data must be
development and verification of an 8-bit Serial read before the next transmission can occur, ensuring that
Peripheral Interface (SPI) protocol using System Verilog data exchange is continuous and synchronized [4]. In SPI,
and Universal Verification Methodology (UVM). SPI, a each device must be capable of both transmitting and
popular protocol in embedded communication, enables receiving data. The master device governs the clock line
high-speed, synchronous, full-duplex data transfer (SCK), controlling data exchange between devices through
this clock line. Serial Peripheral Interface (SPI) is a
between a master and one or more slave devices. By
commonly used critical communication protocol in a variety
utilizing SystemVerilog for hardware modeling and
of embedded systems. It also enables high-speed
UVM for a modular, reusable testbench framework, this synchronous data transfer between devices. The main
approach enhances the verification process's efficiency objective is to enable efficient, dependable communication,
and accuracy. Various operational scenarios for the SPI especially in systems where pin count is critical. This study
protocol are tested, ensuring robust performance in focuses on developing an 8-bit SPI protocol with System
communication systems. Verilog, a strong hardware description and verification
language In scenarios such as processor-to-processor and
Keywords- SPI Protocol, SystemVerilog, Universal processor-to-peripheral communication, data integrity and
Verification Methodology (UVM), VLSI Design, speed are critical.
Embedded Systems, Communication Protocols, Modular
Testbench The methodology for
implementing and verifying the SPI protocol is based on
two key approaches: System Verilog for coding the protocol
I. INTRODUCTION and Universal Verification Methodology (UVM) for
System-on-chip designs typically include a wide verification. System Verilog allows for precise hardware
range of peripherals, such as analog-to-digital converters modeling of the SPI protocol, and UVM provides a
(ADCs), registers, memory units, and digital-to-analog standardized testbench framework for comprehensive and
converters (DACs). As a result, efficient data transmission systematic verification of the communication system. Using
and reception between these connected peripherals are these protocols guarantees that the design is robust and
essential for SoC functionality. The Serial Peripheral performs properly in a variety of scenarios. UVM also offers
Interface (SPI) is one of the most widely used serial a verification environment that is reusable and scalable
protocols for both inter-chip and intra-chip low-to-medium which results in improving verification efficiency and
speed data transfers. SPI facilitates communication between simplifies the testing procedure. Nonetheless, the SPI
processors and devices like external EEPROMs, DACs, protocol's lack of a flow control mechanism and addressing
ADCs, and similar components. In the landscape of scheme restricts its use in increasingly complex systems. In
communication protocols, SPI is often referred to as a addition, the slave devices have to obey the master's
"small" protocol. It's crucial to recognize the unique role of
commands to the letter, and in multi-slave deployments, it
each protocol; for instance, Ethernet, USB, and SATA are
designed for "outside-the-box communications," supporting can be challenging to manage several devices due to the
data exchange between entire systems. In contrast, SPI is absence of a formal addressing structure [5 – 7]. While
specifically designed for interconnecting integrated circuits System Verilog offers a versatile and powerful solution to
for low-to-medium speed data transfer on-board with implementing the 8-bit SPI protocol, UVM verification
1893
Authorized licensed use limited to: INDIAN INSTITUTE OF TECHNOLOGY DELHI. Downloaded
979-8-3315-2963-5/24/$31.00 on April
©2024 IEEE 19,2025 at 09:21:47 UTC from IEEE Xplore. Restrictions apply.
Proceedings of the Fourth International Conference on Ubiquitous Computing and Intelligent Information Systems (ICUIS-2024)
IEEE Xplore Part Number: CFP24UG3-ART; ISBN: 979-8-3315-2963-5
allows for scalability and reuse. Method 1, which is direct slave is not selected, the MISO line is held in a high-
implementation with System Verilog, has the advantage of impedance state. Master Out Slave In (MOSI): Through the
having more control over hardware modeling, but it may MOSI line, the master transmits data to the slave in a serial,
lack systematic testing. Method 2, which uses UVM, one-way direction, also starting with the MSB. In SPI, the
addresses this issue by providing a reusable, modular rising or falling clock edges dictate when data is sent and
verification environment, which necessitates additional received by the master and slave, respectively. SPI
learning and setup time [8]. By comparing various methods, Communication setup where a single SPI Master device is
we hope to demonstrate how combining them can overcome connected to multiple SPI Slave devices (four in this case),
allowing the master to communicate with each slave
limits such as debugging complexity and increase overall
individually over a shared bus. The SPI protocol utilizes four
system verification efficiency [9 -11]. The novelty of the
main signal lines: SCLK (Serial Clock), MOSI (Master Out
project is unlike previous works that primarily focused on Slave In), MISO (Master In Slave Out), and SS (Slave
SystemVerilog and UVM, our paper uniquely integrates Select). The SCLK line, generated by the master, is a clock
both methodologies to deliver a comprehensive and robust signal that coordinates the timing of data transmission
verification framework. between the master and all slaves. This clock signal is shared
among all slave devices to ensure synchronized data transfer.
II. SPI PROTOCOL
The MOSI line is used by the master to send data to the
The Serial Peripheral Interface (SPI) is a widely used slaves, allowing it to transmit information in a serial format.
communication protocol, offering synchronous, full-duplex Each slave listens on this line, but only the selected slave
data transmission at high speeds over short distances— processes the data being sent. Conversely, the MISO line is
typically between devices on the same circuit board. As used by the active slave to send data back to the master,
shown in the figure 1, SPI is commonly employed to enable creating a two-way communication link. To avoid conflicts
communication between microcontrollers or when multiple slaves are connected to the same MISO line,
microprocessors and various peripherals [12]. To ensure only the select slave drives the line, while the others remain
synchronized data transmission and reception, SPI requires a in a high-impedance (tri-state) state, effectively
clock signal. Operating in a master-slave configuration, SPI disconnecting them from the line to prevent data overlap or
supports both single master-single slave and single master- interference. When the master pulls one of these SS lines
multiple slave architectures. Communication between low, it enables the corresponding slave to communicate,
while the other slaves remain inactive. For example, if the
master and slave devices occurs over a synchronous clock
master wants to communicate with the first slave, it pulls
signal generated by the master. Only four signal lines are SS1 low, activating only that slave and keeping others in
needed for communication between master and slave standby mode. This selective activation enables the master to
devices in SPI [14 -15]. communicate with multiple slaves over shared MOSI and
MISO lines without causing data conflicts. Once the slave is
selected, the master initiates data transfer over a series of
clock pulses.
In a typical 16-bit SPI setup, the master
and active slave exchange 16 bits of data in a full-duplex
manner, meaning data is sent on the MOSI line from the
master to the slave while, at the same time, data from the
slave is sent to the master over the MISO line. The SS
(Slave Select) lines play a crucial role in this configuration,
as they allow the master to select and activate a specific
slave for communication. Each slave has its dedicated SS
line, which is controlled directly by the master. When the
master pulls one of these SS lines low, it enables the
corresponding slave to communicate, while the other slaves
remain inactive. For example, if the master wants to
communicate with the first slave, it pulls SS1 low,
activating only that slave and keeping others in standby
mode. Each slave module would also have logic to drive the
Fig. 1. SPI Protocol MISO line with its data output when active. The use of shift
SPI consists of four primary signals: Serial Clock (SCK) registers in both the master and slave modules is a common
This clock signal synchronizes data transmission between the approach to handling serial data transfer, ensuring the
master and slave over the MOSI and MISO lines. An entire correct timing and format for 8-bit data frames.
byte of data is exchanged between master and slave within
eight clock cycles, with SCK generated by the master and III. PROPOSED ARCHITECTURE
serving as the input clock for the slave. Chip Select (CS) / (a) System Verilog Architecture
Slave Select (SS): This line selects the slave device for
communication. It remains active-low during data transfer The System Verilog testbench architecture provides a
[6-8]. Master In Slave Out (MISO): Through the MISO line, structured, modular approach to verifying a Design
the master receives data from the slave. Data is transmitted
Under Test (DUT), as shown in the figure 2. At the
serially, with the most significant bit (MSB) sent first. If the
highest level is the Top Module, which instantiates the
`
1894
Authorized licensed use limited to: INDIAN INSTITUTE OF TECHNOLOGY DELHI. Downloaded
979-8-3315-2963-5/24/$31.00 on April
©2024 IEEE 19,2025 at 09:21:47 UTC from IEEE Xplore. Restrictions apply.
Proceedings of the Fourth International Conference on Ubiquitous Computing and Intelligent Information Systems (ICUIS-2024)
IEEE Xplore Part Number: CFP24UG3-ART; ISBN: 979-8-3315-2963-5
DUT and the Environment, setting up the necessary detailed insights into which parts of the DUT have been
connections for simulation. The Environment serves as tested. By setting specific coverage goals, the
a container for essential verification components, verification team can identify any untested scenarios
organizing and grouping them to ensure modularity and and adjust the stimulus to achieve comprehensive
reusability. Within the Environment, the Agent contains coverage, ensuring that every critical path in the DUT is
several critical sub-components, including the exercised. Another powerful aspect of this architecture
Generator, BFM (Bus Functional Model), Monitor, and is the use of Assertions, which are embedded within the
Coverage components. The Generator creates stimulus testbench to check for expected behavior in real time.
or test patterns, which are often randomized or Assertions act as checkpoints during simulation, quickly
constrained to simulate a wide range of operating identifying protocol violations or incorrect behavior by
scenarios and passes these patterns to the BFM. verifying that signals follow specified timing, order, or
Acting as an interface between the testbench state transitions. This immediate feedback accelerates
and the DUT, the BFM converts the high-level debugging and enhances the accuracy of test results.
transactions from the Generator into pin-level signals System Verilog also supports Randomization and
that drive the DUT inputs. Meanwhile, the Monitor Constraints in stimulus generation, enabling the creation
passively observes the communication between the of complex, varied test scenarios that help expose
BFM and the DUT, capturing output data without corner cases that may not be covered by manual test
interfering with the simulation. This data is then sent to patterns. Randomization introduces a degree of
the Scoreboard, which compares it with expected unpredictability in test patterns, while constraints guide
outputs to verify the DUT's functionality, checking for this randomness to ensure valid transactions within the
any mismatches and logging errors. DUT’s expected operating parameters. Additionally,
Virtual Interfaces are used in the testbench to simplify
connections between components and increase
modularity. Virtual interfaces allow different testbench
components to access shared signals dynamically,
making it easier to swap modules or reconfigure the
testbench for different DUT configurations.
`
1895
Authorized licensed use limited to: INDIAN INSTITUTE OF TECHNOLOGY DELHI. Downloaded
979-8-3315-2963-5/24/$31.00 on April
©2024 IEEE 19,2025 at 09:21:47 UTC from IEEE Xplore. Restrictions apply.
Proceedings of the Fourth International Conference on Ubiquitous Computing and Intelligent Information Systems (ICUIS-2024)
IEEE Xplore Part Number: CFP24UG3-ART; ISBN: 979-8-3315-2963-5
`
1896
Authorized licensed use limited to: INDIAN INSTITUTE OF TECHNOLOGY DELHI. Downloaded
979-8-3315-2963-5/24/$31.00 on April
©2024 IEEE 19,2025 at 09:21:47 UTC from IEEE Xplore. Restrictions apply.
Proceedings of the Fourth International Conference on Ubiquitous Computing and Intelligent Information Systems (ICUIS-2024)
IEEE Xplore Part Number: CFP24UG3-ART; ISBN: 979-8-3315-2963-5
`
1897
Authorized licensed use limited to: INDIAN INSTITUTE OF TECHNOLOGY DELHI. Downloaded
979-8-3315-2963-5/24/$31.00 on April
©2024 IEEE 19,2025 at 09:21:47 UTC from IEEE Xplore. Restrictions apply.
Proceedings of the Fourth International Conference on Ubiquitous Computing and Intelligent Information Systems (ICUIS-2024)
IEEE Xplore Part Number: CFP24UG3-ART; ISBN: 979-8-3315-2963-5
[3] P.R. Reddy, P. Sreekanth and K.A. Kumar, "Serial peripheral interface-
master universal verification component using UVM", International
Table 3 Code Coverage of Slave Module Journal of Advanced Technologies in Engineering and Management
Sciences, Vol. 3, 2017.
[4] Veda Patil, Vijay Dahake, Dharmesh Verma, Elton Pinto,
“Implementation of SPI Protocol in FPGA” International Journal Of
Computational Engineering Research, Vol. 3, 2013
[5] M.Sandyal, K.Rajasekhar, “Design and Verification of Serial Peripheral
Interface”, Vol. 3, Issue. 4, 2012
[6]K.Aditya, M.Sivakumar, Fazal Noorbasha,T.Praveen Blessington
” Design and Functional Verification of a SPI Master Slave Core Using
System Verilog”, Vol. 2, Issue. 2, 2012
[7] K.V. Ashok Kumar, M. Santhosh Krishna,” Design and Functional
Verification of a SPI Master Slave Core using UVM”, Vol. 04, Issue.
Table 1 shows the mode of operation and Table 2 illustrates 51, 2015
[8] Rahul Jandyam, Sanjay Reddy Kandi, Umar Farooq
the code coverage details of the SPI master functional Mohammad,” Design and Implementation of Spi Module in Verilog
module. Table 3 shows the code coverage details of the SPI HDL using FPGA design Flow”, Vol. 5, Issue. 4, 2017
slave functional module. The SPI protocol operates in four [9] K. Aditya, M. Sivakumar, Fazal Noorbasha, T.PraveenBlessington,
“Design and Functional Verification of a SPI Master Slave Core Using
distinct modes, determined by the Clock Phase (CPHA) and System Verilog,”, Vol. 2, 2012.
Clock Polarity (CPOL) settings. In Mode 0 (CPHA = 0, [10] Abhijeet Kumar,” Implementation of Low Power SPi Protocol with
CPOL = 0), the clock polarity is low, and data is sampled on Clock Domain Crossing, Vol. 1, Issue. 2, 2014.
[11] Aman Kulkarni, S.M. Sakthivel,” UVM methodology based functional
the rising edge and shifted out on the falling edge. Mode 1 verification of SPI protocol”,2020.1-3, 1 Aug 2016.
(CPHA = 1, CPOL = 0) also has a low clock polarity, but [12] Anuradha, M. Saravanan, “ Design and Development of a Portable
data is sampled on the falling edge and shifted out on the ECG Acquisition System” International Journal of Advanced Research
in Computer and Communication Engineering, Vol. 5, Issue 2, 2016
rising edge. Mode 2 (CPHA = 0, CPOL = 1) sets the clock
[13] P.M. Aarthi; A. Dinesh; T. Janani; V.Ananth Kumar; M. Saravanan; J.
polarity to high, where data is sampled on the rising edge Ajayan, “Study of Performance of High-Speed Low-Power Differential
and shifted out on the falling edge. Finally, Mode 3 (CPHA Input Based Dynamic Comparator Using 22 nm CMOS Technology”
DOI: 10.1109/ICACCS48705.2020.9074441, April 2020
= 1, CPOL = 1) also has a high clock polarity, with data [14] G Ramesh, P Manikandan, P Naveen, M Saravanan, SR Ashok
being sampled on the falling edge and shifted out on the Kumar, C Swedheetha, “Energy efficient high-performance
adder/subtractor circuits” 2022 3rd International Conference on Smart
rising edge. Each mode offers different timing for data Electronics and Communication (ICOSEC), pp 333-338, 2022
sampling and shifting based on the phase and polarity [15] M Saravanan, KA Balasuriya, D Deepak Raj, B Dharun, R Dinesh
configuration. Kumar, Palanichamy Naveen, “ Design and Implementation of 32-bit
Signed Divider for VLSI Applications”, 2023 7th International
Conference on Electronics, Communication and Aerospace
V. CONCLUSION Technology (ICECA), pp 316-320, 2023
REFERENCES
`
1898
Authorized licensed use limited to: INDIAN INSTITUTE OF TECHNOLOGY DELHI. Downloaded
979-8-3315-2963-5/24/$31.00 on April
©2024 IEEE 19,2025 at 09:21:47 UTC from IEEE Xplore. Restrictions apply.