CM3计算板安装硬件时钟DS3231
1、硬件連接
DS3231是高速(400kHz)I2C接口的實時時鐘芯片,0°C至+40°C范圍內精度為±2ppm,-40°C至+85°C范圍內精度為±3.5ppm,工作電壓3.3V,提供電池備份,具有輸入低功耗,實時時鐘產生秒、分、時、星期、日期、月和年計時,并提供有效期到2100年的閏年補償。
可以使用CM3計算板上任意的I2C接口連接DS3231,這里使用GPIO2和GPIO3 I2C1接口連接時鐘芯片。采用CR1220電池對芯片備用供電。硬件連接如下:
2、系統注冊設備
2.1 查看是否正確連接
首先查看i2c 接口是否識別到DS3231設備,使用如下命令查看是否存在id為68的設備,如果存在則i2c已經正確連接了DS3231:
sudo i2cdetect -y 12.2 設置開機注冊時鐘設備并同步
CM3開機后主動注冊DS3231,并同步時鐘時間為系統時間。在/etc/rc.local中填入如下命令:
sudo modprobe i2c-dev sudo modprobe i2c-bcm2708 echo ds3231 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device sudo hwclock -s sudo hwclock -wmodprobe命令自動處理可載入模塊,可載入指定的個別模塊,或是載入一組相依的模塊會根據depmod所產生的相依關系,決定要載入哪些模塊。若在載入過程中發生錯誤,在modprobe會卸載整組的模塊。
hwclock命令用法如下:
Usage:hwclock [function] [option...]Time clocks utility.Functions:-r, --show display the RTC time--get display drift corrected RTC time--set set the RTC according to --date-s, --hctosys set the system time from the RTC-w, --systohc set the RTC from the system time--systz send timescale configurations to the kernel-a, --adjust adjust the RTC to account for systematic drift--predict predict the drifted RTC time according to --dateOptions:-u, --utc the RTC timescale is UTC-l, --localtime the RTC timescale is Local-f, --rtc <file> use an alternate file to /dev/rtc0--directisa use the ISA bus instead of /dev/rtc0 access--date <time> date/time input for --set and --predict--delay <sec> delay used when set new RTC time--update-drift update the RTC drift factor--noadjfile do not use /etc/adjtime--adjfile <file> use an alternate file to /etc/adjtime--test dry run; implies --verbose-v, --verbose display more details-h, --help display this help-V, --version display versionsudo hwclock -s? 用RTC時間更新系統時間
sudo hwclock -w 用系統時間更新RTC時間
2.3 重啟并確認是否注冊成功
重啟后,查看i2c-1 原來68的id已經變成UU,變成UU則說明已經注冊成功。
2.4?查看時間
date 查看系統時間,hwclock -r 讀取硬件時間。
總結
以上是生活随笔為你收集整理的CM3计算板安装硬件时钟DS3231的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: STM32 网络通信Web Server
- 下一篇: html文件上传限制类型,html in