这两处都是超时中止操作。rs的值只有三个SD_OK,SD_TIMEOUT,SD_ERROR。rs不是指令的响应。这里以发送r1类指令的代码作为参考
/**
* @brief SDCard Send Command which uses Response 1 Token
* @param cmd:Pointer of Command Structure
r1:Pointer of Response 1 Token
* @retval Operation Result Depending on Response Token
*/
static uint8_t SD_W_CMD_R1(SD_CMDTypeDef* cmd, SD_R1TypeDef* r1)
{
uint32_t tick_now = HAL_GetTick();
uint8_t rs = SD_OK;
//Add Start and Transmission bit, Add End bit
cmd->Cmd |= CMD_START;
cmd->Crc |= CMD_END;
//Card Select
SD_CS_RESET();
//Send Card Command
SD_WR_Byte(cmd->Cmd);
SD_W_Buff((uint8_t*)(&(cmd->Arg)), sizeof(cmd->Arg));
SD_WR_Byte(cmd->Crc);
do
{
if((HAL_GetTick() - tick_now) > CMD_TIMEOUT)
{
//Timeout and Return
rs = SD_TIMEOUT;
goto DONE;
}
//Get R1 Response
*r1 = SD_WR_Byte(0xFF);
}
while((*r1 & 0x80)); //wait for accurate R1 Response
DONE:
//Card Release
SD_CS_SET();
return rs;
}
具体指令返回啥值还是要翻specification,有一点要注意的是在发送完go_ilde指令后r1响应中ilde位的值很重要 |