Pages: 1 [2]   Go Down
Author Topic: fat16lib vs SD standard library  (Read 3145 times)
0 Members and 1 Guest are viewing this topic.
Smithfield, Rhode Island
Offline Offline
God Member
*****
Karma: 2
Posts: 843
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Many applications write a "record" of data and then call sync().  I just can't automatically do the "right thing" in the library.

Got it, thanks very much, that is a huge help. I'll do what I do with Fat16 then, track the amount of data written and then call sync() about every 512 bytes. If I understand correctly, this is the most efficient way to use the library, yes?

Last question, I hope. If i don't call close will I corrupt data? I know I'll lose all data since the last sync() call when the user hits the switch or pulls the card, but will the file and file system be okay other than loosing the last bit of data?


Logged

0
Offline Offline
Edison Member
*
Karma: 44
Posts: 1484
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

close() just calls sync() and marks the file closed so you won't lose data.
Code:
bool SdFile::close() {
  if (sync()) {
    type_ = FAT_FILE_TYPE_CLOSED;
    return true;
  }
  return false;
}
What works for Fat16 should work for SdFat.
Logged

Smithfield, Rhode Island
Offline Offline
God Member
*****
Karma: 2
Posts: 843
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Awesome! Thanks for your help, and for the library!
Logged

Berlin
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I am having an issue. I can not get any of the sample apps to compile. The compiler complains of an error on line 40 of ArduinoStream.h: expected ')' before '&' token. I took a look and the reference parameter seemed to be declared correctly.

I tried several of the example files and each one gave me the same error. I'll try the SD classes without the stream IO and see if I have better luck.
 

I ran into the same problem today and found the solution to have nothing to do with Sanguino at all.
And why should it.

I am using a Diecemilia and got the same error.
The example code on the other hand compiled fine.

The solution was, not to use the Sketch->Import Library->(contributed)SdFat function of the IDE.
Wehn doing so, the IDE places #include statements for all headers in the libraries folder into the source of the sketch.
the #include <ArduinoStream.h> is at the top of the list in this case.

Simply removing all the #includes and adding
#include <SdFat.h>
#include <SdFile.h>
manually solved the problem. (for my sketch, anyway, I am using only those).

It puzzles me that you got the error when compiling the sample code, because that is only including the necessary headers, it seems.

And btw: Thanks to William for the excellent work.

hase
Logged

Hartmut "hase" Semken

0
Offline Offline
Edison Member
*
Karma: 44
Posts: 1484
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I designed SdFat so you only need
Code:
#include <SdFat.h>
for most sketches. 

SdFatUtil.h is needed if you use FreeRam(), PgmPrint(), or PgmPrintln().

Including all the .h files can cost up to 3500 bytes of flash.  The IDE scans these files and forces the loading of some functions that are not needed in the average sketch.

I will fix ArduinoStream.h so it doesn't produce a compile error but it should not be included at the start of a sketch.

Thanks for the feedback.  I will add a caution to the documentation. 
Logged

Pages: 1 [2]   Go Up
Jump to: