SDHC code with SPI works on kingston card but not on Sony card

Discussion in 'General Electronics Chat' started by aamirali, Oct 7, 2013.

  1. aamirali

    Thread Starter Member

    Feb 2, 2012
    I have made SDHC interface code with SPI for kingston card, C4 4gb card. It works fine, card gets initialized properly & I can read write without any problem.

    But same code doesn't work for Sony C4,4Gb card. Card don't get initialized. I have tried many times. Card doesn't get initialized. When I send first command to CMD_GO_IDLE_STATE, it returns nack.

    I don't understand what is the problem. I can attach code if someone want to check my code. Or its hardware related problem?. Hardware is simple, card is connected via SPI port & CS pin is GPIO.

    Kingston card work fine on same card but not Sony card?
  2. nsaspook

    AAC Fanatic!

    Aug 27, 2009
  3. aamirali

    Thread Starter Member

    Feb 2, 2012
    I have checked it, problem occurs in below highlighted part of code.
    I have commented the part where I got wrong response from sony card while sandisk card send correct response
    Error at that point means there card caanot go into idle state, & also response returned i.e R1 is 0xC0. But according to card spcs, MSB should be zero of R1, but here I got 1 MSB.
    Also Bit 6 represent parameter error in R1. Why it is occuring in sony card

    Code ( (Unknown Language)):
    1. static uint8_t SD_init(void)
    2. {
    3.   uint16_t count;
    4.   uint8_t response;
    6.   delay_us(1000000);   /*  1 sec delay */
    8.   SD_CS_DISABLE();  
    9.   SD_INIT_SETTING(KHZ234);               /* initialize with 234Khz */
    10.   SD_CS_DISABLE();                       /* disable chip select */
    12.   for(count=10;count>0;count--)          /* send 80 bit long cycle to establish link with SD card */
    13.   {  
    14.     unsigned_sd_spi_byte(0xff);        /* fulfills minimum 74 clocl cycle requirement */
    15.   }
    17.   SD_CS_ENABLE();                        /* enable card */
    19.   count = 0xfffe;                    
    20.   do
    21.   {
    22.     response = SD_Command( CMD0_GO_IDLE_STATE, 0,0x95 );
    23.   } while((response != 0x01) && (--count));
    25.                                              [B]/* here response send from sony card is 0xc0  */[/B]
    26.   if( !count )
    27.     return( SDHC_ERR_TIMEOUT);
    30.   *****other part of initializing sdhc code
    31. }
    Last edited by a moderator: Oct 9, 2013
  4. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    Try sending a dummy 'SD_Command( CMD0_GO_IDLE_STATE, 0,0x95 );' command after the 'SD_CS_ENABLE();' before checking for the proper response, some cards are very slow to respond to SPI mode so you might have to wait longer for the correct response.

    I have some "hacky" SPI code to init SD cards here.
  5. aamirali

    Thread Starter Member

    Feb 2, 2012
    I have tried that also but even that didn't work.
    I now suspect that if sony card support SPI in their card or not. I am attaching image of both card in zip file.

    Also I have a memory card reader , in that sony card gets read fine. I think the memory cards works on SDIO interface that's why.
  6. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    Check the voltage to the card to be sure it's exactly 3.3 volts, some cards are very picky about supply voltages under SPI. SANDISK cards are very robust but others can be picky.