SDHC card Interface, taking long time while writing

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SDHC card Interface, taking long time while writing

437 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by aamir ali on Thu Dec 13 04:49:08 MST 2012
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.


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

[B][U]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();[/U][/B]


return SDHC_ERR_NONE;
0 Kudos
Reply
0 Replies