I2C -- DS1307 Real Time Clock

Here we have two exercises employing the same circuit, showing the use of the DS1307 real time clock chip. This integrated circuit contains both a clock and also some user RAM, so the first demo puts the clock through its paces, while the second illustrates how to read and write with the memory. In both instances, communication is via I2C. The two source code folders are zipped together for your convenience in the download, below.

Here's the circuit:

The most convenient way to approach these two projects is by way of a breakout board which you can find on Amazon for about $6. Even better is that the module includes an I2C 4K EEPROM chip as well. Refer to the previous exercise to learn about those memory chips. The entire rig is denoted TinyRTC, and also sports a rechargeable battery backup. Here's what the breakout board looks like:

Note that the usual pull-up resistors required in I2C communication are incorporated on the board.

The first exercise, illustrated in the photo at the top of his page, creates a simple clock and calendar. Two pushbuttons let you set the date and time, as well as view the latter in either 12- or 24-hour mode. Operating instructions are in the source code, so look that over. While doing so, be sure to notice how I've included two Pascal library units with this project, one to handle the I2C and the other to provide sixteen high level commands for the TinyRTC module.

As mentioned, the second exercise is for demonstrating how to read from and write to the RAM residing with the DS1307 (56 bytes total). Here's what that experiment looks like:

Again, you'll find full instructions in the source code.

If you'd like even more information on the TinyRTC module, be sure to see my article, "Add a Real Time Clock to Your PIC Projects," Nuts & Volts Magazine, April 2015, pp. 48-51. Here's an online link to it:

You'll note that I wrote up the project there using the Great Cow Basic compiler, which I switched from to PIC Micro Pascal shortly thereafter.

Also for your notes, you might find the DS1307 data sheet useful:

Finally, to round out your study, I found the following document, "The I2C-bus and how to use it (including specifications)" from Philips Semiconductors extremely informative when creating the I2C library unit:

Click to get the source code.
Click to get the schematic PDF.

Next Project: 1-Wire -- Powered, Single-Drop

No comments:

Post a Comment