1 SD Card Standard
The SD card standard is a standard designed and authorized by the SD Card Association for removable storage devices. It is mainly used to formulate the card's external dimensions, electrical interface and communication protocol.
1.1 SD Card Pin Function
The external shape of the SD card is shown in Figure 1, and the pin functions are listed in Table 1. The pins of the SD card have dual functions and can work in both SD mode and SPI mode. In different modes, the pins have different functions.
SD mode is mostly used in situations where the SD card reading and writing speeds are required to be high, while SPI mode sacrifices reading and writing speeds in exchange for better hardware interface compatibility. Since the SPI protocol is currently a widely popular communication protocol, most high-performance microcontrollers are equipped with SPI hardware interfaces, and the hardware connection is relatively simple. Therefore, when the SD card reading and writing speeds are not required to be high, the SPI mode is undoubtedly a good choice.
1.2 SPI mode
SPI mode is a simple command response protocol. After the main controller issues a command, the SD card returns a corresponding response for different commands.
The command list of the SD card starts with CMD and ACMD, which refer to general commands and special commands respectively, followed by the command number. For example, CMD17 is a general command used to read a single block of data.
In SPI mode, commands are sent in the following 6-byte format:
Each frame command starts with "01", followed by a 6-bit command number and a 4-byte parameter (high bit first, low bit last), and finally a 7-bit CRC checksum and a 1-bit stop bit "1".
Each command of the SD card will return a corresponding response type. In SPI mode, there are 3 response types: R1, R2, and R3, which occupy 1, 2, and 3 bytes respectively. Only the format of the R1 response is listed here, as shown in Table 2. When the status described in the table appears, the corresponding position is 1. The format of the first byte of R2 and R3 is exactly the same as R1. For details, please refer to the SD card standard.
2 Hardware Design
This design uses Freescale's 32-bit low-power microcontroller MCF51QE128 and uses SPI mode to implement the interface with the SD card.
Since MCF51QE128 is a low-power microcontroller with a typical operating voltage of 3.6 V, which is compatible with the operating voltage of the SD card, it can be directly connected to the SD card without a level conversion circuit. The second SPI port of MCF51 QE128 is used here, and the hardware connection is shown in Figure 2.
3 Software Implementation
The software part mainly implements the initialization of MCF51QE128, the underlying SPI communication, and the general write commands, initialization and single-block data reading and writing of the SD card.
3.1 Initialization of MCF51QE128
Before communicating with the SD card, you first need to configure MCF51QE128 and initialize the SPI port. The code is as follows:
1 SD Card Standard
The SD card standard is a standard designed and authorized by the SD Card Association for removable storage devices. It is mainly used to formulate the card's external dimensions, electrical interface and communication protocol.
1.1 SD Card Pin Function
The external shape of the SD card is shown in Figure 1, and the pin functions are listed in Table 1. The pins of the SD card have dual functions and can work in both SD mode and SPI mode. In different modes, the pins have different functions.
SD mode is mostly used in situations where the SD card reading and writing speeds are required to be high, while SPI mode sacrifices reading and writing speeds in exchange for better hardware interface compatibility. Since the SPI protocol is currently a widely popular communication protocol, most high-performance microcontrollers are equipped with SPI hardware interfaces, and the hardware connection is relatively simple. Therefore, when the SD card reading and writing speeds are not required to be high, the SPI mode is undoubtedly a good choice.
1.2 SPI mode
SPI mode is a simple command response protocol. After the main controller issues a command, the SD card returns a corresponding response for different commands.
The command list of the SD card starts with CMD and ACMD, which refer to general commands and special commands respectively, followed by the command number. For example, CMD17 is a general command used to read a single block of data.
In SPI mode, commands are sent in the following 6-byte format:
Each frame command starts with "01", followed by a 6-bit command number and a 4-byte parameter (high bit first, low bit last), and finally a 7-bit CRC checksum and a 1-bit stop bit "1".
Each command of the SD card will return a corresponding response type. In SPI mode, there are 3 response types: R1, R2, and R3, which occupy 1, 2, and 3 bytes respectively. Only the format of the R1 response is listed here, as shown in Table 2. When the status described in the table appears, the corresponding position is 1. The format of the first byte of R2 and R3 is exactly the same as R1. For details, please refer to the SD card standard.
2 Hardware Design
This design uses Freescale's 32-bit low-power microcontroller MCF51QE128 and uses SPI mode to implement the interface with the SD card.
Since MCF51QE128 is a low-power microcontroller with a typical operating voltage of 3.6 V, which is compatible with the operating voltage of the SD card, it can be directly connected to the SD card without a level conversion circuit. The second SPI port of MCF51 QE128 is used here, and the hardware connection is shown in Figure 2.
3 Software Implementation
The software part mainly implements the initialization of MCF51QE128, the underlying SPI communication, and the general write commands, initialization and single-block data reading and writing of the SD card.
3.1 Initialization of MCF51QE128
Before communicating with the SD card, you first need to configure MCF51QE128 and initialize the SPI port. The code is as follows:
3.5 SD card single block data reading and writing
SPI mode supports single block and multi-block data reading and writing operations, which can be achieved by sending corresponding commands. The operation process of reading single block data is shown in Figure 4. After pulling down the chip select, the main controller MCF51QE128 first sends the single block data reading command CMD17, and then waits for the response of the SD card. After receiving the data block start flag 0xfe, it starts to read 512 bytes of data from the SD card, and finally reads the 2-byte CRC check bit.
The function code for reading a single block of data is as follows:
The operation process of writing a single block of data is similar to the read operation, as shown in Figure 5. After the chip select is pulled low, the main controller MCF51QE128 also sends a single block of data write command CMD24. After the SD card responds correctly, it sends the data block start flag 0xfe, followed by a 512-byte data block and a 2-byte CRC check.
After writing data, the SD card will send a 1-byte data response to feedback the data writing status, and its format is shown in Figure 6. When the data is correctly written to the SD card, the data response is 0x05. Finally, read the data bus and wait when writing data until the bus is high.
The function code for writing a single block of data is as follows:
Conclusion
SD card is a widely used erasable large-capacity storage device. Its interface design can be used as a general solution for storage units in various embedded systems. This paper combines the relevant technologies of the SD card standard and completes the design of the hardware interface and underlying communication software based on the MCF51QE128 microcontroller. On this basis, a file system can be further constructed to achieve more effective management of stored data.
Previous article:A secure system based on FPGA single chip quad-core two-by-two
Next article:Implementing the hardware abstraction layer of EMC2
Recommended ReadingLatest update time:2024-11-16 22:47
- Popular Resources
- Popular amplifiers
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- CGD and Qorvo to jointly revolutionize motor control solutions
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Nidec Intelligent Motion is the first to launch an electric clutch ECU for two-wheeled vehicles
- Bosch and Tsinghua University renew cooperation agreement on artificial intelligence research to jointly promote the development of artificial intelligence in the industrial field
- GigaDevice unveils new MCU products, deeply unlocking industrial application scenarios with diversified products and solutions
- Advantech: Investing in Edge AI Innovation to Drive an Intelligent Future
- CGD and QORVO will revolutionize motor control solutions
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- C6678 Multi-core DSP Software Development Difficulties and Solutions
- 150V Non-Synchronous Buck Solution with Voltage Controller
- When will the gifts redeemed from TI Mall be shipped?
- WPI Group sincerely invites you to gather in Chongqing to attend the "Ansemester and NXP - Automotive Electronics Innovation Products and Technology Seminar"
- RVB2601 Evaluation Board Trial 5: Remote Audio Acquisition System
- God, please help me find where I am wrong.
- Comparison of three basic triode amplifier circuits
- SinlinxA33 lvds screen configuration
- PCB size measurement, VX9000 optical scanning imaging measuring machine VS imager measurement
- DC Gain of Nanopower Op Amps