Example 17: DS1302 RTC clock
About 2 min
Example 17: DS1302 RTC clock
Synchronized Device Documentation
This page corresponds to the synchronized Chinese source. Commands, JSON examples, API paths, field names, and screenshots are kept aligned with the Chinese device-side source documentation.
What This Page Covers
- Hardware purpose, wiring requirements, and firmware edition notes.
- Peripheral configuration fields and JSON examples.
- Validation steps, PeriphExec linkage, and field-operation notes.
Source Reference
The detailed operational source is preserved below so implementation details stay exact while the English navigation, titles, and reading path remain available.
示例17:DS1302 RTC时钟
实验概述
DS1302 是一款低功耗实时时钟芯片,通过纽扣电池可在断电后持续计时。FastBee 当前未内置 DS1302 专用外设类型,但可通过 GPIO 配置和脚本扩展实现时间读取。
硬件接线
| 开发板标识 | GPIO引脚 | 连接设备 |
|---|---|---|
| CLK | GPIO14 | DS1302 时钟线 |
| DAT | GPIO27 | DS1302 数据线 |
| RST | GPIO26 | DS1302 复位/使能 |
DS1302 使用三线 SPI 协议通信,需要 3 个 GPIO 引脚。
JSON 配置示例
{
"peripherals": [
{
"id": "rtc_clk",
"name": "DS1302-CLK",
"type": 12,
"enabled": false,
"pins": [14],
"params": { "initialState": 0 }
},
{
"id": "rtc_dat",
"name": "DS1302-DAT",
"type": 12,
"enabled": false,
"pins": [27],
"params": { "initialState": 0 }
},
{
"id": "rtc_rst",
"name": "DS1302-RST",
"type": 12,
"enabled": false,
"pins": [26],
"params": { "initialState": 0 }
}
]
}外设执行联动(方案A:NTP方案)
场景:定时显示时间(定时触发)
功能:每秒更新数码管显示NTP同步的系统时间
Web界面配置步骤
步骤1:确保已配置TM1637数码管
- 外设ID:
tm1637_01 - 类型:数码管显示
步骤2:创建规则
- 点击左侧菜单 外设配置 → 切换到 外设执行管理 标签
- 点击 新增规则 按钮
- 填写基础配置:
- 规则名称:
定时显示时间 - 上报数据:✅ 启用
- 启用:✅ 启用
- 规则名称:
步骤3:配置触发器
点击 添加触发 按钮
填写触发器配置:
字段 填写内容 说明 触发类型 选择 定时触发 定时更新 定时模式 选择 固定间隔 按毫秒间隔 间隔时间 10001秒
步骤4:配置动作
点击 添加动作 按钮
填写:
- 动作类型:选择 显示时间
- 目标外设:选择
tm1637_01
点击 保存 按钮
方案对比
| 方案 | 优点 | 缺点 | 适用场景 |
|---|---|---|---|
| NTP | 精度高、无需硬件 | 需要联网 | 联网设备 |
| DS1302 | 断电保持、离线可用 | 需额外硬件、精度低 | 离线设备 |
注意事项
- 电池:DS1302 需 CR2032 纽扣电池维持断电计时
- NTP 优先:联网环境建议使用 NTP,DS1302 适合离线场景
- 驱动支持:FastBee 当前版本未内置 DS1302 驱动,需自定义扩展
- 精度:DS1302 精度约 ±2ppm(每月误差约5秒)
- 通信协议:DS1302 使用 3 线 SPI(非标准 SPI),时序需软件模拟
