I am using an STM32 micrcocontroller to interface an SD card memory using the SPI peripheral. I have done tests with 2Gb , 4Gb , 8Gb and 16Gb SanDisk cards. When I perform a reset with the 2Gb and 8Gb cards , nothing happens and I keep going with my tests. However, with 4Gb and 16Gb , once the reset is performed intialization fails . In fact , at the first insert in the SD slot , these cards are quite good initialized but one I perform the reset it does’nt pass.
When I tried to debug this problem, I discovered that when dealing a reset the response to command CMD0 is wrong . I get 0x00 instead of 0x01 which means that my card is not in Idle state.
I supposed that the problem is due to timing issues with the CS line. So , I tried to de-assert the CS before sending the CMD0 command and sending dummy bytes in order to make the card waiting 8 cloks period. Then , I send CMD0 and I assert the CS line to High. ( see below )
response = SD_SendCmd(SD_CMD_GO_IDLE_STATE, 0, 0x95, SD_ANSWER_R1_EXPECTED);
Using this solution , the Initialization passes after few reset tests. But , at any moment it can fails which is not the case with the 2Gb and 8Gb cards.