2
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\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 Jan 25 '14 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 Jan 25 '14 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 Jan 25 '14 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 Jan 25 '14 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 Jan 25 '14 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.