0% found this document useful (0 votes)
53 views

Beginning FPGA Programming - Partie70

This chapter discusses two-way communication between a Raspberry Pi and FPGA using SPI. It describes connecting the devices, defining the SPI slave interface in the FPGA with clock, slave select, MOSI and MISO pins, and designing an SPI slave module in VHDL.

Uploaded by

ali alilou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Beginning FPGA Programming - Partie70

This chapter discusses two-way communication between a Raspberry Pi and FPGA using SPI. It describes connecting the devices, defining the SPI slave interface in the FPGA with clock, slave select, MOSI and MISO pins, and designing an SPI slave module in VHDL.

Uploaded by

ali alilou
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Chapter 14 ■ How Fast Can You Run? Ask the Accelerometer!

14.4 Summary
In this chapter, we showed you the steps to create your own interface IP and we created a complicated
command list for the SPI from the UART interface. It is important to define the requirements first and then
define the port list. The last step is going to create the VHDL process (sequential and combination logic)
based on the requirements.
We created a generic SPI master interface module. It supports a very wide range of SPI clock frequencies
and it is programmable at runtime. The module only does one byte at a time, which is the basic unit for SPI
interfaces. This allows higher-level software/hardware to create different read/write operations for different
SPI slaves.
In the SPI master module, we only used one 17-bit counter, one 4-bit counter, two 8-bit shift registers,
and some registers. This helps to demonstrate that creating an interface module is not all that difficult.

“The only way to do great work is to love what you do.”


—Steve Jobs

343
PART IV

Taking It Further: Talking to the


Raspberry Pi and LED Displays
CHAPTER 15

Two-Way Communications with


Your Raspberry Pi: SPI

15.1 Introduction
We are going to use the Raspberry PI SPI (Serial Peripheral Interface) master to control the BeMicro MAX10
LEDs (light-emitting diodes). We need to design an SPI slave interface in the FPGA (field-programmable gate
array) to let the Raspberry PI control the LEDs on the board. In the following section, we will show you how
to connect a Raspberry Pi to BeMicro MAX10 board, design an SPI slave for the FPGA, and write a simple
Python script to run on the Raspberry Pi that will do two-way communication on the SPI interface.

Figure 15-1.  SPI two-way communication between Raspberry Pi and MAX10 FPGA block diagram

15.2 Define Our SPI Slave Interface for the Raspberry Pi


We are going to design a four-pin SPI slave device for the FPGA. The four pins are clock, slave select (or chip
select), MOSI (master output slave input), and MISO (master input slave output). In Chapter 13, we had
the same signals but in reverse. In this design, the clock, slave select, and MOSI are inputs to the FPGA and
MISO is an output from FPGA.

© Aiken Pang and Peter Membrey 2017 347


A. Pang and P. Membrey, Beginning FPGA: Programming Metal, DOI 10.1007/978-1-4302-6248-0_15
Chapter 15 ■ Two-Way Communications with Your Raspberry Pi: SPI

There are some general purpose input/output pins (GPIO) on the BeMicro MAX10 board labeled pin
header 5 (J5). We need to find four pins available from J5 for the SPI to use. Table 15-1 shows the pins we
selected from the FPGA and Raspberry Pi. We will use the Raspberry Pi SPI0 CE1 Master to talk with the
FPGA SPI slave on J5. Figure 15-2 shows both the FPGA and Raspberry Pi pin locations with color codes.
Black is the ground. It is very important to connect the ground pins first before you make another pin
connection. Yellow is the CLOCK. Orange is the SLAVE SELECT. RED is the MOSI. BROWN is the MISO. The
same color jumper wires are used to connect them to the breadboard. There is one more color, BLACK, in
Figure 15-2.

Table 15-1.  Pin Definition on Both FPGA and Raspberry

FPGA J5 Raspberry PI Pin


CLOCK GPIO _01 - Pin 1 SPI0 SCLK - Pin 23
SLAVE GPIO _03 - Pin 3 SPI0 CE1 - Pin 26
SELELCT
MOSI GPIO _02 - Pin 2 SPI0 MOSI - Pin 19
MISO GPIO _04 - Pin 4 SPI0 MISO - Pin 21
GROUND Pin 12 Pin 39

Figure 15-2.  Cable connection between the Raspberry Pi and the BeMicro MAX10 for SPI

■■Note  Before making any connection between two boards, make sure both of them are powered off and
connect the ground between the two boards first! The jumper J1 and jumper J9 on the BeMicro MAX10 board
provide a selection of 2.5V or 3.3V for the pin header 5 (J5). Both of them need to be set to 3.3V. (Figure 15-3 in
the lower right corner shows the correct jumper locations: near the edge of the board.) Pin 39 on the Raspberry
Pi and J5 pin 12 on the BeMicro MAX10 are both grounds.

348
Chapter 15 ■ Two-Way Communications with Your Raspberry Pi: SPI

Figure 15-3.  SPI slave example wires set up with Raspberry Pi SPI 0 CE1 Master

15.3 Design SPI Slave in FPGA


We are going create a new project from the BeMax10 template which is from the section “Write Code” in
Chapter 4, and it is similar to Chapter 14. This design will have three modules: (1) SPI slave module which is
a new design (spi_slave.vhd); one Altera PLL IP (pll_29p5M), which is the same PLL (phase-locked loop)
from Chapter 13; and a new top-level module which is raspberryPi_spi_top.vhd. Figure 15-4 shows all the
modules need for this chapter design. We are going to describe how to design the new SPI slave module in
this chapter. First we have to define what we need to design in the SPI slave (the requirements) and then we
can design it in next section.

349

You might also like