1

我从我的 SD 卡(CMD8、CMD55 和 CMD41)收到无效的响应代码。

初始化例程:

SDCS = 1; // MMC deaktiviert
SPI1CON1bits.SMP = 0;
SPI1CON1bits.CKE = 1;
SPI1CON1bits.MSTEN = 1;
SPI1CON1bits.CKP = 0;
SPI1STATbits.SPIEN = 1;

for(i=0; i<10; i++)
    SPI(0xFF);

// RESET
unsigned char rr=Command(CMD0,0);
SDCS=1; // MMC deactivated
/* OK response == 1 */

r = Command(CMD8,0); // Check voltage
SDCS=1;
/*
  esponse ==  0xC1 ?!?
*/

r = Command(CMD58,0); // READ_OCR

unsigned char ocr1 = SPI(0xFF);
unsigned char ocr2 = SPI(0xFF);
unsigned char ocr3 = SPI(0xFF);
unsigned char ocr4 = SPI(0xFF);
unsigned char ocr5 = SPI(0xFF);

/*
  r = 0xF8; ?!?
  ocr1 = 0x0F;
  ocr2 = 0xFF;
  ocr3 = 0xFF;
  ocr4 = 0xFF;
  ocr5 = 0xFF;
*/

SDCS=1;

// INIT
unsigned char rrr = 0;
i = 10000;
do
{
    rrr = Command(55,0); // Next is APP CMD
    SDCS = 1;
    if(r)
        break;
} while(--i>0);

/*
OK response == 1
*/

// APP CMD 41 with OCR = 0x0F??

您可以在评论中阅读响应代码。

响应代码是否可能CMD80xC1?第 7 位应该是 0,对吧?

是硬件错误吗?

4

1 回答 1

1

可以在 Stack Overflow 问题Initializing SD card in SPI issues中找到解决方案。

简而言之:在每个命令之前(CMD0 除外),发送0xFF直到您得到0xFF响应。

于 2010-08-04T18:50:07.697 回答