I'm using a DS1302 with an Arduino Mega 2560. Connected to both I have a 5V power supply from 220V AC (image of diagram attached).
I tried running the code from the example in the library, but without the delay:
#include <DS1302.h>
// Init the DS1302
DS1302 rtc(53, 51, 49);
void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);
// Setup Serial connection
Serial.begin(9600);
// The following lines can be commented out to use the values already stored in the DS1302
//rtc.setDOW(FRIDAY); // Set Day-of-Week to FRIDAY
//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(6, 8, 2010); // Set the date to August 6th, 2010
}
void loop()
{
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
// delay(1000);
// Wait one second before repeating :)
}
I can confirm that pins are all set correctly because the clock works perfectly.
I'm running the sketch plugged to my pc, the problem is, sometimes when I plug the power supply to 220V the rtc resets to 01/01/2000 00:00:00, and keeps working perfectly from there. Im plugging it in after running the sketch because I discovered this issue with a project of mine, where I would get this reset whenever I connect or disconnect a relay close (not connected) to the arduino, so I'm assuming it might be a problem with peaks of voltage caused by any interference or such, don't really know.
Thanks for any help!
