C
MEDIA_INFORMATION * MDD_SDSPI_MediaInitialize();
Description
This function will send initialization commands to and SD card.
Preconditions
The MDD_MediaInitialize function pointer must be pointing to this function.
Return Values
Return Values |
Description |
errorCode member may contain the following values |
|
Side Effects
None.
Remarks
Psuedo code flow for the media initialization process is as follows:
-----------------------------------------------------------------------------------------
SD Card SPI Initialization Sequence (for physical layer v1.x or v2.0 device) is as follows:
-----------------------------------------------------------------------------------------
- Power up tasks a. Initialize microcontroller SPI module to no more than 400kbps rate so as to support MMC devices. b. Add delay for SD card power up, prior to sending it any commands. It wants the longer of: 1ms, the Vdd ramp time (time from 2.7V to Vdd stable), and 74+ clock pulses.
- Send CMD0 (GO_IDLE_STATE) with CS = 0. This puts the media in SPI mode and software resets the SD/MMC card.
- Send CMD8 (SEND_IF_COND). This requests what voltage the card wants to run at.
Some cards will not support this command. a. If illegal command response is received, this implies either a v1.x physical spec device, or not an SD card (ex: MMC). b. If normal response is received, then it must be a v2.0 or later SD memory card.
If v1.x device:
---------------
- Send CMD1 repeatedly, until initialization complete (indicated by R1 response byte/idle bit == 0)
- Basic initialization is complete. May now switch to higher SPI frequencies.
- Send CMD9 to read the CSD structure. This will tell us the total flash size and other info which will be useful later.
- Parse CSD structure bits (based on v1.x structure format) and extract useful information about the media.
- The card is now ready to perform application data transfers.
If v2.0+ device:
---------------
- Verify the voltage range is feasible. If not, unusable card, should notify user that the card is incompatible with this host.
- Send CMD58 (Read OCR).
- Send CMD55, then ACMD41 (SD_SEND_OP_COND, with HCS = 1). a. Loop CMD55/ACMD41 until R1 response byte == 0x00 (indicating the card is no longer busy/no longer in idle state).
- Send CMD58 (Get CCS). a. If CCS = 1 --> SDHC card. b. If CCS = 0 --> Standard capacity SD card (which is v2.0+).
- Basic initialization is complete. May now switch to higher SPI frequencies.
- Send CMD9 to read the CSD structure. This will tell us the total flash size and other info which will be useful later.
- Parse CSD structure bits (based on v2.0 structure format) and extract useful information about the media.
- The card is now ready to perform application data transfers.