All parts / DS1307
DS1307 register map
I2C real-time clock with 56 bytes of battery-backed NVRAM — Analog Devices
8 registers
I2C
I²C 0x68
8-bit reg addresses
75% bit coverage
not yet human-verified
I²C address conflict. On its default address(es) this part collides with
DS3231 (0x68);
MPU6050 (0x68);
PCA9685 (0x68). You cannot put them on the same bus without changing a strap pin, using an I²C multiplexer, or moving one to a second bus.
See the full address map.
Get it as a C header
pip install regforge
regforge gen DS1307 --out ./src --driver --tests
Writes ds1307_regs.h with every address, mask and shift below, a bus-agnostic driver skeleton, and a file of compile-time assertions that make your compiler check the bit arithmetic. No API key needed — this part ships inside the package.
Not yet human-verified. Transcribed and mechanically validated — no overlapping fields, no out-of-range bits, reset values consistent with their fields — but not yet checked line-by-line against the datasheet.
Verifying it is a useful half hour.
Registers
| Addr | Register | Access | Width | Reset | Description |
| 0x00 | SECONDS | RW | 8 | — | Seconds in BCD, plus the clock halt bit |
| 0x01 | MINUTES | RW | 8 | — | Minutes in BCD, 00-59 |
| 0x02 | HOURS | RW | 8 | — | Hours in BCD. Layout depends on the 12/24 bit. |
| 0x03 | DAY | RW | 8 | — | Day of week, 1-7, defined by the user |
| 0x04 | DATE | RW | 8 | — | Day of month in BCD, 01-31 |
| 0x05 | MONTH | RW | 8 | — | Month in BCD, 01-12 |
| 0x06 | YEAR | RW | 8 | — | Year within the century in BCD, 00-99 |
| 0x07 | CONTROL | RW | 8 | 0x03 | Square-wave output control |
Bit layouts
Drawn MSB-first, the way the datasheet draws them. [7:5] means shift 5, width 3, mask 0xE0 — this is the notation that costs people a day when they read it backwards.
SECONDS @ 0x00 — 3 fields
CH[7]
SECONDS_10[6:4]
SECONDS_1[3:0]
| Bits | Field | Access | Mask | Reset | Description |
| [7] | CH | RW | 0x80 | — | Clock halt. 1 stops the oscillator. Set on a new part, so clear it before the clock will run. |
| [6:4] | SECONDS_10 | RW | 0x70 | — | Tens of seconds, 0-5 |
| [3:0] | SECONDS_1 | RW | 0x0F | — | Units of seconds, 0-9 |
MINUTES @ 0x01 — 2 fields
—7
MINUTES_10[6:4]
MINUTES_1[3:0]
| Bits | Field | Access | Mask | Reset | Description |
| [6:4] | MINUTES_10 | RW | 0x70 | — | Tens of minutes, 0-5 |
| [3:0] | MINUTES_1 | RW | 0x0F | — | Units of minutes, 0-9 |
HOURS @ 0x02 — 4 fields
—7
MODE_12_24[6]
AM_PM_HOUR_20[5]
HOURS_10[4]
HOURS_1[3:0]
| Bits | Field | Access | Mask | Reset | Description |
| [6] | MODE_12_24 | RW | 0x40 | — | 0 = 24-hour mode, 1 = 12-hour mode |
| [5] | AM_PM_HOUR_20 | RW | 0x20 | — | In 12-hour mode: 0 = AM, 1 = PM. In 24-hour mode: the 20-hour bit. |
| [4] | HOURS_10 | RW | 0x10 | — | The 10-hour bit |
| [3:0] | HOURS_1 | RW | 0x0F | — | Units of hours, 0-9 |
HOURS.MODE_12_24 values
| Value | Name | Meaning |
| 0x00 | MODE_24H | 24-hour format |
| 0x01 | MODE_12H | 12-hour format, bit 5 is AM/PM |
DAY @ 0x03 — 1 fields
| Bits | Field | Access | Mask | Reset | Description |
| [2:0] | DAY | RW | 0x07 | — | Day of week, 1-7 |
DATE @ 0x04 — 2 fields
—7
—6
DATE_10[5:4]
DATE_1[3:0]
| Bits | Field | Access | Mask | Reset | Description |
| [5:4] | DATE_10 | RW | 0x30 | — | Tens of the date, 0-3 |
| [3:0] | DATE_1 | RW | 0x0F | — | Units of the date, 0-9 |
MONTH @ 0x05 — 2 fields
—7
—6
—5
MONTH_10[4]
MONTH_1[3:0]
| Bits | Field | Access | Mask | Reset | Description |
| [4] | MONTH_10 | RW | 0x10 | — | Tens of the month |
| [3:0] | MONTH_1 | RW | 0x0F | — | Units of the month, 0-9 |
YEAR @ 0x06 — 2 fields
| Bits | Field | Access | Mask | Reset | Description |
| [7:4] | YEAR_10 | RW | 0xF0 | — | Tens of the year |
| [3:0] | YEAR_1 | RW | 0x0F | — | Units of the year |
CONTROL @ 0x07 — 3 fields
OUT[7]
—6
—5
SQWE[4]
—3
—2
RS[1:0]
| Bits | Field | Access | Mask | Reset | Description |
| [7] | OUT | RW | 0x80 | 0x00 | Output level on SQW/OUT when SQWE is 0 |
| [4] | SQWE | RW | 0x10 | 0x00 | Square-wave enable |
| [1:0] | RS | RW | 0x03 | 0x03 | Square-wave rate select |
CONTROL.RS values
| Value | Name | Meaning |
| 0x00 | HZ_1 | 1 Hz |
| 0x01 | KHZ_4_096 | 4.096 kHz |
| 0x02 | KHZ_8_192 | 8.192 kHz |
| 0x03 | KHZ_32_768 | 32.768 kHz (default) |
Generated C header
What regforge gen DS1307 writes for HOURS:
/* ------------------------------------------------------------------------ */
/* HOURS @ 0x02u rw 8-bit */
/* Hours in BCD. Layout depends on the 12/24 bit. */
/* ------------------------------------------------------------------------ */
#define DS1307_HOURS 0x02u
#define DS1307_HOURS_WIDTH 8u
/* MODE_12_24 bits [6] rw -- 0 = 24-hour mode, 1 = 12-hour mode */
#define DS1307_HOURS_MODE_12_24_SHIFT 6u
#define DS1307_HOURS_MODE_12_24_WIDTH 1u
#define DS1307_HOURS_MODE_12_24_MASK 0x40u
#define DS1307_HOURS_MODE_12_24_GET(reg) (((uint8_t)(reg) & 0x40u) >> 6u)
#define DS1307_HOURS_MODE_12_24_SET(reg, val) (((uint8_t)(reg) & (uint8_t)~0x40u) | (((uint8_t)(val) << 6u) & 0x40u))
#define DS1307_HOURS_MODE_12_24_MODE_24H 0x00u /* 24-hour format */
#define DS1307_HOURS_MODE_12_24_MODE_12H 0x01u /* 12-hour format, bit 5 is AM/PM */
/* AM_PM_HOUR_20 bits [5] rw -- In 12-hour mode: 0 = AM, 1 = PM. In 24-hour mode: the 20-hour bit. */
#define DS1307_HOURS_AM_PM_HOUR_20_SHIFT 5u
#define DS1307_HOURS_AM_PM_HOUR_20_WIDTH 1u
#define DS1307_HOURS_AM_PM_HOUR_20_MASK 0x20u
#define DS1307_HOURS_AM_PM_HOUR_20_GET(reg) (((uint8_t)(reg) & 0x20u) >> 5u)
#define DS1307_HOURS_AM_PM_HOUR_20_SET(reg, val) (((uint8_t)(reg) & (uint8_t)~0x20u) | (((uint8_t)(val) << 5u) & 0x20u))
/* HOURS_10 bits [4] rw -- The 10-hour bit */
#define DS1307_HOURS_HOURS_10_SHIFT 4u
#define DS1307_HOURS_HOURS_10_WIDTH 1u
#define DS1307_HOURS_HOURS_10_MASK 0x10u
#define DS1307_HOURS_HOURS_10_GET(reg) (((uint8_t)(reg) & 0x10u) >> 4u)
#define DS1307_HOURS_HOURS_10_SET(reg, val) (((uint8_t)(reg) & (uint8_t)~0x10u) | (((uint8_t)(val) << 4u) & 0x10u))
/* HOURS_1 bits [3:0] rw -- Units of hours, 0-9 */
#define DS1307_HOURS_HOURS_1_SHIFT 0u
#define DS1307_HOURS_HOURS_1_WIDTH 4u
#define DS1307_HOURS_HOURS_1_MASK 0x0Fu
#define DS1307_HOURS_HOURS_1_GET(reg) (((uint8_t)(reg) & 0x0Fu) >> 0u)
#define DS1307_HOURS_HOURS_1_SET(reg, val) (((uint8_t)(reg) & (uint8_t)~0x0Fu) | (((uint8_t)(val) << 0u) & 0x0Fu))
/* ------------------------------------------------------------------------ */
/* DAY @ 0x03u rw 8-bit */
/* Day of week, 1-7, defined by the user */
/* ------------------------------------------------------------------------ */
#define DS1307_DAY 0x03u
Compared with
Related parts
Source
Transcribed from Maxim/ADI DS1307 datasheet (hand-transcribed) (hand-transcribed). Hand-authored seed entry, not machine-extracted. Timekeeping registers carry no reset value because the datasheet states none -- they hold whatever the backup battery preserved. The 56 bytes of NVRAM at 0x08-0x3F are plain memory rather than registers and are not modelled. Check against the datasheet before trusting it, then mark it verified.
Raw JSON · Report an error