各位大神:
小弟最近调试裸机版本的SD卡读写测试程序,发现在仿真的时候 时对时错,很不稳定。
数据报错的时候提示数据CRC错误。
各位大神有没有类似的经历或者经验介绍,期待各位的帮忙。
DMA读写方式,附部分源码
/**
* @brief Tests the SD card Single Blocks operations.
* @param None
* @retval None
*/
void SD_SingleBlockTest(void)
{
/*------------------- Block Read/Write --------------------------*/
/* Fill the buffer to send */
Fill_Buffer(Buffer_Block_Tx, BLOCK_SIZE, 0x320F);
if (Status == SD_OK)
{
/* Write block of 512 bytes on address 0 */
Status = SD_WriteBlock(Buffer_Block_Tx, 0x00, BLOCK_SIZE);
/* Check if the Transfer is finished */
Status = SD_WaitWriteOperation();
while(SD_GetStatus() != SD_TRANSFER_OK);
}
if (Status == SD_OK)
{
/* Read block of 512 bytes from address 0 */
Status = SD_ReadBlock(Buffer_Block_Rx, 0x00, BLOCK_SIZE);
/* Check if the Transfer is finished */
Status = SD_WaitReadOperation();
while(SD_GetStatus() != SD_TRANSFER_OK);
}
/* Check the correctness of written data */
if (Status == SD_OK)
{
TransferStatus1 = Buffercmp(Buffer_Block_Tx, Buffer_Block_Rx, BLOCK_SIZE);
}
if(TransferStatus1 == PASSED)
{
STM_EVAL_LEDOn(LED2);
}
else
{
STM_EVAL_LEDOff(LED2);
STM_EVAL_LEDOn(LED4);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
现将暂时解决方案附上,望对后来者可以有所启发。
(1) 24M CLK ,SD卡 1bit
(2) 8M以下时钟,SD卡 4bit,会有一定几率,但是相比24MCLK 4bit要低很多很多
问题猜测:
SD卡座距离CPU较远,10 cm左右的样子,配置为1bit 可以有效的解决数据错位的问题。降低CLK速率,可以有效解决误码问题。
一周热门 更多>