Detailed SD card commands

table of Contents

01. Introduction to SD card

02, SD card features

03, SD register

04, SD card operation

4.1, SD initialization

4.2, SD card read operation

4.3, SD card write operation


01. Introduction to SD card

SD card (SecureDigital MemoryCard) is a secure digital card. It is developed on the basis of MMC. It is a new generation of memory device based on semiconductor flash memory. It is widely used in portable devices, such as digital Cameras, personal digital assistants (PDAs) and multimedia players, etc. The SD card was jointly developed by Japan's Panasonic, Toshiba and the US SanDisk Corporation in August 1999.

SD cards are classified by capacity and can be divided into 3 categories: SD cards, SDHC cards, and SDXC cards, as shown in the following table:

The appearance and interface of the SD card are shown in the figure below:

The SD card has 9 pins to communicate with the outside world, and supports SPI and SDIO modes. In different modes, the SD card pin functions are described in the following table:

02, SD card features

①High capacity, up to 2TB (there is currently a 512GB SD card).

②High safety.

③High speed. There are SD cards with a reading speed of nearly 100MB/S.

④Small size, the size of a standard SD card is only the size of a postage stamp, and the weight is only 2g.

⑤Simple interface, supports two access modes of SPI and SDIO.

Note: TF card + card holder can also be used as SD card in combination. However, a large part of TF card does not support SPI access mode. Therefore, when SPI drives the SD card, try to choose a large card (SD card) instead of a TF card.

03, SD register

5 registers of SD

For detailed introduction of these registers, please refer to Chapter 5 of "SD Card 2.0 Protocol.pdf"

04, SD card operation

4.1 , SD initialization

To realize the SDIO drive SD card, the most important step is the initialization of the SD card. As long as the initialization of the SD card is completed, the rest (read and write operations) are simple, so we focus on the initialization of the SD card here.

Please refer to the document "SD Card 2.0 Protocol.pdf" for the following figure.

It can be seen from the SD card initialization process that no matter what card (here we divide the card into 4 categories: SD2.0 high-capacity card (SDHC, maximum 32G), SD2.0 standard capacity card (SDSC, maximum 2G), SD1.x card And MMC card), the first thing we have to perform is to power on the card (set SDIO_POWER

[1:0]=11), after power on, send CMD0 to soft reset the card, then send CMD8 command to distinguish SD card 2.0, only 2.0 and later cards support CMD8 command, MMC card and V1.x The card does not support this command. The CMD8 command format is as follows:

When sending CMD8, we can set the VHS bit through its parameters to tell the SD card, the host's power supply, and let the SD card know the host's power supply range.

The VHS bit definition is shown in the following table:

Here we use the parameter 0X1AA, which tells the SD card that the power supply of the host is between 2.7~3.6V. If the SD card supports CMD8 and supports this voltage range, it will pass the response of CMD8 (R7, for SD card response, please refer to " SD Card 2.0 Protocol.pdf "Section 4.9) returns the original parameter part to the host, if it does not support CMD8, or does not support this voltage range, it will not respond.

After sending CMD8, send ACMD41 (note: before sending ACMD41, send CMD55 first) to further confirm the operating voltage range of the card, and use the HCS bit to tell the SD card whether the host supports high-capacity cards (SDHC)

The ACMD41 command format is shown in the following table:

The ACMD41 command response (R3) contains the contents of the SD card OCR register, and its definition is shown in the following table:

For cards that support CMD8, the host sets the ACMD41 parameter HCS=1 to tell the SD card that the host supports SDHC cards.

For 2.0 cards, the CCS bit of OCR is used to indicate whether SDHC or SDSC; for 1.x cards, this bit is ignored;

For MMC cards, ACMD41 is not supported. MMC cards only need to send: CMD0 and CMD1 to complete the initialization.

CMD2 is used to obtain the CID register data. The definition of each bit of the CID register is as follows:

After receiving CMD2, SD card will return R2 long response (136 bits), which contains 128 bits of valid data (CID register content), stored in 4 registers including SDIO_RESP1~4. By reading these four registers, the CID information of the SD card can be obtained.

CMD3 is used to set the relative address of the card (RCA, must be non-zero). For SD cards (non-MMC cards), after receiving CMD3, a new RCA will be returned to the host to facilitate the host's addressing. The existence of RCA allows multiple SD cards to be connected to one SDIO interface, and RCA is used to distinguish which card the host needs to operate. For the MMC card, the RCA is not automatically returned by the SD card, but the host actively sets the RCA of the MMC card, that is, the RCA setting is realized through CMD3 with parameters (the upper 16 bits are used for RCA setting). The same MMC card also supports one SDIO interface to hang multiple MMC cards. Unlike the SD card, all RCAs are actively set by the host, while the RCA of the SD card is sent to the host by the SD card.

After obtaining the card RCA, we can send CMD9 (with RCA parameters) to obtain the contents of the CSD register of the SD card. From the CSD register, we can get the SD card's capacity and sector size and other very important information. We will not introduce the CSD register in detail here. For a detailed introduction to the CSD register, please refer to "SD Card 2.0 Protocol.pdf".

At this point, our SD card initialization is basically over, and finally through the CMD7 command, select the SD card we want to operate, and then start reading and writing operations on the SD card.

4.2 SD card read operation

SD card single data block read process

SD card multi-block data reading process

CMD16 instruction description

CMD17 instruction description

CMD18 instruction description

CMD12 instruction description

4.3 , SD card write

SD card single data block write process

SD card multi-block data writing process

CMD13 instruction description

R1 response:

SD card status, please refer to page 63 of "SD Card 2.0 Protocol.pdf"-Table4-35

CMD24 instruction description

ACMD23 instruction description

Note: Before sending ACMD, CMD55 must be sent to notify the SD card, and the next thing to be sent is the application command (APPCMD), not the standard command

CMD55 instruction description

CMD25 instruction description

Guess you like

Origin blog.csdn.net/Firefly_cjd/article/details/109406289