Abstract: This paper first introduces the basic structure and principle of SD Memory Card (Secure Digital Memory Card), focusing on the command words and operation flow of SD card. Then it studies the hardware interface circuit between Samsung 32-bit embedded processor S3C2410 and SD card and its basic reading and writing operation methods for SD card.
Keywords: SD; storage; S3C24101
1 Introduction
SD card (Secure Digital Memory Card) is a new generation of memory based on Flash. It focuses on the security, capacity and performance of data storage. It is an ideal external storage medium for many portable electronic products such as digital cameras, mobile phones, PDAs, etc.
2 Basic Concepts of SD
2.1 SD communication protocol
The SD card system can work under two communication protocols: SD protocol and SPI protocol. Users can freely select the communication protocol of the SD card system during hardware initialization. For a specific hardware circuit, users only need to use one communication protocol.
This article only discusses the most commonly used SD protocol based on the author's hardware.
2.2 SD data transmission method
SD supports two data transmission modes: 1-bit mode (standard bus) and 4-bit mode (wide bus). In 1-bit mode, data is transmitted only on data line 0 (DAT[0]). In 4-bit mode, data is transmitted simultaneously on 4 data lines (DAT[3:0]). In 4-bit data transmission mode, the maximum data transmission rate can reach 100Mb/sec. Table 1 lists the definitions of SD interface signals in the two modes.
After power-on, the system works in 1-bit mode by default. When the SD card is in transfer mode, the user can freely change to 1-bit or 4-bit mode.
2.3 SD communication principle
The SD bus is a star-shaped bus structure. The system allows one master controller and up to ten slave devices (SD cards). When the system is initialized, the master controller assigns a device address to each device, and then the master controller can independently operate the device according to the device address.
SD bus communication is based on command and data bit streams, each of which includes a start bit and an end bit.
Each SD command represents the start of a card operation. SD commands are transmitted via the command line (CMD).
After receiving the command, the SD card will send a response signal to the host controller to indicate that a command has been received. The response signal is transmitted on the CMD line. A small number of commands do not have a response signal, which depends on the type of command.
SD data transmission is bidirectional. All data transmission is carried out on the data line.
2.4 Data organization format in SD system
The command transmission, response signal transmission and data transmission in the SD system have their own special organizational forms, as shown in Figure 1.
The first bit of all command words, responses and data is the start bit "0" and the last bit is the end bit "1".
The second bit in the command word and response is the sender flag bit, "1" indicates the host controller command, and "0" indicates the SD card response signal.
The SD card has four different responses: R1, R2, R3 and R6, depending on the command word received. For details, please refer to the SD related documents.
When transmitting data, if the wide bus transmission mode is used, four bits of data are transmitted at the same time, using four data lines respectively. The CRC check code on each data line is calculated independently.
3 SD card operation process
All communications in the SD system are controlled by the host controller. The host controller must be responsible for initializing the system, setting various parameters required for communication, and then initiating data read or write operations. During this series of processes, the SD card may be in one of the various states shown in Table 2.
3.1 System Initialization
The system's operating mode at this stage belongs to the card authentication mode.
The main controller first sends the command word CMD0 to reset all cards in the system in the identification mode. After receiving the command CMD0, the SD card will be initialized and obtain a default address 0 (relative card address register RCA = 0x0).
Then the host controller sends the command ACMD41 to query the OCR (operating environment register) of the SD card with the required operating voltage range as the parameter. Cards whose operating voltage is not within this required range will be excluded from further bus operations and enter the inactive state. Cards that meet the voltage range requirements will enter the ready state.
Next, the main controller sends a command CMD2 to obtain the identification number CID of the SD card. After the SD card sends the CID number, it enters the identification state.
Finally, the host controller sends the command CMD3 with the relative address as the parameter. After receiving the command, the SD card updates its RCA with the parameter. After that, the host controller can use this address to address the card.
After initialization is completed, the SD card is in the waiting state of the data transmission mode, which is the initial state of the data transmission mode. At this time, the card selection command CMD7 enters the transmission state, and data can be written and read.
3.2 SD write operation
The reading and writing of SD cards is based on data blocks. The size of data blocks varies from card to card, usually from 512 bytes to 2048 bytes. The size of data blocks for a specific card is defined in the card's characteristic register (CSD). In special cases, some cards support reading and writing in small blocks (the smallest unit can be bytes). However, it is recommended to read and write in blocks.
SD cards support single-block writing and multi-block writing. Single-block writing uses command CMD24, and multi-block writing uses command CMD25. When there are multiple data blocks to be written, using multi-block writing can achieve higher efficiency than executing single-block writing multiple times.
Since the SD card has a buffer area inside, the SD card is in the data receiving state during the above process, and the received data is not actually written into the memory of the SD card, but is stored in the buffer area of the SD card. When the data reception is completed, the SD card automatically enters the data programming state, and the data is actually written into the memory of the SD card.
3.3 SD read operation
Corresponding to the write operation, the SD card supports single-block read and multi-block read. Single-block read uses command CMD17, and multi-block read uses command CMD18. When there are multiple data blocks to read, using multi-block read can achieve higher efficiency than executing single-block read multiple times.
4 Applications based on S3C2410
Samsung's S3C2410 is a 32-bit embedded processor with a built-in SD host controller that is compatible with SD 1.0, MMC 2.11, and SD IO 1.0 versions. The S3C2410 can be easily interfaced with an SD card.
4.1 Interface between S3C2410 and SD card
The interface between S3C2410 and SD card is shown in Figure 2. Among them, nCD_SD is the card detection signal, and WP_SD is the write protection signal of the card. For simple write operation, it is only necessary to detect the WP_SD bit before writing.
4.2 Using S3C2410 to read and write SD cards
In the usual SD read and write operations, you can use the query mode, interrupt mode or DMA. When the SD card is in the transmission state, first reset the S3C2410 send buffer, select the bus width, select read data or write data, select the number of read and write data blocks, select the start address of the read and write data blocks, write the read or write command word, and then continuously read or write one or more data blocks from/to the SD data buffer according to the number of data blocks to be read or written. The following code can use the query mode to write one or more data blocks to the SD card:
The process of reading SD card is similar to that of writing, except that the command words used are different. Users can modify it according to the write operation code.
5 Conclusion
As more and more electronic products support SD memory cards, the application scope of SD cards is getting wider and wider. The storage system composed of the 32-bit embedded processor S3C2410 and the SD card provides users with a safe and lightweight storage solution. SD cards have many functions, and all operations cannot be explained clearly in this article. However, through the introduction of this article, readers can have a conceptual understanding of SD and understand its basic operation process, and then extend it.
Previous article:A brief discussion on embedded real-time systems and their applications in communication systems
Next article:Research on the mobile local personal digital library system based on Android
Recommended ReadingLatest update time:2024-11-16 17:58
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- CGD and Qorvo to jointly revolutionize motor control solutions
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Nidec Intelligent Motion is the first to launch an electric clutch ECU for two-wheeled vehicles
- Bosch and Tsinghua University renew cooperation agreement on artificial intelligence research to jointly promote the development of artificial intelligence in the industrial field
- GigaDevice unveils new MCU products, deeply unlocking industrial application scenarios with diversified products and solutions
- Advantech: Investing in Edge AI Innovation to Drive an Intelligent Future
- CGD and QORVO will revolutionize motor control solutions
- 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
- EEWORLD University Hall ---- FPGA Tips for Ming Deyang
- About GD32E230I2C as a slave
- With Trump's propaganda, RF has become extremely popular in the past two years. There are articles everywhere to share.
- [Liquid Level Sensor Evaluation] Sensor Performance Comparison (and Final Report)
- Bluetooth Technology Principle
- FIDI: CircuitPython Rapid Prototyping Board
- [Summary] Review and Outlook, Goodbye 2019, Hello 2020!
- The IO port of the microcontroller can generally be set to three states
- Is the solder in the soldering iron toxic?
- What are the benefits of connecting a PNP transistor and a Zener diode in series to control NMOS?