schar reset_sd(void)
{
uchar resp, n, c;
SD_CS_ON(); // CS pin of SD in high, SD deasserted
SD_PWR_OFF(); // switch SD card off
delay_3000ms(); // time-out for 3000 ms
SD_PWR_ON(); // switch SD card power on
delay_1000ms();
for (c=0; c<4; c++) // try reset command 3 times if needed
{
SD_CS_OFF();
for (n=0; n<10; n++) // initialize clk signal to sync card
_FF_spi(0xFF);
_SD_send_cmd(CMD0, 0);
for (n=0; n<200; n++)
{
resp = _FF_spi(0xFF);
if (resp == 0x1)
{
SD_CS_OFF();
return(0);
}
}
}
return ((schar)EOF);
}