15.3.1 New Spi Slave Module Port List: Two-Way Communications With Your Raspberry Pi: Spi
15.3.1 New Spi Slave Module Port List: Two-Way Communications With Your Raspberry Pi: Spi
We are going to define the SPI slave input and output ports, review Raspberry Pi SPI master, and then
define the detail requirements for the SPI slave.
350
Chapter 15 ■ Two-Way Communications with Your Raspberry Pi: SPI
Figure 15-5. Port list for the new SPI slave module
Figure 15-6 also shows the protocols. The top one shows a read cycle. The SPI master (Raspberry Pi)
first byte is 0x01 and the SPI slave (FPGA) needs to send out one byte with the following eight clock cycles.
The bottom of Figure 15-6 shows a write cycle. The first and second bytes are sent from the SPI master
(Raspberry PI). The first byte is 0x0 to indicate a write cycle and the second byte is the byte from Raspberry
Pi written to the FPGA. We will use this byte to control the onboard LEDs.
351
Chapter 15 ■ Two-Way Communications with Your Raspberry Pi: SPI
We will need to create seven signals in the spi_slave module and we need to put the code in between
architecture and begin. Figure 15-8 shows all seven of the signals and their definitions.
352
Chapter 15 ■ Two-Way Communications with Your Raspberry Pi: SPI
On line 45, we use a 3-bit shift register (spi_clk_dly_line) to sample the rspi_sclk by sys_clock. When the
change of the rspi_sclk is sampled and stored in the shift register we can do all the clock edge detection logic
in sys_clock domain. Figure 15-10 shows that the rising edge detection pulse is delayed two sys_clock clock
cycles. It is expected when we use a fast clock to sample a slow clock and do the clock edge detection. The
spi_clk_dly_line (2), (1), and (0) are storing the history of the rspi_sclk. We defined the rising edge as when
(2) and (1) are logic low and at the clock cycle (0) and rspi_sclk are logic high.
353
Chapter 15 ■ Two-Way Communications with Your Raspberry Pi: SPI
Figure 15-11 shows the falling edge detection simulation. It uses the same concept of edge detection as
rising edge. It only changes the logic value.
This clock edge logic works like a clock tick for the rest of the logic.
354