if(errorstatus==SD_OK)//SD2.0/SD 1.1,否则为MMC卡
{
//SD卡,发送ACMD41 SD_APP_OP_COND,参数为:0x80100000
while((!validvoltage)&&(count<SD_MAX_VOLT_TRIAL))//0XFFFF=65536
{
SDIO_CmdInitStructure.SDIO_Argument = 0x00;//发送CMD55,短响应
SDIO_CmdInitStructure.SDIO_CmdIndex = (u8)55; //CMD55
SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
SDIO_SendCommand(&SDIO_CmdInitStructure); //发送CMD55,短响应
errorstatus=CmdResp1Error((u8)55); //等待R1响应
if(errorstatus!=SD_OK)return errorstatus; //响应错误
//acmd41,命令参数由支持的电压范围及HCS位组成,HCS位置一来区分卡是SDSc还是sdhc
SDIO_CmdInitStructure.SDIO_Argument = 0x80100000 | SDType;//0x80100000发送ACMD41,短响应
SDIO_CmdInitStructure.SDIO_CmdIndex = 0X41;//0X41
SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //r3
SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
SDIO_SendCommand(&SDIO_CmdInitStructure);
errorstatus=CmdResp3Error(); //等待R3响应
if(errorstatus!=SD_OK)return errorstatus; //响应错误
response=SDIO->RESP1;; //得到响应
validvoltage=(((response>>31)==1)?1:0); //PPT34页,0没有完成,卡在循环里。判断SD卡上电是否完成
count++;
}
if(count>=SD_MAX_VOLT_TRIAL)//OXFFFF
{
errorstatus=SD_INVALID_VOLTRANGE;//error27
return errorstatus;
}
if(response&=SD_HIGH_CAPACITY)//PPT34页,第30页为1就是高容量
{
CardType=SDIO_HIGH_CAPACITY_SD_CARD;
}
}else//MMC卡 |