views:

210

answers:

1

I get invalid response Codes from my SD Card(CMD8, CMD55, CMD41)

Init routine:

  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;
  /*
 response ==  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??

You can read the response codes in the comments.

Is it possible the response code to CMD8 is 0xC1? Bit 7 should be 0, right?

Is it a hardware error?

A: 

Solution can be found here: http://stackoverflow.com/questions/2365897/initializing-sd-card-in-spi-issues

In short: Before each Command (except CMD0) send 0xFF until you get 0xFF as response.

Turbo J