我现在测试MSD_WriteBuffer和MSD_ReadBuffer 是否能读写buffer ,函数返回正常值0,但是不能写入和读出sd卡的内容。 我把主程序列的下面,让大家帮我看看。
#include <stm32f10x_lib.h>
#include "sys.h"
#include "usart.h"
#include "delay.h"
#include "led.h"
#include "key.h"
#include "exti.h"
#include "wdg.h"
#include "timer.h"
#include "lcd.h"
#include "rtc.h"
#include "wkup.h"
#include "adc.h"
#include "dma.h"
#include "24cxx.h"
#include "flash.h"
#include "touch.h"
#include "24l01.h"
#include "mmc_sd.h"
u8 buf[512];//SD卡数据缓存区
u8 buf_1[512];//SD卡数据缓存区
u8 buf_2[512];//SD卡数据缓存区
u8 buf_3[512];//SD卡数据缓存区
u8 cidcid[16];
u16 num;
int main(void)
{
u32 sd_size;
u8 t=0;
Stm32_Clock_Init(9);//系统时钟设置
delay_init(72); //延时初始化
uart_init(72,9600); //串口1初始化
LCD_Init(); //初始化液晶
LED_Init(); //LED初始化
 OINT_COLOR=RED;//设置字体为红色
LCD_ShowString(60,50,"Mini STM32");
LCD_ShowString(60,70,"SD Card TEST");
LCD_ShowString(60,90,"ATOM@ALIENTEK");
LCD_ShowString(60,110,"2011/8/19");
while(SD_Init()!=0)//检测不到SD卡
{
LCD_ShowString(60,130,"SD Card Failed!");
delay_ms(500);
LCD_ShowString(60,130,"Please Check! ");
delay_ms(500);
LED0=!LED0;//DS0闪烁
}
//检测SD卡成功
LCD_ShowString(60,130,"SD Card Checked OK ");
LCD_ShowString(60,150,"SD Card Size: Mb");
sd_size=SD_GetCapacity();
LCD_ShowNum(164,150,sd_size>>20,4,16);//显示SD卡容量
while(1)
{if(t==1)//每1s钟执行一次
{
for(num=0;num<512;num++) //先给buf_2赋值,从0至511
{
buf_2[num]=num;
}
if(MSD_WriteBuffer(buf_2,0xb9d4,511)==0) // 把buf_2中的值写入SD卡
{
LCD_ShowString(15,130,"WRITE Buffer OK!");
}
delay_ms(900);
for(num=0;num<512;num++) //再给buf_2赋值全部为0xaa
{
buf_2[num]=0xaa;
}
if(MSD_ReadBuffer(buf_2,0xb9d4,511)==0) //从SD卡中读出的数据放入buf_2
{
LCD_ShowString(15,270,"READ Buffer OK!");
}
else
LCD_ShowString(15,270,"MSD READ NOT OK!");
LCD_ShowNum(10,150,buf_2[1],4,16); //开始显示buf_2中的数据
LCD_ShowNum(50,150,buf_2[2],4,16);
LCD_ShowNum(90,150,buf_2[3],4,16);
LCD_ShowNum(130,150,buf_2[4],4,16);
LCD_ShowNum(170,150,buf_2[5],4,16);
LCD_ShowNum(10,170,buf_2[6],4,16);
LCD_ShowNum(50,170,buf_2[7],4,16);
LCD_ShowNum(90,170,buf_2[8],4,16);
LCD_ShowNum(130,170,buf_2[9],4,16);
LCD_ShowNum(170,170,buf_2[10],4,16);
LCD_ShowNum(10,190,106,4,16);
LCD_ShowNum(50,190,buf_2[21],4,16);
LCD_ShowNum(90,190,buf_2[22],4,16);
LCD_ShowNum(130,190,buf_2[23],4,16);
LCD_ShowNum(170,190,buf_2[24],4,16);
LCD_ShowNum(10,210,buf_2[25],4,16);
LCD_ShowNum(50,210,buf_2[26],4,16);
LCD_ShowNum(90,210,buf_2[27],4,16);
LCD_ShowNum(130,210,buf_2[28],4,16);
LCD_ShowNum(170,210,buf_2[29],4,16);
LCD_ShowNum(10,230,buf_2[30],4,16);
LCD_ShowNum(50,230,buf_2[31],4,16);
LCD_ShowNum(90,230,buf_2[32],4,16);
LCD_ShowNum(130,230,buf_2[33],4,16);
LCD_ShowNum(170,230,buf_2[34],4,16);
t=0;
}
t++;
delay_ms(900);
}
}
|