The SD card technology is developed based on the multimedia card (MMC) format, and the SD card and mmccard maintain upward compatibility. The internal structure of the SD card is divided into two parts: the SD controller and the NAND memory.
SD card types are divided into three types: mmccard, similar to SD card, using MMC protocol; sd1.0, sd1.0 card supports a maximum of 2 Gbyte; sd2.0, sd2.0 card maximum capacity hcsd up to 32 Gbyte. The protocols from MMC to sd1.0 to sd2.0 are compatible with each other. That is to say, MMC commands can operate sd1.0 and sd2.0. Similarly, sd1.0 commands can operate sd2.0 cards.
(1) Hardware pin Encapsulation
SD card interface: SD card interface supports SPI mode and SD mode. The SD mode adopts a 4-line parallel mode. This interface is used as a multimedia storage device to increase transmission speed. The SPI makes it easier for low-end MCU to access and transmit at a limited speed.
(2) SD protocol command format
Let's take a look at the SD card protocol command format, the mmccard only has the basic command, that is, the CMD0-CMD38, of course this is not consecutive. The SD card has basic commands and specific commands. A specific command must be followed by the Basic command serial 55. To use a specific command, you must first send a serial 55 notification to the SD card before sending a specific command. Each Command consists of 6 bytes, which consists of three parts: 1 byte operator code, 2-5 bytes as parameters, some commands do not have parameters, So enter 0, some parameters are determined according to parameter description, the last word is CRC verification. However, the SPI mode does not require CRC verification, so you can enter it as needed. However, there are several special commands with the specified CRC verification code, which must be added. Each Command has a response. Different commands may have R1, r1b, R2, and R3 (OCR) registers to determine whether the command is successful.
(3) initialization and read, write, and erase operations
After understanding the commands, you can operate the SD card as long as you know the process of each operation. The main operations include initialization, reading, writing, and erasure. The following describes the operations:
A. Initialization:
1. the latency should be at least 74 clock. Wait for the internal operation of the SD card to be completed, which is clearly stated in the MMC protocol.
2. SD card for Cs Low-level selection.
3. If sending limit 0, 0x01 must be returned to enter the idle status.
4. In order to distinguish between SD card 2.0, SD card 1.0, or mmccard, follow the principle of protocol upward compatibility. First, send the command ipv8 only available for sd2.0. If ipv8 returns no error, the initial judgment is 2.0 cards, and the command is sent to send messages 55 + acmd41 cyclically until 0x00 is returned. Make sure that the sd2.0 card is initialized successfully and enters the ready status, then, send the dig 58 command to determine whether it is hcsd or scsd. By now, the sd2.0 card is initialized successfully. If iis8 returns an error, the system further determines whether it is a 1.0-card or an mmccard, and sends messages 55 + acmd41 cyclically. If no error is returned, the sd1.0 card is returned, and the initial success of the sd1.0 card is reached, if an error is returned for a certain number of cycles, the cmd1 is further sent for initialization. If no error is returned, the mmccard is returned. if the error is returned for a certain number of times, the card cannot be identified, and the start is over.
5. CS increase.
B. Read steps:
1. Send the (single block) or (multiple blocks) read command, and return 0x00.
2. The receiving data start token 0xfe (or 0xfc) + official data 512 bytes + CRC verification 2 bytes. By default, the length of formally transmitted data is 512 bytes, and the block length can be set with limit 16.
C. Write steps:
1. Send the 24 (single block) or 25 (multiple blocks) write command, and return 0x00.
2. The sending data starts with the token 0xfe (or 0xfc) + official data 512 bytes + CRC verification 2 bytes.
D. Erase steps:
1. Send token 32, and specify the first starting address to be erased with a parameter (block number in the SD Manual ).
2. Send Route 33, and specify the final address.
3. Send messages 38 and erase the content in the specified range.
E. In short, the SD card is a memory, but it is operated by command. As long as we master each command and operation method, we can flexibly operate the SD card.
(4) Hot swapping Detection
There are three methods for detecting the SD card:
1. Run the CMD command to check whether the tcard exists during startup. This method does not support hot swapping.
2. The tcard_detect signal is connected to the interrupt controller through the tcard_detect module. When no plug-in card is available, the tcard_detect signal is low. After the tcard is inserted, the signal tcard_detect is pulled high to a high level, resulting in an interruption. That is, hot swapping is implemented. Note: The trigger from low to high or from high to low can be set by collaboration between hardware and software.
3. The CD/dat3 signal is used for detection. The CD/dat3 signal is connected to the interrupt controller and pulled down by a K resistor. When no tcard is inserted, the signal is low, once there is a tcard insertion, the tcard uses 50kohm to pull the data3 signal to a high level, and an interruption occurs immediately, enabling hot swapping. The pin is described as follows:
In practice, we will find different application scenarios of dat3/CD. In some circuit diagrams, the CD/dat3 signal is pulled down, and some are not pulled down. If the T-card seat is designed under the battery, there is no need for hot swapping. You only need to check whether there is a T-card at startup. At this time, the CD/dat3 signal does not need a drop-down resistor, a. When the design of the T-card seat is outside the fuselage, it needs to support hot swapping. It needs to be connected to the drop-down resistor, B.
A,
B,
This makes it clearer.
Http://blog.csdn.net/cuitianxiang/article/details/5503173 ()