Initializating SanDisk SD card using SPI fails aft

2019-05-11 08:22发布

问题:

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 )

SD_IO_CSState(0);
SD_IO_WriteByte(SD_DUMMY_BYTE);
response = SD_SendCmd(SD_CMD_GO_IDLE_STATE, 0, 0x95, SD_ANSWER_R1_EXPECTED);
SD_IO_CSState(1);
SD_IO_WriteByte(SD_DUMMY_BYTE);

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.

Any suggestions to solve it ??

回答1:

I am also facing the exact same issue with my 24 GB SanDisk SD Card. What I have learnt is that perhaps SD Cards once initialized in SPI mode don't accept CMD0 again (which is the software reset command!), the only method to bring them back to initial state is to perform their power cycle.