中级会员
- 积分
- 305
- 金钱
- 305
- 注册时间
- 2016-12-7
- 在线时间
- 13 小时
|
10金钱
模拟spi低些sd卡实验,初始化时候CMD0,CMD8,CMD55返回值都正确,就发送ACMD41时一直返回0xff。代码如下:
u8 SD_Init(void)//SD¿¨¸′λ
{
volatile u8 i,response=0;
u8 buf[4];
volatile u32 count;
SpiSim_Init();
SD_CS = 1;//Ƭѡ
for(i=0;i<15;i++)
{
SpiSim_SendOneByte(0xff,0x04);//ÖáéùÑó3ù74¸öòÔéÏê±Öó£¬′Ë′|Îa120
}
SD_CS = 0;
SD_SendCMD(CMD0,0x00,0x95,0x04);
response=SD_response(0x01,50);//Ñ-»··¢ËíCMD0Ö±μ½Ïìó|Îa1»òÕß3¬ê±hile(response==0x01&&count--);
if(response==0x01)
{
SpiSim_SendOneByte(0xff,0x04);
SD_SendCMD(CMD8,0x1aa,0x87,0x04);
response=SD_response(0x01,50);
if(response==0x01)
{
for(i=0;i<4;i++)buf[i]=SpiSim_ReadOneByte(0x02);
if(buf[2]==0X01&&buf[3]==0xAA)
{
SpiSim_SendOneByte(0xFF,0x04);
SD_SendCMD(CMD58,0,0X01,0x04);
response=SD_response(0x01,50);
count=0xfffe;
do
{
SD_SendCMD(CMD55,0x00,0xff,0x04);
SD_SendCMD(CMD41,0x40000000,0xff,0x04);
response=SD_response(0x00,0x30);
count--;
if(count==0)
break;
}while(response!=0);
if(response==0)
{
SD_SendCMD(CMD58,0,0X01,0x04);
response=SD_response(0x01,50);
if(response==0)
{
for(i=0;i<4;i++)buf[i]=SpiSim_ReadOneByte(0x04);
}
}
}
}
}
return 0;
}
|
最佳答案
查看完整内容[请看2#楼]
问题解决,具体原因不知道我在网上查到的资料:
http://blog.163.com/dreamatic_al ... 045420137892747845/
按着这个上面发送完cnd55重新片选一下就好了
|