Linux 設定RTC外接感測器完整教程
阿新 • • 發佈:2018-12-15
關於RTC PCF8523的除錯記錄
#參考文獻連結:
- 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