ExtraFunky
Member
Hope someone can help me figure this out.
Teensy 4.0 + Audio Shield
Arduino IDE 2.3.2
Teensy Loader 1.59
Windows 10 IoT Enterprise (also tried on Windows 11 pro with same results)
TimeLib successfully syncs with RTC and displays correct time but timestamp on files and folders when writing to the SD card is one day behind.
I tested it with and without FsDateTime::setCallback(dateTime) callback with same results.
I know dateTime callback function is called because it prints the correct day().
I thought this used to work when I started my project back in December, but I could be wrong.
Here's my test code. It prints the correct date and time every 5 seconds. Manually creating a folder gets incorrect timestamp.
Teensy 4.0 + Audio Shield
Arduino IDE 2.3.2
Teensy Loader 1.59
Windows 10 IoT Enterprise (also tried on Windows 11 pro with same results)
TimeLib successfully syncs with RTC and displays correct time but timestamp on files and folders when writing to the SD card is one day behind.
I tested it with and without FsDateTime::setCallback(dateTime) callback with same results.
I know dateTime callback function is called because it prints the correct day().
I thought this used to work when I started my project back in December, but I could be wrong.
Here's my test code. It prints the correct date and time every 5 seconds. Manually creating a folder gets incorrect timestamp.
C++:
#include <SD.h>
#include <TimeLib.h>
#include <MTP_Teensy.h>
#define SDCARD_CS_PIN 10
uint32_t delayStart = millis();
void setup() {
Serial.begin(9600);
while (!Serial && millis() < 5000) {
// wait for serial port to connect.
}
// Initialize SD card
if (!SD.begin(SDCARD_CS_PIN))
Serial.println("SD card: Failed");
else
Serial.println("SD card: OK");
// Begin MTP session
MTP.begin();
// Add SD Card
MTP.addFilesystem(SD, "Media");
// Synchronise the Time object used in the program code with the RTC time provider.
// See https://github.com/PaulStoffregen/Time
setSyncProvider(getTeensy3Time);
if (timeStatus() != timeSet)
Serial.println(F("Unable to sync with RTC"));
else
Serial.println(F("RTC has set system time"));
// Define a callback that will assign the correct datetime for any file system operations
FsDateTime::setCallback(dateTime);
}
void loop() {
MTP.loop();
if ((millis() - delayStart) > 5000) {
printDateTime();
delayStart = millis();
}
}
// Retrieve the current time from Teensy built-in RTC
time_t getTeensy3Time() {
return Teensy3Clock.get();
}
// Callback to assign timestamps for file system operations
void dateTime(uint16_t* date, uint16_t* time, uint8_t* ms10) {
Serial.print("Day: ");
printDigits(day());
Serial.println();
// Return date using FS_DATE macro to format fields.
*date = FS_DATE(year(), month(), day());
// Return time using FS_TIME macro to format fields.
*time = FS_TIME(hour(), minute(), second());
// Return low time bits in units of 10 ms.
*ms10 = second() & 1 ? 100 : 0;
}
void printDateTime() {
printDigits(month());
Serial.print("/");
printDigits(day());
Serial.print("/");
Serial.print(year());
Serial.print(" ");
printDigits(hour());
Serial.print(":");
printDigits(minute());
Serial.print(":");
printDigits(second());
Serial.println();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}