SDHC card Interface, taking long time while writing

Thread Starter

aamirali

Joined Feb 2, 2012
412
HI,

I have written SDHC code,for writing block of data.Problem is block,italic part took long time i.e around 2ms.Return byte took long time to get to zero so that condition exits, My other code has 1ms interrupt in which it has to do other task, those tasks cannot be written in interrupt. Can someone suggest me some way how to deal with this. So that when control reaches here,I can jump to take my reading of 1ms & return here after 2 ms to try again.

Or I am doing some mistake here in code & it should not take 2ms .

Rest my code is working fine, writing & reading SD card are OK.

Rich (BB code):
response = SD_Command(CMD24_WRITE_SINGLE_BLOCK , startBlock,0x00);   // if reponse not zero then there is error    // try calling sdhc_write_block again

if(response != 0)

return response; 


SD_CSenable(); //enable chip select by setting it zero

SPI_Byte( 0xfe ); // start block token 11111110b


for(i = 0; i < 512; i++) //write globally defined buffer into sd card
{
SPI_Byte(buffer1); 
}


SPI_Byte(0xff); // bogus CRC (16-bit), CRC ignored
SPI_Byte(0xff);

response = SPI_Byte(0xff);

if( (response & 0x1f) != 0x05)
{
SD_CSdisable();
return response;
}

count = 0xfffe;
while(!SPI_Byte(0xff)) // wait for write complete and go idle
{
if(count-- < 10)
{
SD_CSdisable();
return SDHC_ERR_W_TIMEOUT;
}
}

SD_CSdisable();

SPI_Byte(0xff); // 8 clock cycle delay while SS line high

SD_CSenable(); // reset SS line low to verify if card still busy

count = 0;
while(!SPI_Byte(0xff)) // wait for write complete and go idle
{
if(count++ > 0xfffe)
{
SD_CSdisable(); 
return SDHC_ERR_W_TIMEOUT;}
}
SD_CSdisable();


return SDHC_ERR_NONE;

 

davebee

Joined Oct 22, 2008
540
Does this happen on every write?

SD cards sometimes do take a long time to complete a write; as long as 35 milliseconds in some cases.

I once ran a test of timing writes as my microcontroller program wrote several thousand sequential sectors to an SD card. Most writes took only about 600 microseconds (if I remember correctly) but approximately (but not strictly) every 512 sectors, the write would have the very long delay of many milliseconds.

I assume that the card internal firmware occasionally needs the extra time to pre-erase large blocks of sectors, but that's just a guess.

If the SDHC card is behaving differently than standard SD cards, all I can suggest is to read the manufacturer's documentation to see if they warn of any possible performance issues. Or try another card.
 
Top