树莓派使用DS3231时钟芯片

FsTy 提交于 周三, 01/13/2016 - 23:04

1.编辑/boot/config.txt   在末尾加入

dtparam=i2c_arm=on
dtoverlay=i2c-rtc,ds3231

2.在/etc/modules文件中添加一行:

i2c-dev

3.sudo apt-get install i2c-tools
4.sudo i2cdetect -y 1

5.sudo dpkg --purge fake-hwclock

6.sudo ntpdate cn.pool.ntp.org

7.sudo hwclock -w //将系统时钟写入硬件时钟

8.sudo hwclock -s //时钟芯片写入系统时钟

9.sudo nano /lib/systemd/system/hwclock-start.service

[Unit]

Description=Set time from RTC on startup

After=network.target

 
[Service]

Type=oneshot

ExecStart=/sbin/hwclock -s

TimeoutSec=0

 
[Install]

WantedBy=multi-user.target

10.sudo nano /lib/systemd/system/hwclock-stop.service

[Unit]

Description=Synchronise Hardware Clock to System Clock

DefaultDependencies=no

Before=shutdown.target

 
[Service]

Type=oneshot

ExecStart=/sbin/hwclock --systohc

 
[Install]

WantedBy=reboot.target halt.target poweroff.target

11.sudo systemctl enable hwclock-start hwclock-stop

资料来源:http://www.geek-workshop.com/thread-24954-1-1.html

奇怪啊。我的/etc/rc.local为啥不运行啊。。。。