WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Configuring PCF8523 real-time clock  (Read 652 times)

Offline kmhill

  • Jr. Member
  • **
  • Posts: 57
Configuring PCF8523 real-time clock
« on: January 23, 2018, 07:14:24 PM »
Hello folks;

I'm having an issue in configuring a PCF8523 real-time clock, your help would be appreciated. Here is a summary.

  • I have rtc-4.9.22-piCore.tcz installed and is configured for onboot
  • The nortc keyword is still in the config.txt file.
  • The i2cdetect program in i2c-tools.tcz tells me that the RTC is attached at device address 0x68
    $ i2cdetect -y 1
  • At this point I'm typing in commands to try to configure the RTC. I'm following the basic outline that I used previously for the ds1307. The following is a session:
    $ sudo modprobe rtc-pcf8523
    $ echo pcf8523 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
    pcf8523 0x68
    tee: /sys/class/i2c-adapter/i2c-1/new_device: I/O error
So, it looks to me that modprobe is loading something but that the RTC is not being added as a new device.

In looking at the last few lines of what dmesg reports, I found:
Quote
[   80.179057] i2c i2c-1: Failed to register i2c client pcf8523 at 0x68 (-16)

Any ideas? Thanks in advance, Krista

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 6980
    • My Community Forum
Re: Configuring PCF8523 real-time clock
« Reply #1 on: January 23, 2018, 09:15:03 PM »
Most probably RTC is not enabled, check Device Tree Overlay in config.txt
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline kmhill

  • Jr. Member
  • **
  • Posts: 57
Re: Configuring PCF8523 real-time clock
« Reply #2 on: January 23, 2018, 10:05:18 PM »
Thanks for your reply. Apologies for not mentioning before, in looking back I see that I had the following line at the end of config.txt already. I'm not sure if that's correct or not.

dtoverlay=i2c-rtc,pcf8523

I next commented that line out and rebooted. The following session appears to go one step further.

$ sudo modprobe rtc-pcf8523
$ echo pcf8523 0x68 | sudo tee /sys/class/i2c-adatr/i2c-1/new_device
pcf8523 0x68
$ hwclock
hwclock: RTC_RD_TIME: Invalid argument

This time dmesg reports something else, but no comment on hwclock.
Quote
    [   63.825808] rtc-pcf8523 1-0068: rtc core: registered rtc-pcf8523 as rtc0
    [   63.825881] i2c i2c-1: new_device: Instantiated device pcf8523 at 0x68

Offline kmhill

  • Jr. Member
  • **
  • Posts: 57
Re: Configuring PCF8523 real-time clock
« Reply #3 on: January 23, 2018, 10:42:16 PM »
In looking about the web I'm seeing comments, that after the echo pcf8523 line, to use a command like the following:

$ sudo hwclock --systohc --utc

But those options only assign the hwclock time from the system time. So, I guessed that while the pcf8523 has been registered, it must first be assigned a valid date and time. So, I used https://time.is/UTC to get the date and time, then set the RTC.

$ sudo date -s 2018.01.24-06:21:00
Wed Jan 24 06:21:00 UTC 2018
$ sudo hwclock --systohc --utc

My previous post has a typographical error, as i2c-adatr should be i2c-adapter. The original post is correct. In any case, I rebooted the system and here is the latest session:

$ sudo modprobe rtc-pcf8523
$ echo pcf8523 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
pcf8523 0x68
$ hwclock
Wed Jan 24 06:33:53 2018  0.000000 seconds

The next step is to enter commands into bootlocal.sh





Offline kmhill

  • Jr. Member
  • **
  • Posts: 57
Re: Configuring PCF8523 real-time clock
« Reply #4 on: January 24, 2018, 04:27:18 PM »
Here is a summary of my adventure in configuring the PCF8523 real-time clock. I did this with a RasPi-0W and TinyCore version 9.0.3

I'm using the Adafruit PiRTC - PCF8523 Real Time Clock module. While on one hand its socket plugs neatly into the GPIO connector, the socket hides some pins including those for the TTY port as well as +5V power. There are feed through holes, so that with some careful soldering, I was able to solder some pin strips for those otherwise hidden pins.

For libraries, make sure that the following is installed and configured as onboot.
rtc-4.9.22-piCore.tcz

Before editing bootlocal.sh, be sure to try the commands out by hand... First set the system date and time. If your system is connected to the Internet, it should have already used settime.sh to set the date and time.

Otherwise you can manually set the date and time. I used https://time.is/UTC to get the date and time, then I set the RTC.

$ sudo date -s 2018.01.24-06:21:00
Wed Jan 24 06:21:00 UTC 2018

The following are commands that I typed in to configure the RTC. The hwclock command will report the date and time from the RTC.

$ sudo modprobe rtc-pcf8523
$ echo pcf8523 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
$ sudo hwclock --systohc --utc
$ hwclock

At this point edit the /opt/bootlocal.sh file. Insert the following lines at the end.

modprobe rtc-pcf8523
echo pcf8523 0x68 | tee /sys/class/i2c-adapter/i2c-1/new_device
sleep 1s
hwclock -s

Once the text is inserted, be sure to backup. From the command line you can execute filetool.sh -b

In the future if you need to reset the RTC, first set the system date and time then set the RTC. Having the notes in this forum have been a huge help, thanks everyone. If I missed anything, a post will be appreciated.

$ sudo date -s 2018.01.24-06:21:00
Wed Jan 24 06:21:00 UTC 2018
$ sudo hwclock --systohc --utc
$ hwclock


Offline Paul_123

  • Sr. Member
  • ****
  • Posts: 430
Re: Configuring PCF8523 real-time clock
« Reply #5 on: January 24, 2018, 07:34:29 PM »
while modprobe will work, the more correct way to load the driver is with overlays.

Take a look at /mnt/mmcblk0p1/overlays/README

Look at overlay i2c-rtc

overlays get set in the config.txt on the boot drive.