it detects SD card sometimes while does not detect SD card sometime, even it is also detecting
while no SD card is attached minorly :/.
It depends how you try to detect it. Is it by the SD card socket switch (if any)? Is it by software?
- If you have unpredictable result with the switch method, I would check if there is a pull-up or
pull-down on that switch.
Dora.
Hello!
- If you try to initialize it and get a wrong result, then there can be zillions for reasons.
Dora.
Why don't you use a known working level translation circuit?
Could you just post your initialization/detection code?
unsigned char SD_init(void)
{
unsigned char i=0, response=0;
unsigned int retry=0;
spi_init();
usart_puts("\n\r1");
_delay_ms(2);
CS_DEASSERT;
/*First 74 Clocks*/
for(i=0;i<40;i++)
SPI_rec();
/*Software Reset*/
CS_ASSERT;
for(retry=0;response != 0x01;++retry)
{
response = SD_sendCommand(GO_IDLE_STATE, 0); //send 'reset & go idle' command
if(retry > 0xfe){
CS_DEASSERT;
//usart_puts("\r\nCard not detected!");
return 1; //time out, card not detected
}
}
usart_puts("\r\nCard detected!");
retry = 0;
/**/
if(retry == 0){
do
{
response = SD_sendCommand(SD_SEND_OP_COND, 0); //activate card's initialization process
//response = SD_sendCommand(SD_SEND_OP_COND, 0); //same command sent again for compatibility with some cards
retry++;
if(retry>0xfe){retry = 0; break;} //time out
}while(response);
}
if(retry == 0){
do
{
response = SD_sendCommand(SEND_OP_COND, 0); //activate card's initialization process
//response = SD_sendCommand(SEND_OP_COND, 0); //same command sent again for compatibility with some cards
retry++;
if(retry>0xfe){usart_puts("MMC");return 1;} //time out
}while(response);
}
SD_sendCommand(CRC_ON_OFF, OFF); //disable CRC; deafault - CRC disabled in SPI mode
SD_sendCommand(SET_BLOCK_LEN, 512); //set block size to 512
CS_DEASSERT;
usart_puts("\r\nDetected\r\n");
SPI_HIGH_SPEED;
return 0; //successful return
}
void spi_init(void)
{
PORTB |= 1<<CS;
DDRB = (1<<4)|(1<<5)|(1<<7);
SPCR = 0x52; //setup spi: master mode, msb first, sck phase low, sck idle low
SPSR = 0x00;
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?