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

Beginning FPGA Programming - Partie74

a

Uploaded by

ali alilou
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Beginning FPGA Programming - Partie74

a

Uploaded by

ali alilou
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

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

15.5 How to Use Raspberry Pi SPI Master Interface


Here we will only show the basic steps to make the Raspberry Pi SPI master work. We have provided some
web site links later in the chapter if you want to explore further.
We can use the Raspberry Pi Python SpiDev() to control the SPI master. Run the following commands
on your Raspberry Pi:

$ sudo apt-get update sudo apt-get install python-dev


$ git clone git://github.com/doceme/py-spidev
$ cd py-spidev
$ sudo python setup.py install

The following link provides more info on thee SPIDEV modules: www.100randomtasks.
com/simple-spi-on-raspberry-pi.

15.5.1 Python Code to Read and Write SPI Master


You can use the Python code shown in Figure 15-23 to test your FPGA slave SPI. The code enables Master 0
on the Raspberry Pi and uses CE1 which is connected to the FPGA GPIO_03 to select the SPI slave.

Figure 15-23.  Python code for controlling SPI master in Raspberry Pi

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

Run the Python code as follows. Figure 15-24 shows the result from the Raspberry Pi. The LEDs on
the BeMicro MAX10 board will start blinking when the code is running. The LED is on and off as the value
shown in the Raspberry PI.

$ python max10spi_simple.py

Figure 15-24.  Running the Python code max10spi_simple.py

Following are additional web sites with information about the SPI in Raspberry Pi:
http://raspberrypi-aa.github.io/session3/spi.html
www.raspberrypi-spy.co.uk/2014/08/enabling-the-spi-interface-on-the-raspberry-pi/

15.6 Summary
This chapter shows you how to do two-way communication with your Raspberry Pi. We created our own
two-byte protocol for reading and writing.
We have also provided detailed design explanations on the spi_slave. You should now know the
function of all six processes in the design and the connection between them. This example illustrates
(clock edge detection) how to deal with the number-one issue of external communication—clock in the
communication link. The example shows you how to use shift registers to send and receive data.
It is not that hard to send and receive data to and from the FPGA though standard interfaces.

“As an engineer I’m constantly spotting problems and plotting how to solve them.”
—James Dyson

366
CHAPTER 16

Up in Lights: How to Drive LED


Segment Displays

16.1 Introduction
In this chapter we will introduce a 7 segment display counter design. The counter counts from 0 to 9 and
then resets to 0 and starts again. The Raspberry Pi can also send a control message to force the counter to
have a particular value. We will re-use all of the VHDL code from Chapter 15 and add a 7 segment display
counter module.

Figure 16-1.  7 segment displays system block diagram with Raspberry Pi

16.2 How to drive a 7 segment display


In the last couple of chapters, the BeMicro MAX10 was only able to use the onboard 8 LEDs to display some
binary information. To improve information display from the FPGA, we can use a 7 segment display. 7
segment displays look like the one in Figure 16-2. The name 7 segments comes from the fact that it has 7
LEDs. What’s special though is that the arrangement of the 7 LEDs can be used to display decimal numbers,
0 to 9. Figure 16-3 shows a schematic of a common cathode 7 segment display that we will be using. It shows
which pins map to which LED. For example, the pin 7 is used to control the segment A. If we provide voltage
on Pins 6 & 4 and ground pins 3 & 8, the the LED segment B and C will light up. Together, this looks like a
“ONE”. There is another type of 7 segment display which is referred to as common anode. We only show
how to connect common cathode 7 segment display in our example. The reason of using cathode version
is because we can turn on the LED by output logic high and user will not damage the FPGA by driving the
LED with external voltage source which is possilbe too high for the FPGA. For common anode 7 segments
display, change the connections of pin 3 and 8 from ground to 3.3V pin (Pin 11 on J5).

© Aiken Pang and Peter Membrey 2017 367


A. Pang and P. Membrey, Beginning FPGA: Programming Metal, DOI 10.1007/978-1-4302-6248-0_16
Chapter 16 ■ Up in Lights: How to Drive LED Segment Displays

Figure 16-2.  7 segment display block

Figure 16-3.  Pins mapping on the 7 segment display

16.2.1 Connecting 7 segment display to FPGA


In our example, we will connect the 7 segment to the BeMicro MAX10 board connector J5. Figure 16-4 shows
the connections between the 7 segment display and the connector. We need to add a 1~5k ohm resistor
between connector and 7 segment display pins connection. The resistor is used to protect the LEDs and the
FPGA output drivers.

368
Chapter 16 ■ Up in Lights: How to Drive LED Segment Displays

Figure 16-4.  Pins mapping on the 7 segment display

The connections should look like the following table mapping on the FPGA side. We will use the FPGA
port names in the VHDL design.

369

You might also like