关于RTC PCF8523的调试记录
#参考文献链接:
https://cdn-learn.adafruit.com/downloads/pdf/adding-a-real-time-clock-to-beaglebone-black.pdf
- PCF8523
V | 3.3v 和 5v |
G | GND 地线 |
SDA | 数据线 |
SCL | 时钟线 |
- Connect the PCF8523 RTC module to BBGw according to the drawing;
- Connect GND on the breakoutboard to the P9_1(GND) pin on the BB
- Connect SDA on the breakoutboard to the P9_20(I2C2—SDA) pin of the BB
检测是否有68
i2cdetect -y -r 2
the i address :0x68
- rtc_pcf8523
- Make a new folder rtc_pcf8523
mkdir /usr/share/rtc_pcf8523
- clock_init.sh
- Make a new sh scripts clock_init.sh
- The purpose is to update the RTC time every 15s.
vi /usr/share/rtc_pcf8523/clock_init.sh
将此代码放入clock_init.sh
#!/bin/bash
sleep 15
echo pcf8523 0x68 > /sys/class/i2c-adapter/i2c-2/new_device
hwclock -s -f /dev/rtc1
hwclock -w
- 设置开机启动自动更新时间
vi /lib/systemd/system/rtc-pcf8523.service
将绿色部分代码放入rtc-pcf8523.service文件中
####The following is the content of rtc-pcf8523.service####
[Unit]
Description=PCF8523 RTC Service
[Service]
Type=simple
WorkingDirectory=/usr/share/rtc_pcf8523
ExecStart=/bin/bash clock_init.sh
SyslogIdentifier=rtc_pcf8523
[Install]
WantedBy=multi-user.target
- enable the service at reboot,Nothing response is OK
systemctl enable rtc-pcf8523.service
- start the service now,Nothing response is OK
systemctl start rtc-pcf8523.service
- check status
service rtc-pcf8523 status
- Restart the BBG system to ensure that the above configuration file takes effect:
reboot
- After rebooting, you will see that the original 0x68 address becomes UU, indicating that the device has achieved the boot-up target in the driver.
i2cdetect -y -r 2
- Correct RTC time
- If the system time is correct, the following commands can help you write the system time into the RTC module;
- If the system time is incorrect, you need to update the system time correctly before running the following command;
hwclock -w -f /dev/rtc1
- a simple test method:
- Disconnect BBG network connection
- Turn off the BBG system for a few minutes
- Start the BBG system and run the date command.
date