> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man4/ds3231.4.md).

# ds3231.4

`ds3231` — 极高精度 I2C 集成实时时钟（RTC）/TCXO/晶体

## 名称

`ds3231`

## 概要

`device iic device iicbus device ds3231`

## 描述

`ds3231` 是一种低成本、极高精度的 I2C 实时时钟（RTC），集成了温度补偿晶体振荡器（TCXO）和晶体。

该器件包含电池输入，当器件主电源中断时能维持精确计时。

通过 [sysctl(8)](/man/man8/sysctl.8.md) 接口访问 `ds3231` 数据：

```sh
dev.ds3231.0.%desc: Maxim DS3231 RTC
dev.ds3231.0.%driver: ds3231
dev.ds3231.0.%location: addr=0xd0
dev.ds3231.0.%pnpinfo: name=rtc compat=maxim,ds3231
dev.ds3231.0.%parent: iicbus1
dev.ds3231.0.temperature: 23.2C
dev.ds3231.0.temp_conv: 0
dev.ds3231.0.bbsqw: 0
dev.ds3231.0.sqw_freq: 8192
dev.ds3231.0.sqw_mode: interrupt
dev.ds3231.0.32khz_enable: 1
```

**`dev.ds3231.%d.temperature`** RTC 读取的当前温度的只读值。

**`dev.ds3231.%d.temp_conv`** 启动一次新的温度转换。读取为 1 时表示温度转换正在进行。读取为 0 然后设为 1 时，启动一次温度转换。温度转换在上电时自动运行，此后每 64 秒运行一次。

**`dev.ds3231.%d.bbsqw`** 若设为 1 且 `dev.ds3231.%d.sqw_mode` 设为 square-wave，则启用电池备份方波输出。若设为 0，当 RTC 由电池供电时，SQW 引脚将设为高阻态。

**`dev.ds3231.%d.sqw_freq`** 在 `dev.ds3231.%d.sqw_mode` 上启用方波输出时选择 SQW 引脚的频率。可设为 1、1024、4096 和 8192。

**`dev.ds3231.%d.sqw_mode`** 设置 SQW 引脚的工作模式。可设为'interrupt'（默认）或'square-wave'。在 interrupt 模式下，SQW 引脚用于为 RTC 闹钟生成中断。在 square-wave 模式下，SQW 引脚输出频率为 `dev.ds3231.%d.sqw_freq` 的方波。

**`dev.ds3231.%d.32khz_enable`** 启用 32kHz 输出。

更多详情请查阅 `ds3231` 数据手册。

在基于 [device.hints(5)](/man/man5/device.hints.5.md) 的系统（如 `MIPS`）上，这些值可为 `ds3231` 配置：

**`hint.ds3231.%d.at`** `ds3231` 所连接的 [iicbus(4)](/man/man4/iicbus.4.md)。

**`hint.ds3231.%d.addr`** `ds3231` 的 8 位 i2c 地址。`ds3231` 的默认 8 位地址为 0xd0。

在基于 FDT(4) 的系统上，必须设置以下属性：

**`compatible`** 必须始终设为"maxim,ds3231"。

**`reg`** `ds3231` 的 7 位 i2c 地址。`ds3231` 的默认 7 位地址为 0x68。

## 参见

[fdt(4)](/man/man4/fdt.4.md), [iic(4)](/man/man4/iic.4.md), [iicbus(4)](/man/man4/iicbus.4.md), [sysctl(8)](/man/man8/sysctl.8.md)

## 历史

`ds3231` 驱动首次出现于 FreeBSD 11.0。

## 作者

`ds3231` 驱动及本手册页由 Luiz Otavio O Souza <loos@FreeBSD.org> 编写。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man4/ds3231.4.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
