一朝风月 万古长空

0%

OpenWrt 添加 RTC

TP-Link703(ar71xx)增加实时时钟(RTC ds1307)

RTC通讯GPIO

选取openwrt pcb板上相应空闲GPIO端口,作为与I2C芯片通讯端口。
通过GPIO模拟I2C总线时序来实现与扩展I2C芯片通讯。
若无法确定当前GPIO端口,参考openwrt GPIO官方wiki确定连接的GPIO。

内核开启RTC支持

编辑target/linux/ar71xx/Makefile,添加

1
2
-FEATURES:=squashfs jffs2 targz 
+FEATURES:=squashfs jffs2 targz rtc

vi target/linux/ar71xx/config-3.3

1
2
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_DS1307=y

vi .config

1
2
3
CONFIG_RTC_SUPPORT=y
CONFIG_DEFAULT_RTC_SUPPORT=y
CONFIG_PACKAGE_kmod-rtc-ds1307=y

删除openwr编译工程目录下的tmp文件夹
之后执行make,编译完成后,需要手动加载rtc驱动

挂载相关驱动

参考WRTnode添加i2c支持,添加I2C驱动。

i2ctools package也需要安装,可通过i2ctool来检测器件是否正常挂载
SDA = 20,SCL = 19。根据自己实际连接状况进行替换。

1
2
root@openwrt:~# insmod i2c-gpio-custom bus0=0,20,19
echo ds1307 0x68 > '/sys/class/i2c-dev/i2c-0/device/new_device'

若无错误提示,通过i2ctool工具检测ds1307是否挂载成功

1
2
3
4
5
6
7
8
9
10
root@openwrt:~# i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

如上所示,ds1307挂载成功。

通过以下指令设置同步rtc时钟

openwrt系统时间->rtc时钟芯片

hwclock -w

rtc时间->openwrt系统时间

hwclock -s

参考连接中,给出了自动挂载内核模块和时钟同步脚本,稍加修改即可完成上电同步

相关参考链接

Using an i2c RTC with the Carambola2

opewrt wiki I2C

openwrt wiki oldI2C

openwrt forum

openwrt forum

I2C tools使用

Adding an I2C interface to the TL-WR703N

WRTnode添加i2c支持

需要大家支持⬇️⬇️玩摩托,惭愧,惭愧.