各位高手好,小弟最近才入手STM32,在调试SD卡和TF卡时候,遇上了如题的问题,目前SD卡读写一切正常,但是调试TF卡(套了个SD卡套)时,发送CMD17命令之后,始终无法得到0xFE的应答,总是超时退出,请大家帮忙分析一下是什么原因,万分感谢!!!
等待应答函数如下:
SD_Error TFSD_ReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t BlockSize)
{
uint32_t i = 0;
SD_Error rvalue = SD_RESPONSE_FAILURE;
static u8 temp = 0;
/*!< SD chip select low */
SD_CS = EN_CS;
/*!< Send CMD17 (SD_CMD_READ_SINGLE_BLOCK) to read one block */
TFSD_SendCmd(CMD17, ReadAddr, 0xFF);
/*!< Check if the SD acknowledged the read block command:
R1 response (0x00: no errors) */
temp = TFSD_GetResponse(SD_RESPONSE_NO_ERROR);
if (!temp)
{
/*!< Now look for the data token to signify the start of the data */
if (!TFSD_GetResponse(0xFE))
{
/*!< Read the SD block data : read NumByteToRead data */
for (i = 0; i < BlockSize; i++)
{
/*!< Save the received data */
*pBuffer = SD_ReadByte();
*
/*!< Point to the next location where the byte read will be saved */
pBuffer++;
}
/*!< Get CRC bytes (not really needed by us, but required by SD) */
SD_ReadByte();
SD_ReadByte();
/*!< Set response value to success */
rvalue = SD_RESPONSE_NO_ERROR;
}
}
/*!< SD chip select high */
SD_CS = DIS_CS;
/*!< Send dummy byte: 8 Clock pulses of delay */
SD_WriteByte(0xFF);
/*!< Returns the reponse */
return rvalue;
}
SD_Error TFSD_GetResponse(uint8_t Response)
{
uint32_t Count = 0xFFFFF;
while ((SD_ReadByte() != Response) && Count)
{
Count--;
}
if (Count == 0)
{
return SD_RESPONSE_FAILURE;
}
else
{
return SD_RESPONSE_NO_ERROR;
}
} |