First understand the SD card protocol
1. SD Card Protocol Overview
Command: Sent by the host on the CMD line
Response: Sent on the CMD line by the addressed card.
Data: On the data line, use DAT0 or DAT0~DAT3.
The CRC status response and Busy indication can only be sent via DAT0
2. Command format:
High, 48th Low, 1st
0 | 1 | contents | CRC7 | 1 |
Start bit, always 0 | Transmission direction, 1: Host sends 0: The device sends | Content, determined by the specific command | Seven-bit CRC | Stop bit, Total is 1 |
Response format: R1, R3, and R6 are the same as the command format, except that the 47th bit is 0; and R2 is 136 bits, but the contents has more bits than the above table.
Transmission format for four data lines: omitted
The order in which data passes through the bus: high bits first, low bits last.
SD Card Registers:
name | width | illustrate |
CID | 128 | Card identification number; Card identification number |
RCA | 16 | Relative card address; local address, determined by the host and card during initialization |
DSR | 16 | Driver Stage Register; configure the output driver of the card |
CSD | 128 | Card Specific Data; Information about card operations |
SCR | 64 | SD Configuration Register; Card configuration information |
OCR | 32 | Operation conditions register |
SSR | 512 | SD Status; information about the card proprietary features |
CSR | 32 | Card Status; information about the card status |
The red ones are the registers added in V2.0. The green ones are for SPI and the blue ones are for V1.0.
3. Command types: broadcast command, point-to-point addressing command.
Operation mode: identification card mode, data transmission mode.
Card identification process: 1. Reset. Power on or send CMD0 to put the card into idle state.
2. Send ACMD41, CMD2, and CMD3 to make it enter the waiting state of data transmission mode.
For large-capacity SD cards, after sending ACMD41, check whether CCS is 1 to determine whether it is a large-capacity SD card. In order to be able to identify various cards, the initial clock setting cannot be higher than 400kHz
data transmission:
Differences in operations for large-capacity SD cards
The memory access commands include a block read command (CMD17, CMD18), a block write command (CMD24, CMD25) and a block erase command (CMD32, CMD33).
The following are the functional differences between standard capacity SD cards and high capacity SD cards when accessing memory:
1. Command variables
For large capacity SD cards, the 32-bit variable of the memory access command is a memory access for block addressing (the block variable that determines the block). The fixed size of the block is 512 bytes. For standard capacity SD cards, the 32-bit variable is byte addressing, and the block length is determined by the CMD16 command.
Right now:
(a) For standard capacity SD cards, variable 0001h addresses the 0001h byte unit, while for large capacity SD cards, it addresses the 0001h block.
(b) For standard capacity SD cards, variable 0002h addresses the 0002h byte unit, while for large capacity SD cards, it addresses the 0002h block.
2. Local addressing and unaligned addressing. In large-capacity SD cards, local addressing and unaligned addressing (crossing block boundaries) as block addressing are not allowed, and only whole block addressing is allowed.
3. Set the block length
When using the memory read and write commands in block addressing mode, the block length is 512 bytes, regardless of the block length set by CMD16.
The memory access command is invalid. CMD42 does not belong to the memory access command. The data block size and block length specified by CMD16 are set to 512 bytes.
512 bytes will set BLOCK_LEN_ERROR and ignore the card capacity.
4. Write protection group
Large capacity SD cards are not supported. Sending commands CMD28, CMD29 and CMD30 will generate an ILLEGAL_COMMAND error
5. Read and write timeout check
Read: For standard capacity SD cards, the read timeout is set to be 100 times greater than the typical read time, or 100ms. The card parameter read time is: twice the TAACT NSAC parameter in CSD.
Write: For standard capacity SD cards, the write timeout is set to 100 times greater than the typical programming time, or 250mS. The write time of the card parameters is: R2W_FACTOR in CSD
For large capacity cards, the parameters in CSD are fixed values, so it is best to use >100mS as read timeout and >250mS as write timeout.
4. Command format
Sequence | 47 | 46 | [45:40] | [39:8] | [7:1] | 0 |
width | 1 | 1 | 6 | 32 | 7 | 1 |
Numeric | '0' | '1' | x | x | x | '1' |
Remark | Start bit | 1 sent, 0 received | Command Index | variable | CRC7 | Stop bit |
5. About command index
The "command index" is not clearly stated in the SD protocol, but after referring to Samsung programs and online articles, I believe that this statement is correct: the number in the "command index" is its "index value". For ACMD commands, they can be regarded as "compound commands", that is, when executing, CMD55 is executed first, and then the "command with 'A' removed from the front of ACMDn" is executed.
2. Instructions on SD card operation in the S3C2440 manual
The serial clock shifts and synchronizes the information on the data line and samples it, setting SDIPRE to control the transmission frequency.
Basic programming process: 1. Set SDICON to select clock and interrupt.
2. Set SDIPRE to an appropriate value.
3. Wait for 74 SDCLKs to complete the SD card initialization
The process of sending a command: 1. Write a 32-bit command variable to SDICmdArg
2. Set the SDICmdCon register, select the command type and start the transmission
3. Check whether the specified bit of SDICmdSta is set to determine whether the command has been transmitted.
4. If there is a response, check the response register SDIRSPn
5. Write 1 to the corresponding bit of the SDICmdSta register to clear the flag bit
Data channel programming: 1. Write timeout register SDIDTimer
2. Write the block size to be operated to SDIBSize
3. Set block mode, bus width, DMA, etc., and set SDIDatCon. to start transmission
4. When sending data, when TCFIFO is valid, half full, or empty, write the data into SDIDAT.
5. When receiving data, when RXFIFO is valid, half full, or empty, write the data into SDIDAT.
6. Confirm whether the data has been transferred.
7. Clear the corresponding flag in SDIDatSta
1. Differences in initialization commands:
1. Add CMD8 command to identify whether it is a large-capacity card. If so, the response is R7, returning the acceptable power range and the verification code consistent with the one sent.
2. ACMD41 is slightly different from V1.0. Its response is generally rSDIRSP0=0xc0ff8000. For compatibility, an extra branch needs to be added.
3. Send CMD2, and the response is CID. For example, the values of rSDIRSP0:rSDIRSP1:rSDIRSP2:rSDIRSP3 of a card are: 0x1b534d30:0x30303030:0x10b1846c:0xdc00879d, and the meanings are as follows:
127 0
Number of digits | 8 | 16 | 40 | 8 | 32 | 4 | 12 | 7 | 1 |
value | 1b | 534d | 3030303030 | 10 | b1846cd | c | 008 | 79d | |
significance | MID | “SM | 00000” | PRV | PSN | RSV | MDT | CRC |
2. Differences between reading and writing
V2.0 operates on blocks, with each block being 512 bytes. V1.0 can operate on bytes, using CMD16 to set the block size. CMD17 and CMD18 are used to operate on a single block or multiple blocks respectively.
It is worth noting that Samsung's routine is more classic, but it cannot read large-capacity SD cards because the SDI Data Control Register is not set. For large-capacity cards, this register must be set to 0x200, and it must be this value.
The following is the data read from the starting sector of a large capacity card:
0x 0: Rx-0xeb068005,0x2039ffff,0xe800005b,0xc1eb048c
0x 4: Rx-0xc801c38e,0xdb536a19,0xcbf60602,0x 4740f
0x 8: Rx-0x31c08ec0,0xbffc0566,0xb8445543,0x4566ab68
0x c: Rx-0x 2017bc,0x 9031c9,0x51ba8000,0x52b408f9
0x 10: Rx-0xcd135a58,0x16077217,0x80e13ff9,0x741191b4
0x 14: Rx-0x 289c531,0xdb4152f9,0xcd135a72,0x 2f6dc0e
0x 18: Rx-0x1f9c31f6,0x31ffb9df,0xfcf3a5,0xbbfc1966
0x 1c: Rx-0xb8475255,0xaaea7a00,0x 20161f,0x66390775
0x 20: Rx-0x549d723c,0x e1fad88,0xe6ad89c1,0x243f741f
0x 24: Rx-0x29e848f6,0xd8bf0300,0xb4026800,0xd0731db
0x 28: Rx-0x60cd1361,0x730a6031,0xc0cd1361,0x4f75e9f9
0x 2c: Rx-0xe8c50977,0x2883c60c,0x81fefe01,0x72c67715
0x 30: Rx-0xbeb231b4,0x 89952cd,0x13587209,0x9991243f
0x 34: Rx-0x740341eb,0xc0be5101,0xe86f00eb,0xfe1e0666
0x 38: Rx-0x608cc3fa,0x f011660,0x a0f20c0,0x c010f22
0x 3c: Rx-0xc0be0800,0x8ec66631,0xf66631ff,0x66b90024
0x 40: Rx-0x fcf3,0x66a5be10,0x 8ec624,0xfe0f22c0
0x 44: Rx-0x8ec3b900,0x 231f656,0xbf007c57,0x 61f5607
0x 48: Rx-0xfcf3a5bf,0x107ebe00,0xab91e00,0xfcf3662e
0x 4c: Rx-0xa5061ffb,0xcbfab800,0x208ed0bc,0xdc8ffb66
0x 50: Rx-0x61071fe9,0x6fffb40e,0xcd102eac,0x3c0075f6
0x 54: Rx-0xc30d0a4d,0x69737369,0x6e67204d,0x42522d68
0x 58: Rx-0x656c7065,0x722e0000,0x 0,0x 0
0x 5c: Rx-0x 0,0x 0,0x 0,0x 0
0x 60: Rx-0x 0,0x 0,0x 0,0x 0
0x 64: Rx-0x 0,0x 0,0x 0,0x 0
0x 68: Rx-0x 0,0x 0,0x 0,0x 0
0x 6c: Rx-0x 0,0x 0,0x9bb43b00,0x 8001
0x 70: Rx-0x 1000cfe,0x7ff23f00,0x c17f,0x7a000000
0x 74: Rx-0x 0,0x 0,0x 0,0x 0
0x 78: Rx-0x 0,0x 0,0x 0,0x 0
0x 7c: Rx-0x 0,0x 0,0x 0,0x 55aa
Previous article:STM32 Note SD card reading and writing and FatFS file system
Next article:ARM development step by step into the MMU first look
Recommended ReadingLatest update time:2024-11-17 00:46
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- 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
- Common problems and solutions in CCS compilation
- Mingdeyang FPGA project practice 1-bit flashing light design
- First week of SensorTile.box initial experiment
- [Fudan Micro FM33LC046N] FLASH basic time simple test
- EEWORLD University Hall----POS Printer/Printer Special
- High-performance C6000 DSP architecture
- How to share the University Hall video to Moments
- Five solutions to long branch lines in CAN networks
- [Raspberry Pi Pico Review] C/C++ Development Environment Construction
- If the stmTX and RX pins of stm32 are broken, will stm32 still work?