Report
1 year, 6 months 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. /media/uploads/david8251/sd.png

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!!!

Comment on this question

1 Answer

1 year, 6 months 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

THx!!!

posted by jajn HA 28 Dec 2016

To post an answer, please log in.