A new board accepts 14:26:05 and displays it correctly. A few seconds later it still says 14:26:05. One technician is ready to replace the 32.768 kHz crystal beside the DS1307. Another suspects the backup battery. Save an I²C trace before either part comes off the board. A successful date write shows that at least one bus transaction reached the device. The display shows what the software decoded. Establish separately whether the oscillator was enabled, whether the clock is counting and whether it keeps time through a power interruption.
Read the whole seconds byte before the display masks it
With the main supply in range, read register 0x00 and keep all eight bits. Bit 7 is the DS1307 clock-halt bit, CH. A one stops the oscillator, and a zero enables it. The datasheet states that CH is set on first application of power. The other bits hold binary-coded decimal, or BCD, seconds. Save the high bit for diagnostics, then mask it off with 0x7F and decode the remaining tens and ones digits for display. ADI DS1307 clock registers and CH bit
| Raw seconds byte | Displayed seconds | What the byte establishes |
|---|---|---|
0x85 | 05 | Bit 7 is one. The oscillator is disabled. |
0x05 | 05 | Bit 7 is zero. The oscillator is enabled. A later reading will show whether seconds are advancing. |
0xD9 | 59 | Masking bit 7 leaves the valid BCD value 0x59. CH still shows a halted oscillator. |
0x1A | Invalid seconds | A in the ones position falls outside the BCD digit range. Save the byte and trace what was written. |
A driver that returns zero on a failed read can leave the screen stuck on the minute. Check the address, acknowledgment and data actually returned before trusting the formatted result. Also look for code that writes decimal integers directly. The integer 42 is byte 0x2A in hexadecimal, while the DS1307 expects 0x42 for 42 seconds. An acknowledgment tells you that a byte arrived. The firmware still has to check that its digits and range are valid. Log failed reads, invalid BCD, a set CH bit and valid time separately so that the repair technician can tell which case occurred.
Build the complete time in memory before writing seconds
Suppose the factory uses Sunday as day 1 and wants to set a new board to Wednesday, November 25, 2026 at 14:26:05 in 24-hour mode. The seven hexadecimal data bytes for 0x00 through 0x06 are 05 26 14 04 25 11 26. The high bit of seconds is clear, as is the hour mode bit. The 04 for weekday follows the factory convention. DS1307 weekday values are assigned by the application and advance in sequence. Validate the date before writing, and encode the hour again whenever switching to a different hour mode. The operator can take as long as needed to enter the complete timestamp before the bus write begins.
When the DS1307 acknowledges a write to the seconds data byte, it resets the divider chain. The datasheet calls for the remaining clock and calendar bytes to be written within one second to avoid rollover problems. Commit the prepared seven bytes in one sequential write from 0x00. Splitting the update across two calls with a user prompt or a long scheduling delay in between can let the clock advance before the rest of the timestamp arrives. If a write fails partway through, log the bytes that went out, check state and submit a complete valid timestamp again. A readback of all seven registers checks that the calendar and time belong to the same setting. ADI seconds write, divider reset and timing requirement
Choose the time source for the factory operation. A test PC, an external reference and a firmware build date can all produce plausible values, but they represent different moments. Record the source and the actual time written. Compare future readings in the same time basis. Use an independent timer for the elapsed-time check, especially if the host can use the RTC for wake timing. Allow for oscillator startup and whole-second readout when you set a pass band for a three-second wait.
Make the next two transactions genuinely read-only
Pause all time-setting tasks. Read 0x00 through 0x06, wait about three seconds on the independent clock, and read them again. The DS1307 synchronizes its read buffer to the clock registers on an I²C START, so sequential bytes come from one snapshot. A combined transaction typically sends the seven-bit device address 0x68 with the write direction, then sends pointer 0x00. A repeated START changes to the read direction. The host reads seven data bytes, sends a NACK after the last byte and ends the transaction. The write-direction portion contains the register pointer. It has yet to send any data to change the seconds register. ADI Figure 6, set the pointer and then read
For a rollover example, consider 12:34:58 followed about three seconds later by 12:35:01. The seconds byte changes from 0x58 to 0x01 and the minutes change from 0x34 to 0x35. Subtract the seconds fields alone and the answer appears to be minus 57 seconds. If separate transactions read minute 34 before rollover and second 01 afterward, the software can assemble 12:34:01 from two snapshots. Decode the complete group and compare full timestamps. At midnight, include the date so a valid rollover does not register as a lost day.
A more subtle bug can occur when every display refresh reads seconds, clears CH and writes the byte back. Even writing the same value resets the divider. At a nominal 32,768 Hz, a write every 0.5 seconds lets approximately 16,384 crystal cycles accumulate before the next reset. A full second may never accrue despite an enabled oscillator. Capture a long enough window to see how often those writes occur. Two analyzers may label the same transfer differently. One displays address 0x68 with a direction, while another shows address bytes 0xD0 and 0xD1. Look for an extra data byte after the pointer in the write direction to distinguish a seconds write from a read setup.
Use the 1 Hz output as a second observation
If the board brings out SQW/OUT, save the original value of control register 0x07. On a dedicated bench unit, write 0x10 to set SQWE=1 and RS1=RS0=0, selecting 1 Hz. The pin is open drain and needs a pull-up that suits the RTC and the receiving input. Connect the scope or analyzer to the output. The datasheet says the clock registers update on the falling edge in this mode. Record the waveform and the bus transactions on a common external timebase. Restore the original control setting afterward if that pin serves a different purpose in the product. ADI square-wave control and the 1 Hz update edge
Investigate the crystal circuit if CH stays clear, the bus shows no further seconds writes, the time still does not advance, and there is no square wave despite proper configuration and pull-up. Check whether the correct crystal is fitted and whether its terminals go directly to X1 and X2. Look at the solder joints, contamination and nearby switching traces. A general-purpose oscilloscope probe can add enough capacitance at the crystal pins to stop this low-power oscillator. Start with the calendar and buffered observation at SQW/OUT. If the scope shows a steady square wave while software reports frozen seconds, check the register address, caching and actual I²C bytes again. ADI crystal circuit and indirect oscillation checks
Compare the exact crystal datasheet with Table 1 of the DS1307 datasheet. The recommended circuit uses an external 32.768 kHz crystal rated for 12.5 pF load capacitance and a maximum ESR of 45 kΩ, with no external resistor or capacitor required at the crystal. A quote for 32.768 kHz at 12.5 pF and a 70 kΩ maximum misses that ESR criterion. Another crystal specified at 35 kΩ maximum and 6 pF still needs a load review. The frequency marking and case size can help screen incoming parts. Capacitance, ESR and connections need documentation tied to the exact order code. On a matching candidate, verify startup and timekeeping across the required temperatures on the intended board. The datasheet says a matching circuit usually starts within one second. Use the project’s operating conditions and repeated startup tests to establish its acceptance limit. ADI crystal table and recommended oscillator circuit
Check backup timekeeping after main power returns
The DS1307 may block I²C access during a power interruption while still keeping time from the battery. Its recommended main supply is 4.5 to 5.5 V. Take a battery measurement of 3.00 V at VBAT. The nominal power-fail threshold is 1.25 times that voltage, or about 3.75 V. Multiplying by the minimum and maximum factors in the electrical table at that battery voltage gives approximately 3.65 to 3.85 V. A 3.3 V main rail would be below the recommended range and below the access threshold in that example, even with valid bus pull-ups. Measure both supply pins if acknowledgment is missing, especially during a slow ramp or when the measurement was originally taken upstream of a connector. An I²C failure during backup is not by itself evidence for a stopped oscillator. ADI supply range and power-fail threshold · ADI main-power and backup access behavior
On a unit cleared for resetting, set 23:59:30 and first verify that the clock advances. Record when you remove main power, leave the battery in circuit, and restore VCC after about two minutes. Before any startup code writes the build date or synchronizes the clock, read the full calendar and time. At about 120 seconds from the reference time, expect around 00:01:30 on the next day. Judge the actual result using the times of the before and after reads and the supply transition. If the timestamp stays fixed, check the backup voltage at the pin, the contacts and CH. If the date jumps to the firmware build date, look at the startup bus trace. Repeat for a short interruption and the interruption length required by the product, saving the first read after each recovery.
Compare boards that show the same frozen display
Suppose two boards from one build always show 05 seconds. Read both from the same fixture and record their firmware, serial numbers and startup conditions. Board A returns 0x85 every time, pointing to first-use initialization. Board B returns 0x05, but the trace shows an actual seconds write every 0.5 seconds. Pausing the display refresh brings back normal timekeeping on B. The customer sees the same screen on both boards, though the fixes belong in different code paths. Save the existing timestamp before adjusting either board.
If several tasks can reach the RTC, route time setting through one owner so it can commit a full set of registers before another task reads it. Give the display a read-only path. If a write needs to be retried, retrieve a fresh reference timestamp first. When looking at a shared I²C trace, label the requesting task and the number of data bytes after the pointer. A count of acknowledgments at 0x68 alone will miss the difference.
For a board that still fails, run a known-good board with the same supply ramp, probe connection and elapsed time after startup. If the failure appears only when a particular test lead is attached, verify that connection before removing the crystal. Once the conditions are repeatable, change one suspect part at a time and record the waveform and part markings before and after. If the fault follows a specific crystal, you have grounds to compare its exact specifications or submit it for component analysis.
Keep records that purchasing and repair can both use
Give new production boards and repaired boards different time-setting procedures. For a new unit, initialize it once from the chosen reference. Save the original CH bit and two coherent timestamps after the write. For a repaired unit with a valid backup supply, start in read-only diagnostics and preserve its time and control state until a correction is authorized by the repair procedure. List the exact RTC and crystal order codes, board revision, crystal load and ESR, and the main and backup voltages. Attach the raw bus bytes, actual writes, timestamps and test setup. Purchasing can check the quoted part against the specification, while engineering has enough evidence to tell whether to work on initialization, the power path, the PCB or the crystal. ADI hardware and software design considerations for RTCs
