Linux 设置RTC外接传感器完整教程

关于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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值