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 Simonr

    I don't think you understand my situation fully. Sorry for my poor explanation. So, let me explain my program structure one by one.

    In brief, I open file and write it to flash memory area on nRF52840 DK

         1. ff_result = f_open(&file, TEMPERATURE_FILE, FA_CREATE_ALWAYS | FA_WRITE);

         2.ff_result = f_write(&file, temper_info, strlen(temper_info), (UINT *) &bytes_written);

         3. file's date is always 01/01/2016

         4. I found that const variable in ffconf.h. see ffconf.h

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

         5. I found that "Timestamp" part in ff.c. See Timestamp in ff.c

                              /* Timestamp */
                             #if _FS_NORTC == 1
                             
                             #define GET_FATTIME() ((DWORD)(_NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 |                                          (DWORD)_NORTC_MDAY << 16)
                            // #define GET_FATTIME() get_fattime() //Modified 210329
                            #else
                            #define GET_FATTIME() get_fattime()
                            #endif

         6. this has to do with f_open() in ff.c like follwoing. see dw=GET_FATTIME() of f_open() in ff.c

                           

                           FRESULT f_open (
                                 FIL* fp, /* Pointer to the blank file object */
                                const TCHAR* path, /* Pointer to the file name */
                                 BYTE mode /* Access mode and file open mode flags */
                           )
                           {
                                  FRESULT res;

                                   .....

                                   ....

                        
                            if (res == FR_OK && (mode & FA_CREATE_ALWAYS)) { /* Truncate it if overwrite mode */
                            dw = GET_FATTIME();

                                     ....

         7. It's certain that we have to change  "GET_FATTIME()" in ff.c to set the date and time of opened file

         8. That's reason why I change GET_FATTIME() in ff.c.

                                      f_open() => GET_FATTIME => "#define  #define _NORTC_MON 1 #define _NORTC_MDAY 1                                                                                             #define _NORTC_YEAR 2016"

         9. When I changed GET_FATTIME() in ff.c to  

                                           #define _NORTC_MON 3
                                           # define _NORTC_MDAY 30
                                           #define _NORTC_YEAR 2021

              it works well and successfully. But, the time of the file which is opened and written is always AM 12:00 like

                                            TEMPERATURE_FILE       2021-03-30 AM 12:00 17KB

         10. In conclusion, let me know the way to change the time of file from following '#define' 

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

                in ff.c because there is no TIME related bit command(there are only YEAR, MON, DAY part).

         

          11. If you can let me know new #define command to set the time of GET_FATTIME(),  I will take care of others         

    Thanks 

    Michael Jang

Reply
  • Hi Simonr

    I don't think you understand my situation fully. Sorry for my poor explanation. So, let me explain my program structure one by one.

    In brief, I open file and write it to flash memory area on nRF52840 DK

         1. ff_result = f_open(&file, TEMPERATURE_FILE, FA_CREATE_ALWAYS | FA_WRITE);

         2.ff_result = f_write(&file, temper_info, strlen(temper_info), (UINT *) &bytes_written);

         3. file's date is always 01/01/2016

         4. I found that const variable in ffconf.h. see ffconf.h

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

         5. I found that "Timestamp" part in ff.c. See Timestamp in ff.c

                              /* Timestamp */
                             #if _FS_NORTC == 1
                             
                             #define GET_FATTIME() ((DWORD)(_NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 |                                          (DWORD)_NORTC_MDAY << 16)
                            // #define GET_FATTIME() get_fattime() //Modified 210329
                            #else
                            #define GET_FATTIME() get_fattime()
                            #endif

         6. this has to do with f_open() in ff.c like follwoing. see dw=GET_FATTIME() of f_open() in ff.c

                           

                           FRESULT f_open (
                                 FIL* fp, /* Pointer to the blank file object */
                                const TCHAR* path, /* Pointer to the file name */
                                 BYTE mode /* Access mode and file open mode flags */
                           )
                           {
                                  FRESULT res;

                                   .....

                                   ....

                        
                            if (res == FR_OK && (mode & FA_CREATE_ALWAYS)) { /* Truncate it if overwrite mode */
                            dw = GET_FATTIME();

                                     ....

         7. It's certain that we have to change  "GET_FATTIME()" in ff.c to set the date and time of opened file

         8. That's reason why I change GET_FATTIME() in ff.c.

                                      f_open() => GET_FATTIME => "#define  #define _NORTC_MON 1 #define _NORTC_MDAY 1                                                                                             #define _NORTC_YEAR 2016"

         9. When I changed GET_FATTIME() in ff.c to  

                                           #define _NORTC_MON 3
                                           # define _NORTC_MDAY 30
                                           #define _NORTC_YEAR 2021

              it works well and successfully. But, the time of the file which is opened and written is always AM 12:00 like

                                            TEMPERATURE_FILE       2021-03-30 AM 12:00 17KB

         10. In conclusion, let me know the way to change the time of file from following '#define' 

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

                in ff.c because there is no TIME related bit command(there are only YEAR, MON, DAY part).

         

          11. If you can let me know new #define command to set the time of GET_FATTIME(),  I will take care of others         

    Thanks 

    Michael Jang

Children
No Data
Related