SD发送一个命令函数如下:
u8 SD_SendCommand(u8 cmd, u32 arg,u8 crc)
{
unsigned char r1;
unsigned int Retry = 0;
SD_CS_DISABLE();
SPI_ReadWriteByte(0xff);
SD_CS_ENABLE();//片选端置低,选中SD卡
/* 发送命令序列 */
SPI_ReadWriteByte(cmd | 0x40);
SPI_ReadWriteByte((u8)(arg >> 24));//参数[31..24]
SPI_ReadWriteByte((u8)(arg >> 16));//参数[23..16]
SPI_ReadWriteByte((u8)(arg >> 8));//参数[15..8]
SPI_ReadWriteByte((u8)arg); //参数[7..0]
SPI_ReadWriteByte(crc);
//等待响应,或超时退出
while((r1 = SPI_ReadWriteByte(0xFF))==0xFF)
{
Retry++;
if(Retry > 800)break;
}
//关闭片选
SD_CS_DISABLE();
//在总线上额外增加8个时钟,让SD卡完成剩下的工作
SPI_ReadWriteByte(0xFF);
//返回状态值
return r1;
}
其中
while((r1 = SPI_ReadWriteByte(0xFF))==0xFF)
{
Retry++;
if(Retry > 800)break;
}
意思是不是(r1 = SPI_ReadWriteByte(0xFF))==0xFF成立 retry++,直到retry>800,break,此时r1的值为0xff。
return r1;此时r1不是0xff吗?
(r1 = SPI_ReadWriteByte(0xFF))==0xFF不成立不就直接执行 SD_CS_DISABLE();了吗?此时r1的值是什么呢? |