FATFS returns FR_DISK_ERR the second time I use an identical line of code
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am using FATFS to write data to an SD card. It partially works and I am able to write EEPROM data to the SD card. But when I use a different function later on in the code it returns 'FR_DISK_ERR' even though I'm using the same line of code.
The first time I try to write to the SD card is as follows (At this point I have already initialized the SD card and made the file, that is not the issue):
//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;
The function fr = f_open(&File, file_name, FA_OPEN_APPEND | FA_WRITE); returns FR_OK and correctly writes the data to the SD card. This function is called whenever data is ready and stops after the data is collected.
The second time I Call the function it is programmed like this:
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, "rn"); /* 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;
I can't display my code fully. I don't think it matters. What confuses me is that the second (not really second, just another function) time I call the function to open_append the file, it returns an error (the LED on PB6 turns on). The FATFS website doesn't fully explain the error. Does anyone know why this happens?
I know the second part of the code has worked before and fully tested this on the same hardware. Somehow the first part of the software created a bug in the second part, which has not changed.
I expect the first piece of code to write 16 lines of 16 bytes of EEPROM. The next time it has to show other data, like current date/time etc.
EDIT:
I have traced it back to the following function:
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;
}
the function 'if (disk_read(fs->pdrv, fs->win, sector, 1) != RES_OK)' generates the FR_DISK_ERR. What does this mean? It says /* Invalidate window if read data is not valid */, but I am not reading any data
c arduino avr atmega fatfs
add a comment |
I am using FATFS to write data to an SD card. It partially works and I am able to write EEPROM data to the SD card. But when I use a different function later on in the code it returns 'FR_DISK_ERR' even though I'm using the same line of code.
The first time I try to write to the SD card is as follows (At this point I have already initialized the SD card and made the file, that is not the issue):
//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;
The function fr = f_open(&File, file_name, FA_OPEN_APPEND | FA_WRITE); returns FR_OK and correctly writes the data to the SD card. This function is called whenever data is ready and stops after the data is collected.
The second time I Call the function it is programmed like this:
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, "rn"); /* 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;
I can't display my code fully. I don't think it matters. What confuses me is that the second (not really second, just another function) time I call the function to open_append the file, it returns an error (the LED on PB6 turns on). The FATFS website doesn't fully explain the error. Does anyone know why this happens?
I know the second part of the code has worked before and fully tested this on the same hardware. Somehow the first part of the software created a bug in the second part, which has not changed.
I expect the first piece of code to write 16 lines of 16 bytes of EEPROM. The next time it has to show other data, like current date/time etc.
EDIT:
I have traced it back to the following function:
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;
}
the function 'if (disk_read(fs->pdrv, fs->win, sector, 1) != RES_OK)' generates the FR_DISK_ERR. What does this mean? It says /* Invalidate window if read data is not valid */, but I am not reading any data
c arduino avr atmega fatfs
Too many things could go wrong. The exact value offr
would be most helpful.
– user58697
Jan 4 at 22:13
@user58697 the error I get is FR_DISK_ERR, which has a value of 1. I can't find any information on this error.
– Jordi de Bruin
Jan 7 at 8:02
I've been going through ff.c and it seems there are a lot of ways that the FR_DISK_ERR could be generated, and none of them seem easily traceable
– Jordi de Bruin
Jan 7 at 8:23
I have traced it back to the following function in ff.c: static FRESULT move_window ( /* Returns FR_OK or FR_DISK_ERR */
– Jordi de Bruin
Jan 7 at 11:56
add a comment |
I am using FATFS to write data to an SD card. It partially works and I am able to write EEPROM data to the SD card. But when I use a different function later on in the code it returns 'FR_DISK_ERR' even though I'm using the same line of code.
The first time I try to write to the SD card is as follows (At this point I have already initialized the SD card and made the file, that is not the issue):
//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;
The function fr = f_open(&File, file_name, FA_OPEN_APPEND | FA_WRITE); returns FR_OK and correctly writes the data to the SD card. This function is called whenever data is ready and stops after the data is collected.
The second time I Call the function it is programmed like this:
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, "rn"); /* 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;
I can't display my code fully. I don't think it matters. What confuses me is that the second (not really second, just another function) time I call the function to open_append the file, it returns an error (the LED on PB6 turns on). The FATFS website doesn't fully explain the error. Does anyone know why this happens?
I know the second part of the code has worked before and fully tested this on the same hardware. Somehow the first part of the software created a bug in the second part, which has not changed.
I expect the first piece of code to write 16 lines of 16 bytes of EEPROM. The next time it has to show other data, like current date/time etc.
EDIT:
I have traced it back to the following function:
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;
}
the function 'if (disk_read(fs->pdrv, fs->win, sector, 1) != RES_OK)' generates the FR_DISK_ERR. What does this mean? It says /* Invalidate window if read data is not valid */, but I am not reading any data
c arduino avr atmega fatfs
I am using FATFS to write data to an SD card. It partially works and I am able to write EEPROM data to the SD card. But when I use a different function later on in the code it returns 'FR_DISK_ERR' even though I'm using the same line of code.
The first time I try to write to the SD card is as follows (At this point I have already initialized the SD card and made the file, that is not the issue):
//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;
The function fr = f_open(&File, file_name, FA_OPEN_APPEND | FA_WRITE); returns FR_OK and correctly writes the data to the SD card. This function is called whenever data is ready and stops after the data is collected.
The second time I Call the function it is programmed like this:
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, "rn"); /* 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;
I can't display my code fully. I don't think it matters. What confuses me is that the second (not really second, just another function) time I call the function to open_append the file, it returns an error (the LED on PB6 turns on). The FATFS website doesn't fully explain the error. Does anyone know why this happens?
I know the second part of the code has worked before and fully tested this on the same hardware. Somehow the first part of the software created a bug in the second part, which has not changed.
I expect the first piece of code to write 16 lines of 16 bytes of EEPROM. The next time it has to show other data, like current date/time etc.
EDIT:
I have traced it back to the following function:
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;
}
the function 'if (disk_read(fs->pdrv, fs->win, sector, 1) != RES_OK)' generates the FR_DISK_ERR. What does this mean? It says /* Invalidate window if read data is not valid */, but I am not reading any data
c arduino avr atmega fatfs
c arduino avr atmega fatfs
edited Jan 7 at 11:59
Jordi de Bruin
asked Jan 4 at 14:35
Jordi de BruinJordi de Bruin
53
53
Too many things could go wrong. The exact value offr
would be most helpful.
– user58697
Jan 4 at 22:13
@user58697 the error I get is FR_DISK_ERR, which has a value of 1. I can't find any information on this error.
– Jordi de Bruin
Jan 7 at 8:02
I've been going through ff.c and it seems there are a lot of ways that the FR_DISK_ERR could be generated, and none of them seem easily traceable
– Jordi de Bruin
Jan 7 at 8:23
I have traced it back to the following function in ff.c: static FRESULT move_window ( /* Returns FR_OK or FR_DISK_ERR */
– Jordi de Bruin
Jan 7 at 11:56
add a comment |
Too many things could go wrong. The exact value offr
would be most helpful.
– user58697
Jan 4 at 22:13
@user58697 the error I get is FR_DISK_ERR, which has a value of 1. I can't find any information on this error.
– Jordi de Bruin
Jan 7 at 8:02
I've been going through ff.c and it seems there are a lot of ways that the FR_DISK_ERR could be generated, and none of them seem easily traceable
– Jordi de Bruin
Jan 7 at 8:23
I have traced it back to the following function in ff.c: static FRESULT move_window ( /* Returns FR_OK or FR_DISK_ERR */
– Jordi de Bruin
Jan 7 at 11:56
Too many things could go wrong. The exact value of
fr
would be most helpful.– user58697
Jan 4 at 22:13
Too many things could go wrong. The exact value of
fr
would be most helpful.– user58697
Jan 4 at 22:13
@user58697 the error I get is FR_DISK_ERR, which has a value of 1. I can't find any information on this error.
– Jordi de Bruin
Jan 7 at 8:02
@user58697 the error I get is FR_DISK_ERR, which has a value of 1. I can't find any information on this error.
– Jordi de Bruin
Jan 7 at 8:02
I've been going through ff.c and it seems there are a lot of ways that the FR_DISK_ERR could be generated, and none of them seem easily traceable
– Jordi de Bruin
Jan 7 at 8:23
I've been going through ff.c and it seems there are a lot of ways that the FR_DISK_ERR could be generated, and none of them seem easily traceable
– Jordi de Bruin
Jan 7 at 8:23
I have traced it back to the following function in ff.c: static FRESULT move_window ( /* Returns FR_OK or FR_DISK_ERR */
– Jordi de Bruin
Jan 7 at 11:56
I have traced it back to the following function in ff.c: static FRESULT move_window ( /* Returns FR_OK or FR_DISK_ERR */
– Jordi de Bruin
Jan 7 at 11:56
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54040975%2ffatfs-returns-fr-disk-err-the-second-time-i-use-an-identical-line-of-code%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54040975%2ffatfs-returns-fr-disk-err-the-second-time-i-use-an-identical-line-of-code%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Too many things could go wrong. The exact value of
fr
would be most helpful.– user58697
Jan 4 at 22:13
@user58697 the error I get is FR_DISK_ERR, which has a value of 1. I can't find any information on this error.
– Jordi de Bruin
Jan 7 at 8:02
I've been going through ff.c and it seems there are a lot of ways that the FR_DISK_ERR could be generated, and none of them seem easily traceable
– Jordi de Bruin
Jan 7 at 8:23
I have traced it back to the following function in ff.c: static FRESULT move_window ( /* Returns FR_OK or FR_DISK_ERR */
– Jordi de Bruin
Jan 7 at 11:56