RegForge

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

AddrRegisterAccessWidthResetDescription
0x00SECONDSRW8—Seconds in BCD, plus the clock halt bit
0x01MINUTESRW8—Minutes in BCD, 00-59
0x02HOURSRW8—Hours in BCD. Layout depends on the 12/24 bit.
0x03DAYRW8—Day of week, 1-7, defined by the user
0x04DATERW8—Day of month in BCD, 01-31
0x05MONTHRW8—Month in BCD, 01-12
0x06YEARRW8—Year within the century in BCD, 00-99
0x07CONTROLRW80x03Square-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]
BitsFieldAccessMaskResetDescription
[7]CHRW0x80—Clock halt. 1 stops the oscillator. Set on a new part, so clear it before the clock will run.
[6:4]SECONDS_10RW0x70—Tens of seconds, 0-5
[3:0]SECONDS_1RW0x0F—Units of seconds, 0-9
MINUTES  @  0x01  —  2 fields
—7
MINUTES_10[6:4]
MINUTES_1[3:0]
BitsFieldAccessMaskResetDescription
[6:4]MINUTES_10RW0x70—Tens of minutes, 0-5
[3:0]MINUTES_1RW0x0F—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]
BitsFieldAccessMaskResetDescription
[6]MODE_12_24RW0x40—0 = 24-hour mode, 1 = 12-hour mode
[5]AM_PM_HOUR_20RW0x20—In 12-hour mode: 0 = AM, 1 = PM. In 24-hour mode: the 20-hour bit.
[4]HOURS_10RW0x10—The 10-hour bit
[3:0]HOURS_1RW0x0F—Units of hours, 0-9

HOURS.MODE_12_24 values

ValueNameMeaning
0x00MODE_24H24-hour format
0x01MODE_12H12-hour format, bit 5 is AM/PM
DAY  @  0x03  —  1 fields
—7
—6
—5
—4
—3
DAY[2:0]
BitsFieldAccessMaskResetDescription
[2:0]DAYRW0x07—Day of week, 1-7
DATE  @  0x04  —  2 fields
—7
—6
DATE_10[5:4]
DATE_1[3:0]
BitsFieldAccessMaskResetDescription
[5:4]DATE_10RW0x30—Tens of the date, 0-3
[3:0]DATE_1RW0x0F—Units of the date, 0-9
MONTH  @  0x05  —  2 fields
—7
—6
—5
MONTH_10[4]
MONTH_1[3:0]
BitsFieldAccessMaskResetDescription
[4]MONTH_10RW0x10—Tens of the month
[3:0]MONTH_1RW0x0F—Units of the month, 0-9
YEAR  @  0x06  —  2 fields
YEAR_10[7:4]
YEAR_1[3:0]
BitsFieldAccessMaskResetDescription
[7:4]YEAR_10RW0xF0—Tens of the year
[3:0]YEAR_1RW0x0F—Units of the year
CONTROL  @  0x07  —  3 fields
OUT[7]
—6
—5
SQWE[4]
—3
—2
RS[1:0]
BitsFieldAccessMaskResetDescription
[7]OUTRW0x800x00Output level on SQW/OUT when SQWE is 0
[4]SQWERW0x100x00Square-wave enable
[1:0]RSRW0x030x03Square-wave rate select

CONTROL.RS values

ValueNameMeaning
0x00HZ_11 Hz
0x01KHZ_4_0964.096 kHz
0x02KHZ_8_1928.192 kHz
0x03KHZ_32_76832.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

ADXL345
Analog Devices
30 registers
DS3231
Analog Devices
19 registers
BME280
Bosch Sensortec
14 registers

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