This DS1307 you see here is a wonderful little chip. For those who don't know what it does, it is a Real Time Clock and Calendar. It is very accurate,it is low cost,it works with any uC having I2C. It can even remember the time in case of a power cut (if you have a 3 V battery connected to it) But often we have the problem of setting up the current time. This can be done in quite a few ways, i> One, is that you can hook up the uC to the computer with a USART Communications,then you can manually dial in the time from the keyboard then the microcontroller can write it to the internal register of the DS1307. But this has many hassels,for this to work you have to physically write the code for USART,then go through all the trouble of writing it to the DS1307 chip,then you have no way of being sure that if the time is configured properly.Also you have to get a TTL - USB Converter or use a MAX232 chip to handle the communications. There is no point in going through all this trouble because you have to do it only once.(There is no point in writting the date and time every time you switch it on. So the second method I am going to show you is a much easier way of doing it. ii>The second method is a much easier way. This method uses the arduino to handle the communications while utilizing its user friendly UI to get visual conformation. We will be using the following additional libraries i> Time.h (Library by Michael Margolis) ii> DS1307RTC.h Setup Software Setup 1.Connect the arduino to the computer. 2.Open up the arduino IDE. 3.Install the the two libraries in the IDE. 4.Open the example named "SetTime" under RTC in the examples tab. Hardware Setup 5.Now connect the SCL Pin of the Arduino to Pin 6 of DS1307. 6.Also connect the SDA Pin of the Arduino to Pin 5 of the DS1307. 7.Then connect a 32.768 kHz crystal to pin X1 and X2. 8.Now supply power to the chip.(Battery is optional) . After the setup is complete then burn the sketch (SetTime). Then if every thing goes right you should be able to use be able to program the chip. And when you open the serial monitor you should be able to get a visual conformation. Then burn the sketch ( ReadTest ).Once you do that you should be able to see the date and time on the serial monitor. Now you have successfully configured the DS1307 chip and it is ready to use. #Note If the power is by any chance cut off from the chip then the clock will reset and you have to do it all over again And you can also use these libraries to write code for your next project.They are actually pretty neat, So feel free to embed the DS1307 in your next project (either arduino or AVR). This work by Saptarshi Ghosh is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Based on a work at http://www.pjrc.com/teensy/td_libs_DS1307RTC.html. |