AnsweredAssumed Answered

Problem reading SD card

Question asked by Laga.Freya on Mar 11, 2016
Latest reply on Mar 14, 2016 by Laga.Freya
Hi to all,
I have a big issue with SD cards.
I initialize correctly my sd card, but when I try to read a block, I can read it only the first time.
This is my routine:

=====================
uint32_t MYSD::ReadSector(uint32_t sector, uint8_t *block)
{
    uint8_t t;
    uint16_t i;
    
    
    GPIOA->BRR = 0x01<<SDSS0;    // Set SDSS0 low
    t = CommandAndResponse(SPICMD17, sector);    //Read sector command
    if(t != 0)
    {
        GPIOA->BSRR = 0x01<<SDSS0;    // Set SDSS0 high
        myusart1.PrintString((uint8_t *) "Cannot read (CMD17)", ' ', 0);
        myusart1.PrintHex8(t);
        myusart1.PrintChar('\n');
        return 1;
    }
    
    do
    {
        t = sp->Transfer8(0xFF, 0, 0);    // Wait for card response
    }
    while(t == 0xFF);
    if(t != 0xFE)
    {
        GPIOA->BSRR = 0x01<<SDSS0;    // Set SDSS0 high
        myusart1.PrintString((uint8_t *) "Cannot read (Token response)", ' ', 0);
        myusart1.PrintHex8(t);
        myusart1.PrintChar('\n');
        return 2;
    }
    
    for(i=0; i<512; i++) block[i] = sp->Transfer8(0xFF, 0, 0);    //Read data
    
    t = sp->Transfer8(0xFF, 0, 1);    // Read CRC
    t = sp->Transfer8(0xFF, 0, 1);    // Read CRC
    GPIOA->BSRR = 0x01<<SDSS0;    // Set SDSS0 high
    
    return 0;
}


=====================

and this is the tesponse:

Iteration 1: CMD17 response 0
Iteration 2: CMD17 response 4
Iteration 3: CMD17 response 0
Iteration 4: CMD17 response 4
Iteration 5: CMD17 response 0
Iteration 6: CMD17 response 4
Iteration 7: CMD17 response 0


Why I can read block in odd iterations and not  in even? The routine is always the same.

Anyone encountered the same problem?

Thank you
Freya

Outcomes