SDカード

ピンアサイン

使用するプロトコルによって、ピンの名称および用途が異なります。なお「MMCモード」はMMC (マルチメディアカード) で、「SDモード」はSDカードでのみ使用できます。

  SPIモード※1 MMCモード SDモード
ピン番号 名称 説明 名称 説明 名称 説明
1 CS チップセレクト RSV 予約ピン CD/DAT3 Data3 / Card Detect
2 DI データ入力 CMD レスポンス CMD コマンド
3 VSS GND VSS1 GND VSS GND
4 VDD VCC VDD1 VCC VDD VCC
5 SCLK クロック CLK クロック CLK クロック
6 VSS2 GND VSS2 GND VSS GND
7 DO データ出力 DAT データ入出力 DAT0 Data0
8         DAT1 Data1
9         DAT2 Data2
※1 MMC、SDカード共通

ファイルシステム

ファイルシステム

Memory Disk Drive (MDD) file system

MDD file systemは、Microchip Libraries for Applicationsに含まれます。

プロトコル

SDカードとの通信には、SPIモードとSD Busモードの2つのプロトコルがあります。

機能 SPIモード SD Busモード
Negotiating Operating Conditions The operating condition negotiation function of the SD Card bus is supported differently in SPI mode by using the READ_OCR (CMD58) command. The host works within the valid voltage range (2.7 to 3.6 v) of the card or put the card in inactive state by sending a GO_INACTIVE command to the card. The SD Card supports the operation condition verification sequence defined in the SD Card standard specifications. Should the SD Card host define an operating voltage range, which is not supported by the SD Card it will put itself in an inactive state and ignore any bus communication. The only way to get the card out of the inactive state is by powering it down and up again.

In Addition the host can explicitly send the card to the inactive state by using the GO_INACTIVE_STATE command.

Card Acquisition and Identification The host must know the number of cards currently connected on the bus. Specific card selection is done via the CS signal (CD/DAT3). The internal pull-up resistor on the CD/DAT3 line may be used for card detection (insertion/removal). Additional practical card detection methods can be found in SD Physical Specification’s Application Notes given by the SDA.  
Card Status In SPI mode, only 16 bits containing errors relevant to SPI mode can be read out of the 32-bit Status Register. The SD_STATUS can be read using ACMD13, the same as in SD mode.  
Memory Array Partitioning Memory partitioning in SPI mode is equivalent to SD mode. All read and write commands are byte addressable.  
Read/Write Operations In SPI mode, single and multiple block data transfers are supported.  

コマンド

SPI Bus Command

CMD Index SPI Mode Argument Resp Abbreviation Description
        SION stop transmissionduring a multiple block read operation.
CMD13 Yes None R2 SEND_STATUS Asks the selectedcard to send its StatusRegister.
CMD14 Reserved.
CMD15 No --- --- --- ---
CMD16 Yes [31:0] block length R1 SET_BLOCKLEN Selects a block length (in bytes) for all following block commands (read & write).1
CMD17 Yes [31:0] data address R1 READ_SINGLE_ BLOCK Reads a block of the size selected by the SET_BLOCKLEN command.2
CMD18 Yes [31:0] data address R1 READ_MULTIPLE_ BLOCK Continuously transfers data blocks from card to host until interrupted by a STOP_TRANSMISSI ON command.
CMD19 Reserved.
CMD20 No --- --- --- ---
CMD21

CMD23
Reserved.
CMD24 Yes [31:0] data address R1 WRITE_BLOCK Writes a block of the size selected by the SET_BLOCKLEN command.3
CMD25 Yes [31:0] data address R1 WRITE_MULTIPLE_BLOCK Continuously writes blocks of data until a stop transmission token is sent (instead of ‘start block’).
CMD26 No --- --- --- ---
CMD27 Yes None R1 PROGRAM_CSD Programming of the programmable bits of the CSD.
CMD28 Yes [31:0] data address R1b SET_WRITE_ PROT If the card has write protection features, this command setsthe write protection bit of the addressedgroup. The properties of write protection are coded in the cardspecific data
          (WP_GRP_SIZE).
