I am currently working on an electronics project of building my own Digital wall clock. For that I tried making a RTC module with DS1307 IC.
I followed the following instruction from this website.
But when I tried to read and write the time to the IC using the serial monitor on Arduino software I got the following result.
Serial Monitor Output
My inputs were as follows:
first i/p : T000021240114
second i/p: R
And this is the connections I have made
Can someone help me find my mistake.
1 Answer 1
From the code:
second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48));
minute = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
hour = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
dayOfWeek = (byte) (Serial.read() - 48);
dayOfMonth = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
month = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
year= (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
All have two characters except for dayOfWeek
So for right now (2014年01月25日 13:58:00) it would be 14 characters (including 'T')
T0058136250114
You only have 13 characters in your command.
Also you need 4K7 - 10K pullups on SDA and SCL. Note that "Command: 13" in the log is just the carriage return character (enter). Since you had too few characters in the command, it was interpreted as part of the command.
-
\$\begingroup\$ can you explain more about the resistors. there is none specified in the schematics. also i changed the command, but still getting garbage values. The new log can you look into it again. thanks. \$\endgroup\$BharathYes– BharathYes2014年01月25日 08:04:32 +00:00Commented Jan 25, 2014 at 8:04
-
\$\begingroup\$ @BharathYes The pullup resistors are required for I2C. The page you have linked used an RTC board that already has these two resistors included. You have used a bare chip so you need to add the resistors. \$\endgroup\$alexan_e– alexan_e2014年01月25日 09:21:38 +00:00Commented Jan 25, 2014 at 9:21
-
\$\begingroup\$ thanks for the help. turns out the battery wasn't connected properly. but i have a new bug. the time doesn't change for some time. the seconds is updated by one only once every two minutes. do you think there might be something wrong with the crystal ???? \$\endgroup\$BharathYes– BharathYes2014年01月25日 12:33:34 +00:00Commented Jan 25, 2014 at 12:33
-
\$\begingroup\$ @BharathYes What crystal are you using? The data sheet says there is an app note: "Application Note 58: Crystal Considerations with Dallas Real-Time Clocks.". Does it increment regularly every 2 mins or randomly? \$\endgroup\$geometrikal– geometrikal2014年01月25日 13:29:14 +00:00Commented Jan 25, 2014 at 13:29
-
\$\begingroup\$ i bought the crystal at a local electrical store. I asked for a 32.768 kHz crystal, but nothing on it says so. it only has a name "KOSOL" and am assuming it is the manufacturer's name. Also the time seems to increment a little randomly. can you find anything wrong ? \$\endgroup\$BharathYes– BharathYes2014年01月25日 13:43:33 +00:00Commented Jan 25, 2014 at 13:43