This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to set the date and time to the file on SD card or Flash disk on nRF52840

Hi

I'm trying to file open and write for logging temperature data and others on nRF52840.

I successfully open, read and write on SD card or flash in nRF52840.

I also have used  nrf_cal_set_time(year, month-1, day, hour, minute, second) in nrf_calendar.c successfully.

It's a great and file to display date and time.

But, after file creation using f_open(), f_write() and f_close(), I found that the default date&time of the file is always 01/01/2016.

I appreciate that if you let us know what is wrong from my side and how to change or set the date & time of file property.

Thanks

Minsoo Jang

Parents
  • Hi

    It seems like you're calling the default time from the time.h library when you write to this file. Can you try setting a breakpoint at the point in time.h where the date 2016.01.01 is set to see where exactly it's called?

    Best regards,

    Simon

  • Hi

    Thank you very much for your reply.

    I found Timestamp that there is function to set the date in ff.c like:

    ff.c


    /* Timestamp */
    #if _FS_NORTC == 1
    #if _NORTC_YEAR < 1980 || _NORTC_YEAR > 2107 || _NORTC_MON < 1 || _NORTC_MON > 12 || _NORTC_MDAY < 1 || _NORTC_MDAY > 31
    #error Invalid _FS_NORTC settings
    #endif
    #define GET_FATTIME() ((DWORD)(_NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16)
    #else
    #define GET_FATTIME() get_fattime()
    #endif

    ffconf.h

    #define _FS_NORTC 1
    #define _NORTC_MON 1
    #define _NORTC_MDAY 1
    #define _NORTC_YEAR 2016

    So, I changed and made new get_fattime() in main.c  like following:

    main.c

    ...

    DWORD get_fattime(void)
    {
    DWORD date_value;
    DWORD year;
    DWORD month;
    DWORD day;

    year = (DWORD)mRTC_Timer.tm_year;
    month = (DWORD)mRTC_Timer.tm_mon;
    day = (DWORD)mRTC_Timer.tm_mday;

    if (year < 1980 || year > 2107 || month < 1 || month > 12 || day < 1 || day > 31 )
    {
          month = 1;
          day = 1;
          year = 2021;
          printf("Time data is broken, set to default value!!!\r\n");

    }

    date_value = ((DWORD)(year - 1980) << 25 | (DWORD)month << 21 | day << 16);

    return date_value;

    }

    It's working successfully by updating to new RTC date for opened file whenever it opens  and write file using f_open() and f_write().

    But, the time of modified file is always 12:00 AM like following:

    temper.csv 2021-03-29 AM 12:00

    I appreciate if you let me know how to set time value other than date for Timestamp:

    I'm sure we could use and add time value for this function

    GET_FATTIME() ((DWORD)(_NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16)

    Thanks in advance

    Michael Jang

  • Hi

    Seems like the time is called from somewhere else in your application, please try finding out where the time is called from, as it doesn't look like GET_FATTIME is able to provide the time of day.

    Best regards,

    Simon

Reply Children
No Data
Related