微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32 SD卡_没有加文件系统

STM32 SD卡_没有加文件系统

时间:11-13 来源:互联网 点击:

SD_MMC_SPI_SELECT();

SD_MMC_ReadWrite_Byte(0xff);
SD_MMC_ReadWrite_Byte(0xff);
SD_MMC_ReadWrite_Byte(0xff);

//发开始符 start byte 0xfe
SD_MMC_ReadWrite_Byte(0xfe);

//送512字节数据 send 512 bytes data
for(i=0; i<512; i++)
{
SD_MMC_ReadWrite_Byte(*buffer++);
}

SD_MMC_ReadWrite_Byte(0xff); //dummy crc
SD_MMC_ReadWrite_Byte(0xff); //dummy crc

Response = SD_MMC_ReadWrite_Byte(0xff);

//等待是否成功 judge if it successful
if( (Response&0x1f) != 0x05)
{
SD_MMC_SPI_DESELECT();
return Response;
}
//等待操作完 wait no busy
while(SD_MMC_ReadWrite_Byte(0xff) != 0x00)
{
if(retry++ > 0xfffe)
{
SD_MMC_SPI_DESELECT();
return 1;
}
}
SD_MMC_SPI_DESELECT();
SD_MMC_ReadWrite_Byte(0xff);// extra 8 CLK

return 0;
}

if( SD_MMC_SPI_Init() ==1)
printf(" _SD_MMC Initialization ERROR\r\n");
else
{
printf(" _SD_MMC Initialization OK\r\n");
//memset(buffer,0,512);
//读取一个扇区的内容 这里读的是0扇区
SD_MMC_Read_Single_Block( 0 , buffer );
Uart1_PutString( buffer , 512 );
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top