我看了一下堆棧溢出問題Initialization of a microSD card using an SPI interface並沒有看到與我的問題相匹配的任何答案(即,我還沒有試過的東西)。在SPI問題中初始化SD卡
我有一個類似的問題,我試圖通過微控制器的SPI接口(特別是HC908)訪問SD卡。我已經嘗試遵循物理層簡化規範v2.00中的流程圖,並且似乎在創見1上正確初始化,並且似乎在GB卡上正確初始化。但是我從我的照相機中使用的那些舊存儲卡中的其他三張隨機卡中遇到了問題。
我的代碼全部是HC908彙編器。我確定了SPI時鐘線的範圍,初始化期間它的運行頻率大約爲350 kHz(HC908在我的低MCU時鐘速度下提供的唯一倍速器,落在100 - 400 kHz窗口內)。
這裏有三張牌未完成我的初始化程序的結果(連續全部完成而無需改變任何代碼或定時參數):
Canon 16Meg card (labeled as SD):
Set card select high
Send 80 SPI clock cycles (done by writing 0xFF 10 times)
Set card select low
Send CMD0 [0x400000000095] and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x01 (indicates idle)
Send CMD8 [0x48000001AA87] and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x05 (idle and illegal command)
Because illegal command set local flag to indicate v1 or MMC card
Send CMD58 [0x7A00000000FD] and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x05 (idle and illegal command)
because illegal command branch to error routine
Send CMD13 [0x4D000000000D] (show status buffer) and Loop up to 8 times waiting for high bit on response to go low
R1= 0x05 (idle and illegal command)
是非法命令標誌卡?我應該在CMD8之後做些什麼來清除那個標誌?
SanDisk UltraII 256Meg
Set card select high
Send 80 SPI clock cycles (done by writing 0xFF 10 times)
Set card select low
Send CMD0 [0x400000000095] and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x01 (idle)
Send CMD8 [0x48000001AA87] and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x05 (idle and illegal command)
Because illegal command set local flag to indicate v1 or MMC card
Send CMD58 [0x7A00000000FD] and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x01 (idle)
Send 0xFF 4 times to read OCR
OCR = 0xFFFFFFFF
Send CMD55 [0x770000000065] (1st part of ACMD41) and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x01 (idle)
Send CMD41 [0x6900000000E5] (2nd part of ACMD41) and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x05 (idle and illegal command)
Because illegal command, assume card is MMC
Send CMD1 [0x4100000000F9] (for MMC) and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x05 (idle and illegal command)
Repeat the CMD1 50 times (my arbitrary number to wait until idle clears)
Every R1 response is 0x05 (idle and illegal command)
爲什麼OCR都是F?看起來不合適。另外,爲什麼ACMD41和CMD1會響應非法命令?即使命令響應非法,卡CMD55等待有效的ACMD,CMD1是否失敗?
SanDisk ExtremeIII 2G:
Set card select high
Send 80 SPI clock cycles (done by writing 0xFF 10 times)
Set card select low
Send CMD0 [0x400000000095] and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x01 (idle)
Send CMD8 [0x40000001AA87] and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x7F (??? My loop shows the responses for each iteration and I got 0xFF 0xFF 0xC1 0x7F... is the card getting out of sync?)
Send CMD58 [0x7A00000000FD] and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x01 (idle and back in sync)
Send 0xFF 4 times to read OCR
OCR = 0x00FF80
Send CMD55 [0x770000000065] (1st part of ACMD41) and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x5F (??? loop responses are 0xFF 0xFF 0xF0 0x5F... again out of sync?)
Send CMD41 [0x6900000000E5] (2nd part of ACMD41) and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x05 (idle and illegal command, but back in sync???)
Because illegal command, assume card is MMC
Send CMD1 [0x4100000000F9] (for MMC) and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x7F (??? loop responses are 0xFF 0xFF 0xC1 0x7F... again out of sync?)
Repeat CMD1 and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x01 (idle)
Repeat CMD1 and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x7F (??? loop responses are 0xFF 0xFF 0xC1 0x7F... again out of sync?)
Repeat CMD1 and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x00 (out of idle)
Send CMD9 [0x4900000000AF] (get CSD) and Loop up to 8 times waiting for high bit on response to go low
R1 = 0x3F (??? loop responses are 0xFF 0xFF 0xC1 0x3F... again out of sync?)
Code craps out because Illegal command bit is high.
那張卡在地上有什麼問題?
有時它是同步的,其他時間不是。 (上面的模式是可重複。)我已經確定了這一點,並且我沒有看到MOSI/MISO傳輸之間有任何流氓時鐘週期。
忘了提。在這些嘗試初始化3張卡失敗後,我將它們放入筆記本電腦的SD卡讀卡器中,我仍然可以將它們作爲標準SD卡(讀取和寫入)不帶任何問題進行訪問。 – Sembazuru 2010-03-02 19:27:46
在「SanDisk ExtremeIII」的命令列表中發現了一個錯誤:發送CMD8 [0x40000001AA87] - 它應該是0x48,而不是0x40。 – 2014-04-19 15:06:55