模拟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;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
应该不是卡的事,我的卡在你的mini板子上面能正常使用的,我的是sdhc卡,发送过程:CM0返回0x01——》CMD8返回0x01,0x00,0x00,0x01,0xAA——》循环发送:cmd55返回0x01+发送cmd41,发送一次CMD41返回一次0x01,
一周热门 更多>