1 SD card standard
The SD card standard is a standard designed, patented 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 appearance 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. The pins have different functions in different modes.
SD mode is mostly used in situations where the SD card read and write speed is required to be high, while SPI mode sacrifices read and write speed 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 read and write speed is not required to be high, using 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 the corresponding response for different commands.
The command list of 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 check 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 first byte format 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 adopts 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 the MCF51QE128 and initialize the SPI port. The code is as follows:
3.2 Low-level SPI communication
The underlying SPI communication is the key to achieve the final reading and writing. Since MCF51QE128 has its own SPI hardware interface, it only needs to read and write the value of the SPI data register. Here, three data types, byte, word and dword, are defined, corresponding to 8-bit, 16-bit and 32-bit data respectively. The code is as follows:
3.3 SD card general write command
Since the commands of SD card have a unified format, a general write command function can be used to send all commands. In addition, considering that the response type of most commands is R1, the response type received by the general write command function here is R1 by default. The function code is as follows:
3.4 SD card initialization
The initialization of the SD card follows certain steps. First, lower the SPI clock to 400 kHz and wait for at least 74 clock cycles. Then pull the chip select signal low and send the CMD0 command to reset the SD card and put it into SPI mode. Here, a correct CRC check is required, and the check byte is 0x95. If the SD card enters the idle state (that is, when the received response is 0x01), send the CMD1 command to activate the card initialization process. At this time, the response is 0x00. Then set the block length, which is generally 512 bytes. Finally, pull the chip select high and set the SPI clock to the maximum value to ensure the maximum read and write speed. The SD card initialization process is shown in Figure 3.
The SD card initialization code is as follows:
3.5 SD card single block data reading and writing
SPI mode supports single-block and multi-block data read and write 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 read 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 SD card standards and completes the design of hardware interface and underlying communication software based on MCF51QE128 microcontroller. On this basis, a file system can be further constructed to achieve more effective management of stored data.
Previous article:Application of single-ended flyback circuit in inverter power supply
Next article:Design of CAN bus NiMH battery management system
- Popular Resources
- Popular amplifiers
- MathWorks and NXP Collaborate to Launch Model-Based Design Toolbox for Battery Management Systems
- STMicroelectronics' advanced galvanically isolated gate driver STGAP3S provides flexible protection for IGBTs and SiC MOSFETs
- New diaphragm-free solid-state lithium battery technology is launched: the distance between the positive and negative electrodes is less than 0.000001 meters
- [“Source” Observe the Autumn Series] Application and testing of the next generation of semiconductor gallium oxide device photodetectors
- 采用自主设计封装,绝缘电阻显著提高!ROHM开发出更高电压xEV系统的SiC肖特基势垒二极管
- Will GaN replace SiC? PI's disruptive 1700V InnoMux2 is here to demonstrate
- From Isolation to the Third and a Half Generation: Understanding Naxinwei's Gate Driver IC in One Article
- The appeal of 48 V technology: importance, benefits and key factors in system-level applications
- Important breakthrough in recycling of used lithium-ion batteries
- 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
- Using the sensor hub mode of lsm6dsl to drive lis2mdl output data unchanged
- I'm having trouble with stepper motor segmentation. Can anyone help me?
- 74LS160 digital circuit digital electronic clock circuit design
- 【Showing goods】The first wave
- What is the Q value of a filter?
- If you had to give up your 750,000 yuan annual salary at Tencent or return to your hometown to become a civil servant, what would you choose?
- EEWORLD University Hall----Live Replay: TI AMIC110 Multi-protocol Communication Chip Industrial Application Optimization Solution
- 【Gravity:AS7341 Evaluation】+ Frequency Value Detection
- The homemade sensor test board (bone vibration) is finished and ready for production
- RK3288 baseboard + core board design process