Using a Teensy Micromod with SDIO interface to log data.
Each time the data log option is enabled, a new file is created.
I am able to write the timestamp into the file itself (a CSV) but I am having a hard time setting the timestamp on the create field of the file.
Time is captured over CAN and fed into the Time library.
I've tried the following approaches but with no success:
#1
Before initialising mtp and the SD card, I set the time in the file system.
If I do this after I set up mtp/SD I get a weird timestamp when testing on the bench with USB plugged into the computer and no CAN network (so time will default to Jan 1st 1970, but it prints the current day/month with the year at 2030)
#2
When the file is created, I call the following code:
But this doesn't work at all and I get a timestamp when the card was produced (sometime in 2019)
Can anyone suggest another method that is known to work with SD.h and MTP?
Each time the data log option is enabled, a new file is created.
I am able to write the timestamp into the file itself (a CSV) but I am having a hard time setting the timestamp on the create field of the file.
Time is captured over CAN and fed into the Time library.
I've tried the following approaches but with no success:
#1
Before initialising mtp and the SD card, I set the time in the file system.
If I do this after I set up mtp/SD I get a weird timestamp when testing on the bench with USB plugged into the computer and no CAN network (so time will default to Jan 1st 1970, but it prints the current day/month with the year at 2030)
Code:
FLASHMEM void FSdateTime(uint16_t* date, uint16_t* time) {
// return date using FS_DATE macro to format fields
*date = FS_DATE(year(), (uint8_t)month(), (uint8_t)day());
// return time using FS_TIME macro to format fields
*time = FS_TIME((uint8_t)hour(), (uint8_t)minute(), (uint8_t)second());
}
FLASHMEM void sdBegin(){
FsDateTime::setCallback(FSdateTime);
MTP.begin();
// Add SD Card
if (SD.begin(BUILTIN_SDCARD)) {
MTP.addFilesystem(SD, "SD Card");
}
else {
}
}
#2
When the file is created, I call the following code:
Code:
DateTimeFields ts;
ts.hour = hour();
ts.min = minute();
ts.sec = second();
ts.year = year()-1900;
ts.mon = month();
ts.mday = day();
csvFile.setCreateTime(ts);
But this doesn't work at all and I get a timestamp when the card was produced (sometime in 2019)
Can anyone suggest another method that is known to work with SD.h and MTP?