Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years ago.
About the time for SD card
Hi everyone. Thx for reading my question. i would like to ask the question about time for SD card. when i save the data the time always at 2028 1/1 just like below.
i would like to fix it to the now's (time date) and next time when i save the data again if it can also automatically change the newest time. Another question is how can i use the newest date and time for my txt name automatically.
#include "mbed.h" #include "SDFileSystem.h" SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board int main() { int i=0,j=1; mkdir("/sd/mydir", 0777); while(i<10){ FILE *fp = fopen("/sd/mydir/sdtest.txt", "a"); if(fp == NULL) { error("Could not open file for write\n"); } fprintf(fp,"%d\r\n",j); fclose(fp); i++; } }
Thx very much!!!
1 Answer
8 years ago.
I use a 1768 with SD Card .This is my solution:
The SD software use the RTC clock : see developer.mbed.org/questions/2431/How-to-set-Date-and-Time-of-SD-file/
You have to start the RTC and provide a backup battery during power-off. see https://developer.mbed.org/handbook/Time
I hope this can help you