Hi all
Ive been experimenting with this bit of code and using cattledog's first post, I modified it to work with the HCRTC library instead of RTCLib. Here is the code-
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
/* Include the Hobby Components RTC library */
#include <HCRTC.h>
/* The RTC has a fixed address of 0x68 /
#define I2CDS1307Add 0x68
/ DIO pin used to control the SD card CS pin /
//#define SD_CS_DIO 10
File file; // test file
const uint8_t SD_CS = 10; // SD chip select
/ Create an instance of HCRTC library */
HCRTC HCRTC;
char timestamp[30];
//------------------------------------------------------------------------------
// call back for file timestamps
void dateTime(uint16_t* date, uint16_t* time) {
HCRTC.RTCRead(I2CDS1307Add);
sprintf(timestamp, "%02d:%02d:%02d %2d/%2d/%2d \n", HCRTC.GetHour(),HCRTC.GetMinute(),HCRTC.GetSecond(),HCRTC.GetMonth(),HCRTC.GetDay(),HCRTC.GetYear());
Serial.println("yy");
Serial.println(timestamp);
// return date using FAT_DATE macro to format fields
*date = FAT_DATE((HCRTC.GetYear()-48), HCRTC.GetMonth(), HCRTC.GetDay());
// return time using FAT_TIME macro to format fields
*time = FAT_TIME(HCRTC.GetHour(), HCRTC.GetMinute(), HCRTC.GetSecond());
}
//------------------------------------------------------------------------------
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Wire.begin();
// set date time callback function
SdFile::dateTimeCallback(dateTime);
HCRTC.RTCRead(I2CDS1307Add);
sprintf(timestamp, "%02d:%02d:%02d %2d/%2d/%2d \n", HCRTC.GetHour(),HCRTC.GetMinute(),HCRTC.GetSecond(),HCRTC.GetMonth(),HCRTC.GetDay(),HCRTC.GetYear());
Serial.println("xx");
Serial.println(timestamp);
if (!SD.begin(SD_CS)) {
Serial.println("SD.begin failed");
while(1);
}
SD.remove("TEST_SD.TXT");
file = SD.open("TEST_SD.TXT", FILE_WRITE);
file.println("Testing 1,2,3...");
delay(5000);
file.close();
Serial.println("Done");
}
void loop() {
// put your main code here, to run repeatedly:
}
All worked fine except the year on the file stamp was 2068. I've no idea why and I fixed it by subtracting 48 from the Macro "*date = FAT_DATE((HCRTC.GetYear()-48), HCRTC.GetMonth(), HCRTC.GetDay());"
Anybody have a clue as to why this happens?