バックナンバーはこちら。
https://www.simulationroom999.com/blog/In-vehicle-external-storage-backnumber/
はじめに
SDカードの通信について。
登場人物
博識フクロウのフクさん

イラストACにて公開の「kino_k」さんのイラストを使用しています。
https://www.ac-illust.com/main/profile.php?id=iKciwKA9&area=1
エンジニア歴8年の太郎くん

イラストACにて公開の「しのみ」さんのイラストを使用しています。
https://www.ac-illust.com/main/profile.php?id=uCKphAW2&area=1
SDカードの通信種別

じゃ、そろそろSDカードの通信の具体的な話に入っていこう。

おー!

これはSPIモード、SDモード共通なんだけど、SDカードとの通信は大きく以下の種類に分けられる。
- No data Operation
- (Multiple) Block Read Operation
- (Multiple) Block Write Operation
ま、commandの大半がNo data Operationなんだけどねー。

察するにNo data Operation以外の2つは読み書きする時だけ使用するものってことかな?

その認識でOKだね。
よって、頻度としてはNo data Operation以外のこの2つが圧倒的に多いともいえる。
SDカードのNo data Operation(SPIモード)

まずはSPIモードのNo data Operationを見てみよう。


command送ってresponseを受け取るって感じだね。
commnadについて

commandのフォーマットは以下になる。
Bit position | 47 | 46 | 45:40 | 39:08 | 7:1 | 0 |
Width(bits) | 1 | 1 | 6 | 32 | 7 | 1 |
Value | ‘0’ | ‘1’ | x | x | x | ‘1’ |
Description | start bit | transmission bit | command index | argument | CRC7 | end bit |

6byte固定って感じなんだねー。
busyについて

さっきのcommandとresponseの画像の中の2つ目のやり取りのbusyってのは?

responseにも種類があって、
busy付きのresponseってのがあるんだよ。

まぁもう少し説明すると、レスポンスもバリエーションがある。
SPIモードに限定すると以下が存在する。
- R1
- R1b(STOP_TRANSMISSION,SET_WRITE_PROT,CLR_WRITE_PROT,ERASEのresponse)
- R2(SEND_STATUSのresponse)
- R3(READ_OCRのresponse)
- R7(SEND_IF_CONDのresponse)
busy付きがR1bってやつになる。

なんかややこしくなってきたぞ。

R1、R1b以外は特定commandに対するresponseなんで、一旦説明は省略して、
R1、R1bに特化して説明しよう。
SDカード SPIモード R1フォーマット

ほとんどのcommandに対するresponseになるのがR1。
フォーマットは以下になる。


内容的にはエラー通知って感じかなー。

そうだね。
in idle stateはエラーってわけでは無いが、
電源の瞬断等で初期状態に戻った場合の判定で使うことが多いから
まぁエラー的な意味合いにはなるかな。
SDカード SPIモード R1bフォーマット

次はR1bフォーマットだけど、
response自体はR1と同一。
違いは、R1の後にbusy指定が付く。

そのbusy指定ってのはどうなものなの?

0値が出力され続ける。

ほう。
ということは0値が受信され続けている間はSDカード側はbusyってことになるのか。

そういうこと。

responseについてはなんとなくわかった気がするよ。

まぁ他のresponseは必要に応じて説明だね。
まとめ

まとめだよ。
- SDカードの通信の種類は大きく3種類。
- No data Operationはcommandとresponseだけで成り立つもの。
- responseパターンはR1,R1b,R2,R3,R7の5種類。
- R1bがbusy付きresponse。
- busyはresponseの直後に0値出力が続いている間。
バックナンバーはこちら。
コメント