Go Down

Topic: SD Card Close File (Read 136 times) previous topic - next topic

ClaireB

Dear all,

I'm connecting my Arduino to an Adafruit SD Card Breakout Board. I followed the tutorial that adafruit provides and used the same functions. I need to log data in a fast way on my SD card, however I did some tests and noticed that writing to the SD card takes around 4ms: in particular what I do is:
- open file where I want to write on,
- write data on it,
- close file.

This process takes, for example:
- opening: 37 microseconds,
- writing: 166 microseconds,
- closing: 3353 microseconds.
For a total of 3.5 ms.
I obtained the times by getting the microseconds with micros() before and after every action.

What I don't understand is if this is normal or if I'm doing something wrong. Does someone have the same issue?
Is there a way to make the closing process faster?

I'm still a newbie in the electronics department so don't be too harsh with me please!

Thanks!

Claire

PaulS

Quote
What I don't understand is if this is normal
Yes. Writing to the card actually writes to a buffer, until the buffer gets full. If you were writing less than 512 characters, the buffer never got full.

Closing the file actually copies the partial buffer to the file, and closes the file. It is that copying of the buffer to the file that takes most of the time.

Quote
Is there a way to make the closing process faster?
If you flush() the file periodically, the buffer will be empty when you close the file, so the close will be very quick.

Of course, all you've done then is change where the bottleneck occurs.
The art of getting good answers lies in asking good questions.

Go Up