This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

28377D SD卡读写问题



由于没有接触过SD卡,经过这两天的接触,在开发板(采用SPI方式)上修改control提供的demo程序,有个问题请教大家:

变量定义如下:

static FATFS g_sFatFs;

BYTE textFileBuffer[] = {0,1,2,3,4,5};
FRESULT res=FR_OK;
WORD br;
FIL fsrc;         /* file objects */

FRESULT fresult;
 char m[]="0:/fatfs.txt";

主流程如下(demo中 while(1)之后的程序被我屏蔽了):

 fresult = f_mount(0, &g_sFatFs);
    if(fresult != FR_OK)
    {
        UARTprintf("f_mount error: %s\n", StringFromFresult(fresult));
        return(1);
    }
    res = f_open( &fsrc , m , FA_CREATE_ALWAYS | FA_WRITE);//FA_CREATE_NEW | FA_WRITE);

           if ( res == FR_OK )
        {
          /* Write buffer to file */
          res = f_write(&fsrc, textFileBuffer, sizeof(textFileBuffer) , &br);
          /*close file */
          f_close(&fsrc); 
        }  asm(" ESTOP0");

程序执行结果:

SD卡创建了fatfs.txt,但是没有内容,单步调试,发现 f_write的执行结果是FR_RW_ERROR,这个是什么原因呢?

另外,个人感觉TI提供的这个demo不怎么样,底层驱动mmc-F2837x.C写得很乱,不规范,而且FATFS居然是用R0.04b版本,ff.c里面删除很多函数,程序详见附件。

SD20150805154736.rar