Hi, I'm using RL-flash and I would like to know how to set for create FAT file with time/date from RTC. All my files are 01/01/2008 12:00. Which register i can set to update this time and date? Thanks
This is how it may look like:
U32 fs_get_time (void) { U32 h,m,s,time; h = (U8)RTC_GetTime(LPC_RTC, RTC_TIMETYPE_HOUR); m = (U8)RTC_GetTime(LPC_RTC, RTC_TIMETYPE_MINUTE); s = (U8)RTC_GetTime(LPC_RTC, RTC_TIMETYPE_SECOND); time = (h << 16) | (m << 8) | s; return (time); } U32 fs_get_date (void) { U32 d,m,y,date; d = (U8)RTC_GetTime(LPC_RTC, RTC_TIMETYPE_DAYOFMONTH); m = (U8)RTC_GetTime(LPC_RTC, RTC_TIMETYPE_MONTH); y = (U8)RTC_GetTime(LPC_RTC, RTC_TIMETYPE_YEAR); date = (y << 16) | (m << 8) | d; return (date); } //in main file, in the function where file is created void FILE_Create() { ... fs_get_time(); fs_get_date(); file = fopen(filepath, "w"); ... }
RTC must be initialised and enabled before it is to be used, even if the RTC has a battery back up. The date, time registers need not be modified in the initialisation.
//in main file, in the function where file is created void FILE_Create() { ... fs_get_time(); <= did you want any side effect? because you aren't using return value fs_get_date(); <= "- file = fopen(filepath, "w"); ... }
You do not need to call fs_get_time or fs_get_date. RL-Flash does that. You just need to complete the functions to return the date and time you want. And yes, you must carry out the necessary initialisation of the RTC before these calls might be made.