CMD29 Yes [31:0] data address R1b CLR_WRITE_ PROT If the card has write protection features, this command clears the write protection bit of the addressed group.
CMD30 Yes [31:0] write protect data address R1 SEND_WRITE_ PROT If the card has write protection features, this command asks the card to send the status of the write protection bits.
CMD31 Reserved
CMD32 Yes [31:0] data address R1 ERASE_WR_BLK_ START_ADDR Sets the address of the first write block to be erased.
CMD33 Yes [31:0] data address R1 ERASE_WR_BLK_ END_ADDR Sets the address of the last write block in a continuous range to be erased.
CMD34

CMD37
Reserved for each command system set by switch function command (CMD6). Detailed definition can be referenced in each command system specification.
CMD38 Yes [31:0] stuff bits R1b ERASE Erases all previously selected write blocks.
CMD39 No --- --- --- ---
CMD40 No --- --- --- ---
CMD41 Reserved
CMD42 Yes [31:0] stuff bits R1 LOCK_UNLOCK Used to set/re-set the password or lock/unlock the card. A transferred data block includes all thecommand details. The size of the data block is defined with SET_BLOCK_LEN command.
CMD43

CMD49
CMD51
Reserved.
CMD50 Reserved for each command system set by switch function command (CMD6). Detailed definition can be referenced in each command system specification.
CMD52

CMD54
Reserved for I/O mode (refer to SDIO Card Specification).
CMD55 Yes [31:0] stuff bits R1 APP_CMD Notifies the card that the next command is an application-specific command rather than a standard command.
CMD56 Yes [31:0] stuff bits, [0]: RD/WR4 R1 GEN_CMD Used either to transfer a Data Block to the card or to get a Data Block from the cardfor general purpose/applicationspecific commands. The size of the DataBlock is defined with SET_BLOCK_LEN command.
CMD57 Reserved for each command system set by switch function command (CMD6). Detailed definition can be referenced in each command system specification.
CMD58 Yes None R3 READ_OCR Reads the OCR Register of a card.
CMD59 Yes [31:1] stuff bits, [0:0] CRC option R1 CRC_ON_OFF Turns the CRC option on or off. A ‘1’ in the CRC option bit will turn the option on, a‘0’ will turn it off.
CMD60

CMD63
Reserved for manufacturer.
Table 5-2 SPI Bus Command Description - SanDisk SD Card Product Manual Version 2.2

MMC サポート コマンド (MMC/SPI)

