初级会员

- 积分
- 51
- 金钱
- 51
- 注册时间
- 2015-4-22
- 在线时间
- 7 小时
|

楼主 |
发表于 2016-6-28 08:55:10
|
显示全部楼层
我的测试代码
void SD_Card_Test( void )
{
uint32_t sd_size ;
uint8_t buf[512], hex[64];
uint8_t retry = 2;
while( SD_Init() ) // 检测不到SD卡
{
printf( "SD Card Error! \r\n" );
Delay_ms( 10 );
printf( "Please Check! \r\n" );
Delay_ms( 10 );
if( retry==0) break;
retry--;
}
SD_Type = SD_Get_Type();
switch( SD_Type )
{
case 0:
printf( "SD_TYPE_ERR\r\n" );
break;
case 1:
printf( "SD_TYPE_MMC\r\n" );
break;
case 2:
printf( "SD_TYPE_V1\r\n" );
break;
case 4:
printf( "SD_TYPE_V2\r\n" );
break;
case 6:
printf( "SD_TYPE_V2HC\r\n" );
break;
}
printf( "SD Card Initialize succssful! \r\n" );
sd_size = GetSD_Space();
printf( "SD Card Size: %dMB \r\n", sd_size );
SD_Get_CID( buf );
BinToHex( buf, 16, hex ); // 读取SD卡的ID,128Bits
printf( "SD CID: %d \r\n", hex );
Delay_ms( 10 );
//vTaskSuspendAll();
if( SD_Write( buf, 0, 1) ==0 )
{
// xTaskResumeAll();
if( SD_Read( buf, 0, 1 ) ==0 ) // 读取0扇区的内容
{
BinToHex( buf, 32, hex ); // 读取SD卡的ID,128Bits
printf( "SECTOR 0 DATA: \r\n" );
printf( "%s\r\n", hex ); // 打印0扇区数据
printf( "DATA[32] END.\r\n" );
}
else printf( "Read SD Sector 0 Error.\r\n" );
}
else printf( "Write SD Sector 0 Error.\r\n" );
} |
|