-->

FATFS返回FR_DISK_ERR我使用的代码相同的行中的第二时间(FATFS returns F

2019-10-30 01:23发布

我使用FATFS将数据写入SD卡。 这部分的工作,我能EEPROM数据写入SD卡。 但是,当我在后面的代码上使用不同的函数返回“FR_DISK_ERR”即使我使用相同的代码行。

我第一次尝试写SD卡如下(在这一点上我已经初始化,SD卡和取得的文件,这不是问题):

        //write EEPROM to EEPROM file
        fr = f_open(&File, file_name, FA_OPEN_APPEND | FA_WRITE);

        if (fr == FR_OK) 
        {
            //I write some data here, for company privacy purposes I have deleted this. I mainly use f_printf(&file,"data");  functions here


            /* Close the file */
            f_close(&File);
        }



        if(bEEPROMCollected && bEEPROMDataReady)
        {       
                                //stop collecting data
                bCollectEEPROM = false;                 
        }

        bEEPROMDataReady = false;

功能FR = f_open(文件,FILE_NAME,FA_OPEN_APPEND | FA_WRITE); 返回FR_OK和数据正确地写入SD卡。 每当数据已准备就绪,并收集数据后停止此函数被调用。

第二次,我把它称为编程这样的功能:

if(bWriteSDOK == true && (/*some other values are true*/)
        {
            //get current time
            RTC_GetDateTime(&rtcCurrentTime);

            fr = f_open(&File, file_name, FA_OPEN_APPEND | FA_WRITE);

            if (fr == FR_OK) 
            {
                //print the current date and time to the SD card
                f_printf(&File, "%02x/", rtcCurrentTime.date);
                f_printf(&File, "%02x/", rtcCurrentTime.month);
                f_printf(&File, "%02x ", rtcCurrentTime.year);
                f_printf(&File, "%02x:", rtcCurrentTime.hour);
                f_printf(&File, "%02x:", rtcCurrentTime.min);
                f_printf(&File, "%02x,", rtcCurrentTime.sec);


                f_printf (&File, "\r\n");                       /* Put a formatted string to the file */

                /* Close the file */
                f_close(&File);


            }
            else if(fr == FR_DISK_ERR)
            {
                PORTD |= (1 << 6);
                f_close(&File);
            }


            bWriteSDOK = false;

我不能完全显示我的代码。 我不认为它很重要。 是什么让我困惑的是,第二(不是真的第二,只是另一种功能)时我调用该函数来open_append文件,它返回一个错误(在LED上PB6点亮)。 该FATFS网站并不能完全解释的错误。 有谁知道为什么出现这种情况?

我知道代码的第二部分之前已经工作,全面测试了这个在同一硬件上。 不知怎的,该软件的第一部分建立在第二部分中的错误,这并没有改变。

我期望的代码的第一块写入16行的16个字节的EEPROM。 它有下一次,以显示其他数据,如当前的日期/时间等。

编辑:我追查回如下功能:

static FRESULT move_window (    /* Returns FR_OK or FR_DISK_ERR */
    FATFS* fs,          /* Filesystem object */
    DWORD sector        /* Sector number to make appearance in the fs->win[] */
)
{
    FRESULT res = FR_OK;


     if (sector != fs->winsect) {   /* Window offset changed? */
#if !FF_FS_READONLY
        res = sync_window(fs);      /* Write-back changes */
#endif
        if (res == FR_OK) {         /* Fill sector window with new data */
            if (disk_read(fs->pdrv, fs->win, sector, 1) != RES_OK) {
                sector = 0xFFFFFFFF;    /* Invalidate window if read data is not valid */
                res = FR_DISK_ERR;
            }
            fs->winsect = sector;
        }
    }
    return res;
}

功能 '如果(disk_read(FS-> PDRV,FS->取胜,扇区,1)!= RES_OK)' 生成FR_DISK_ERR。 这是什么意思? 它说/ *无效窗口,如果读取的数据是无效的* /,但我不读任何数据

文章来源: FATFS returns FR_DISK_ERR the second time I use an identical line of code