CMD
INDEX
略語 内容 MMC モード SPI モード
Type Argument Resp. Argument Resp.
CMD0 GO_IDLE_STATE MMC リセット bc [31:0] Stuff bits - None R1
CMD1 SEND_OP_COND MMC R/B ポーリング動作電圧の設定 (MMC モードのみ) bcr [31:0]OCR without busy R2 None R1
CMD2 ALL_SEND_CID CID 送信要求 bcr [31:0] Stuff bits R3    
CMD3 SET_RELATIVE_ADDR RCAの設定 ac [31:16] RCA [15:0] Stuff bits R1    
CMD4 SET_DSR DSRの設定 bc [31:16] DSR [15:0] Stuff bits -    
CMD7 SELECT/ DESELECT_CARD アクセスするMMCの選択 ac [31:16] RCA [15:0] Stuff bits R1b (onlyfrom theselected card)    
CMD9 SEND_CSD CSD 送信要求 ac [31:16] RCA [15:0] Stuff bits R2 None R1
CMD10 SEND_CID CID 送信要求 ac [31:16] RCA [15:0] Stuff bits R2 None R1
CMD11 READ_DAT_UNTIL_STOP ストリームリード adtc [31:0]data address R1    
CMD12 STOP_TRANSMISSION リード、ライトストップコマンド ac [31:0] Stuff bits R1b None R1
CMD13 SEND_STATUS カードステータス要求 ac [31:16] RCA [15:0] Stuff bits R1 None R2
CMD16 SET_BLOCKLEN リードライトブロック長変更 ac [31:0]block length R1 [31:0] block length R1
CMD17 READ_SINGLE_BLOCK シングルブロックリード adtc [31:0]data address R1 [31:0] data address R1
CMD18 READ_MULTIPLE_BLOCK マルチブロックリード adtc [31:0]data address R1 [31:0] data address R1
CMD20 WRITE_DAT_UNTIL_STOP ストリームライト adtc [31:0]data address R1    
CMD23 SET_BLOCK_COUNT 転送ブロック数の指定 ac [31:16] Set to 0 [15:0] number of blocks R1 [31:16] Set to 0 [15:0] number of blocks R1
CMD24 WRITE_BLOCK シングルブロックライト adtc [31:0]data address R1 [31:0] data address R1
CMD25 WRITE_MULTIPLE_BLOCK マルチブロックライト adtc [31:0]data address R1 [31:0] data address R1
CMD26 PROGRAM_CID CIDのプログラム adtc [31:0] Stuff Bits R1    
CMD27 PROGRAM_CSD CSDのプログラム adtc [31:0] Stuff Bits R1 None R1
CMD28 SET_WRITE_PROT プロテクトの設定 ac [31:0]data address R1b [31:0] data address R1b
CMD29 CLR_WRITE_PROT プロテクトの解除 ac [31:0]data address R1b [31:0] data address R1b
CMD30 SEND_WRITE_PROT プロテクトビットステータスの送信 adtc [31:0]write protect data address R1 [31:0]write protect data address R1
CMD32 TAG_SECTOR_START イレースしたいエリアの最初のセクタを設定 ac [31:0]data address R1 [31:0] data address R1
CMD33 TAG_SECTOR_END イレースしたいエリアの最後のセクタを設定 ac [31:0]data address R1 [31:0] data address R1
CMD34 UNTAG_SECTOR_ イレースエリアの中でイレースしないセクタを設定 ac [31:0]data address R1 [31:0] data address R1
CMD35 TAG_ERASE_GROUP_START イレースしたいエリアの最初のグループを設定 ac [31:0]data address R1 [31:0] data address R1
CMD36 TAG_ERASE_GROUP_END イレースしたいエリアの最後のグループを設定 ac [31:0]data address R1 [31:0] data address R1
CMD37 UNTAG_ERASE_GROUP イレースエリアの中でイレースしないグループを設定 ac [31:0]data address R1 [31:0] data address R1
CMD38 ERASE 選択済のエリアを消去 ac [31:0] stuff bits R1b [31:0]stuff bits R1b
CMD42 LOCK_UNLOCK パスワードの設定 adtc [31:0] stuff bits R1b [31:0]stuff bits R1b
CMD58 READ_OCR OCR (動作電圧) 情報のリード       None R3
CMD59 CRC_ON_OFF CRC 仕様のON/OFF       [31:1] stuff bits [0:0] CRC option R1
表2.6 マルチメディアカードサポートコマンド一覧 - マルチメディアカード ユーザーズマニュアル

SDカード レジスタ

  • CID (Card identification number)
  • RCA (Relative card address)
  • CSD (Card specific data)
  • SCR (SD Configuration Register)
  • OCR (Operation Condition Register)

CSD (Card Specific Data)

いくつかのカードから読み出したところ、以下のような情報を得られました。

Panasonic 64MB

1 : 00 5D 01 32 13 59
2 : 83 C9 F6 D9 CF FF 16 40 00 E7
3 : B8 7D (CRC)

Canon 16MB

1 : 00 5D 01 32 13 59
2 : 80 E3 76 D9 CF FF 16 40 00 4F
3 : 88 B5 (CRC)

共通項目 (1行目)

TAAC : 500usec (5Dh)
NSAC : 1 (01h)
TRANS_SPEED (Max Transfer) 25Mb/s (32h)
CCC 0001 0011 0101 (1359hの上位12bit)
READ_BL_LEN (Max read data block length) 512bytes

実装

SDカードのコネクタはカードリーダなどを分解しても入手できますが、コネクタの変換基板を利用するのが簡単です。たとえばそれには、メモリーカード変換基板 CK-35 - サンハヤト株式会社などがあります。

参考

ドキュメント

  • SanDisk SD Card Product Manual Version 2.2
  • Simplified Specifications - Part 1:Physical Layer Specification Ver.1.01

MMC

  • マルチメディアカード ユーザーズマニュアル (ADJ-603-002B)
    MMCも基本的な仕様はSDと共通のため、参考になります。
  • HB28H016/D032/B064/B128MM2 (ADJ-203-658E (Z))

参考書