Putting a DS1307 Clock on Your PCB: Crystal, Backup Supply and Firmware Checks
A real-time clock module is convenient during prototyping. Moving the same function onto your own PCB gives you control over size and connectors, but it also makes you responsible for details the module previously supplied: the crystal, battery arrangement, pull-ups and layout.
The surface-mount real-time clock IC collection includes the DS1307 in an eight-pin surface-mount package. This guide focuses on designing with the bare IC. It is a board-design checklist, rather than a claim that every RTC module or similarly named clock uses the same circuit.
Separate the timekeeping function from the board design
Analog Devices describes the DS1307 as an I2C clock/calendar with battery-backed memory and automatic backup-supply switching. It stores calendar fields in binary-coded decimal, or BCD. It does not know your local time zone, daylight-saving rules or whether a stored date is trustworthy for your application.
Decide those policies before writing the interface. A project may store UTC internally and convert for display, or store local time with clearly documented limitations. Either way, include a visible “time not set” state instead of displaying a plausible default date as if it were valid.
Choose a matching crystal, not just a matching frequency
The DS1307 data sheet specifies a 32.768 kHz crystal with 12.5 pF load capacitance. Frequency alone is not enough: verify load capacitance, equivalent series resistance and the other relevant crystal requirements.
The load-capacitance rating is not an instruction to add a 12.5 pF capacitor to each crystal pin. The RTC oscillator includes internal loading. Copying the familiar pair of capacitors from an unrelated microcontroller oscillator can prevent correct operation.
Record the crystal’s complete part number in the bill of materials. “32 kHz crystal” is too vague for a repeatable assembly. Check the component drawing, handling requirements and soldering process as well as its electrical specification.
Give the oscillator a quiet corner of the PCB
Analog Devices’ crystal selection and layout application note explains why these low-power oscillator nodes are sensitive to stray capacitance, leakage and coupled noise. Place the crystal close to the RTC and keep its connections compact.
Follow the manufacturer’s local grounding and routing guidance. Keep switching nodes, fast digital signals and high-current return paths away from the crystal area. Do not use a convenient gap beneath the crystal traces to route another busy signal without considering the recommended shielding and keep-out arrangement.
Leave enough space for inspection and cleaning. Assembly residue can be electrically significant in a high-impedance circuit even when the board looks acceptable. Use a cleaning process compatible with all fitted components, and inspect the finished oscillator area before blaming firmware.
Design the two supplies as different functions
The DS1307’s normal supply range is 4.5–5.5 V. Its backup input serves timekeeping when the main supply is absent; it is not a substitute for a valid main supply during ordinary communications. Check the backup voltage requirements in the data sheet.
Use a suitable holder and a clearly marked battery polarity. Do not add a charging path to a non-rechargeable cell. The bare RTC’s backup arrangement and any charging circuitry on a commercial module are separate things, so copying a module by appearance is not a sound design method.
Make the battery accessible in the enclosure and decide how replacement affects the user. If changing it loses the time, provide a straightforward way to set the clock again. Label the approved cell type in the project documentation rather than relying on someone recognising the holder years later.
Check I2C levels across the complete system
The RTC supply and I2C pull-up voltage need not be assumed identical. Compare the DS1307 input thresholds, its open-drain output behaviour and the controller’s input limits before choosing the bus arrangement. A 5 V pull-up can be unsuitable for a controller whose pins are not 5 V tolerant.
Include existing pull-ups elsewhere on the bus in that calculation. Also consider what happens when the controller resets or loses power while the RTC remains supplied. Keep the bus schematic explicit: power rails, pull-ups and ground connections should all be visible.
Write a deliberate first-run routine
The clock-halt bit must be cleared to enable the DS1307 oscillator. Handle it separately from the seconds value, and decode BCD fields correctly. For example, BCD 0x25 represents decimal 25, not decimal 37.
Do not reset the calendar to the firmware build time on every boot. Instead, separate “read the existing clock” from an explicit “set the clock” operation. Validate incoming dates and store any application-specific validity information in a way that can be checked after power loss.
Analog Devices’ RTC control-code guidance is useful when handling register formats and rollover. Use the documented coherent-read behaviour rather than assembling a timestamp from unrelated reads that can straddle a calendar change.
Bring up the new PCB in layers
- Inspect the package orientation, solder joints, crystal connections and battery polarity with power disconnected.
- Measure the main supply at the RTC and check the bus idle levels.
- Confirm communications, then read raw registers before formatting them for display.
- Set a known valid time and verify that seconds advance.
- Reset only the controller and confirm the RTC continues without being overwritten.
- Remove the main supply for a measured interval, restore it and check elapsed time.
Do not interpret failed communications while running only from backup as proof that the oscillator stopped. Test backup timekeeping by reading the clock after the main supply returns. Avoid loading the crystal pins with an ordinary probe when diagnosing oscillation; use the manufacturer’s recommended method or a suitably configured clock output.
Review the design before ordering more boards
Test near a minute and date rollover, and run the complete project with its display, radio or switching supply active. A quiet test board may behave differently once neighbouring circuits are busy. Record the PCB revision, crystal part and firmware version with the results.
A successful RTC integration does more than show advancing seconds. It starts reliably, retains time through the intended power sequence and tells the user when the stored calendar needs attention.