Briefly describe the working principle of SD card (4)

Briefly describe the working principle of SD card

Features

The SD card is a memory card, and its function is storage.

classification

SD cards are classified according to capacity and can be divided into 3 categories: SD cards, SDHC cards, and SDXC cards, as follows:

capacity

name

Abbreviation

0~2G

Standard Capacity SD Memory Card

SDSC or SD

2G~32G

High Capacity SD Memory Card

SDHC

32G ~ 2T

Extended Capacity SD Memory Card

SDXC

Hardware structure

The SD card outline and interface diagram are shown below:

The interface that drives the SD card to work is the SPI or SDIO port, and the pin distribution is as follows:

Hardware connection diagram of host and SD card:

working principle

To drive the SD card to work, it mainly involves two steps.

The first step is the identification process of the SD card.

The second step is to read and write the SD card, that is, the process of data transmission between the host controller and the SD card.

To make the SD card work properly, one is to supply a stable voltage to the SD card, and the other is to work the SD card in the manner specified by the user. The realization of these two tasks is realized by the host controller sending control commands to the SD card.

The host (SDIO controller) needs to use many commands to drive the SD card, including the application layer command ACMD and the common command CMD. The host (SDIO controller) sends the command to the SD card, and the SD card will respond. The response here Called response, the response commands are divided into 6 categories, namely R1, R1b, R2, R3, R6, R7.

After the host (SDIO controller) sends a command to the SD card, the SD card will respond. The response contains the data required by the host (SDIO controller). These data include SD information, capacity, and storage data.

As mentioned above, the SD card works mainly for identification and data transmission. Its identification process is a bit complicated. When writing code, you can refer to the initialization flowchart given by the protocol. Data transmission includes reading and writing, single-byte and multi-byte reading and writing. The next two sections describe the identification initialization flowchart and the data read and write timing diagram.

flow chart

SD card initialization flow chart:

Timing diagram of reading and writing data

SDIO and SD card communication are generally transmitted in the form of data blocks. SDIO (multiple) data block read operations are shown in the following figure:

SDIO (multiple) data block write operation, as shown below:

Command format

All commands and responses of SDIO are transmitted on the SDIO_CMD pin. The command length is fixed at 48 bits. The format of the SDIO command is shown in the following table:

Among them: In addition to the command index and parameters that we need to set, the others are automatically controlled by the SDIO hardware. The command index (such as CMD0, CMD1, etc.) is set by the SDIO_CMD register, and the command parameters are set by the SDIO_ARG register.

The format of STM32 SDIO short response (48 bits) is shown in the table below:

The format of STM32 SDIO long response (136 bits) is shown in the following table:

register

The registers of the SDIO controller mainly set the indexes and parameters of the SDIO controller and commands.

The SD card has 5 registers CID, RCA, CSD, SCR.OCR. The SD card information is obtained from the SD card register.

to sum up

The normal work of the SD card is to send a command and receive a reply according to the SD card initialization flow chart until the end of the process. Data transmission is also based on the read and write timing diagram, and the data to be sent is placed in the command and sent out.

When the SDIO controller drives the SD card, the frequency is 400K. When transmitting data, the SDIOCK frequency is 6M. When the SD card is initialized, the frequency cannot exceed 400K.

Published 105 original articles · Like 30 · Visits 160,000+

Guess you like

Origin blog.csdn.net/happygrilclh/article/details/102614591