网上有蛮多关于ds3231模块用法的介绍,但是我在树莓派4B上测试的时候,基本上都用不了。折腾了四五个小时,下面分享下自己探索出来的方法。
主要功能:将DS3231设置成为树莓派的系统时钟,树莓派不联网的情况下,可以自动从DS3231获取系统时间。
1. 驱动下载及安装
下载DS3231模块的驱动
git clone https://github.com/Seeed-Studio/pi-hats.git
cd pi-hats/CAN-HAT
安装驱动
sudo ./install.sh -u rtc_ds3231
重启电脑
sudo shutdown -h now
2. 设置时间
将时间设置为 2020年 10月1日 20点35分
date 100120352020.00 备注:10月1日 20点35分 2020年
3. 时间测试
date
4. 其他功能
读取硬件时钟并打印结果
sudo hwclock -r
通过硬件时钟设置系统时间
sudo hwclock -s
从当前系统时间设置硬件时钟
sudo hwclock -w
访问帮助以获得更多用途
hwclock --help
参考
-
https://www.seeedstudio.com/blog/2020/07/07/raspberry-pi-rtc-tutorial-using-ds1307-and-ds3231-rtcs-with-raspberry-pi-m/
-
https://shumeipai.nxez.com/2019/05/08/raspberry-pi-configuration-of-ds3231-clock-module-i2c-interface.html