|
u8 SD_SendCommand(u8 cmd, u32 arg, u8 crc)
{
u8 r1;
u8 Retry=0;
sd_cs_1;
SPIx_ReadWriteByte(0xff); //高速写命令延时
SPIx_ReadWriteByte(0xff);
SPIx_ReadWriteByte(0xff);
//片选端置低,选中SD卡
sd_cs_0;
//发送
SPIx_ReadWriteByte(cmd | 0x40); //分别写入命令
SPIx_ReadWriteByte(arg >> 24);
SPIx_ReadWriteByte(arg >> 16);
SPIx_ReadWriteByte(arg >> 8);
SPIx_ReadWriteByte(arg);
SPIx_ReadWriteByte(crc);
//等待响应,或超时退出
while((r1=SPIx_ReadWriteByte(0xFF))==0xFF)
{
Retry++;
if(Retry>200)break;
}
//关闭片选
sd_cs_1;
//在总线上额外增加8个时钟,让SD卡完成剩下的工作
SPIx_ReadWriteByte(0xFF);
//返回状态值
return r1;
} |
|