Click the blue text
Follow us
This article discusses reading and writing operations on an SD card using the SPI external bus protocol based on Qsys.
1. Experimental Platform and Objectives:
The experiment uses the Altera Pioneer board with chip model: EP4CE10F17C8; an SD card is also required.
The main goal of this experiment is to utilize the SPI IP core to drive the SD card for read and write operations. In this experiment, we will learn how to use SPI and understand the methods for reading and writing to the SD card.
2. System Setup:

(1) Nios Processor Configuration:
Nios II/f

Other settings are default.
(2) SDRAM Controller Configuration


(3) SPI IP Core Configuration

(4) PIO IP Core Configuration

All other IP core configurations not shown are set to default.
3. Top-Level File



PLL IP Core Configuration

clk c0 output is 100MHz with a phase offset of 0; clk c1 output is 100MHz with a phase offset of -60.


System RTL:

4. Pin Binding




5. Software Code in Eclipse
(1) Experiment 1: Compile the following code and run as –> 3 Nios II Hardware









Experiment Results:
The output will be displayed in the Nios II console:

Remove the SD card, insert it into a card reader, and open the WinHex software on your computer to access the SD card.

Select the corresponding disk to open the following interface:

(2) Experiment 2: SD Card Write Operation
Uncomment the code in the main function:








Experiment Results:

From the code, we can see that the API provided by Altera, alt_avalon_spi_command(), is used to access the slave for read/write operations. Additionally, the SPI working mode must be set in Qsys, and the correct parameters must be provided to the alt_avalon_spi_command() function to achieve the desired results. It is important to note:
-
alt_avalon_spi_command() is only effective in master mode; in slave mode, data must be accessed directly from the SPI data register.
-
The SPI core does not match the generic device model types supported by HAL, so it cannot be accessed via HAL API or ANSI C standard library.



*Disclaimer: This article is either original or forwarded by the author. If any party’s intellectual property rights are inadvertently infringed, please inform us for deletion.The above images and text are sourced from the internet; if there is any infringement, please contact us promptly, and we will delete it within 24 hours.The content of the article reflects the author’s personal views, and the Automotive Ethernet Technology Research Laboratory reprints it solely to convey a different perspective, which does not represent the Automotive Ethernet Technology Research Laboratory’s endorsement or support of this view. If there are any objections, please feel free to contact the Automotive Ethernet Technology Research Laboratory.
Original link:
https://blog.csdn.net/xzs520xzs/article/details/132148453