硬件重置后,使用SPI初始化SanDisk SD卡失败 [英] Initializating SanDisk SD card using SPI fails after doing HW reset

查看:565
本文介绍了硬件重置后,使用SPI初始化SanDisk SD卡失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用STM32微控制器通过SPI外设连接SD卡存储器。
我已经使用2Gb,4Gb,8Gb和16Gb SanDisk卡进行了测试。
当我使用2Gb和8Gb卡执行重置时,什么也没有发生,因此我继续进行测试。但是,对于4Gb和16Gb,一旦执行重置,初始化就失败了。实际上,在SD插槽中的第一个插入处,这些卡已经很好地初始化了,但是我执行了一次重置却没有通过。

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.

当我尝试调试时这个问题,我发现进行复位时,对命令CMD0的响应是错误的。我得到的是0x00而不是0x01,这意味着我的卡没有处于空闲状态。

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.

我认为问题是由于CS线路的时序问题引起的。因此,在发送CMD0命令和发送虚拟字节之前,我尝试取消CS的置位,以使卡等待8个时钟周期。然后,我发送CMD0并将CS线断言为高电平。 (请参见下文)

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);

使用此解决方案,初始化会在几次重置测试后通过。但是,在任何时候它都可能会失败,而2Gb和8Gb卡并非如此。

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 ??

推荐答案

我的24 GB SanDisk SD卡也面临完全相同的问题。我了解到,也许一旦以SPI模式初始化的SD卡就不再接受CMD0(这是软件重置命令!),使它们恢复初始状态的唯一方法是执行电源循环。

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.

这篇关于硬件重置后,使用SPI初始化SanDisk SD卡失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