WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

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

Offline kmhill

  • Jr. Member
  • **
  • Posts: 64
Configuring PCF8523 real-time clock
« on: January 23, 2018, 10: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: 7183
    • My Community Forum
Re: Configuring PCF8523 real-time clock
« Reply #1 on: January 24, 2018, 12:15:03 AM »
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: 64
Re: Configuring PCF8523 real-time clock
« Reply #2 on: January 24, 2018, 01:05:18 AM »
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: 64
Re: Configuring PCF8523 real-time clock
« Reply #3 on: January 24, 2018, 01:42:16 AM »
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: 64
Re: Configuring PCF8523 real-time clock
« Reply #4 on: January 24, 2018, 07: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

  • Administrator
  • Hero Member
  • *****
  • Posts: 1243
Re: Configuring PCF8523 real-time clock
« Reply #5 on: January 24, 2018, 10: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.

Offline shaunm

  • Newbie
  • *
  • Posts: 6
Re: Configuring PCF8523 real-time clock
« Reply #6 on: January 04, 2020, 11:34:43 AM »
I'm probably hopelessly lost, but I'm also tryng to do the same and have got this far...

......$ sudo modprobe rtc-pcf8523

I get modprobe: FATAL Module rtc-pcf8523 not found in directory /lib/modules/4.414.26-pcpCore

I also tried Paul's suggestion...
Take a look at /mnt/mmcblk0p1/overlays/README

But my /mnt/mmcblk0p1/ directory is empty.

I am running PiCore v9.1.

Any suggestions gratefully received, apart from this RTC issue I've been using PiCore with my SqueezeBox since August 2018! :-)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11590
Re: Configuring PCF8523 real-time clock
« Reply #7 on: January 04, 2020, 11:47:34 AM »
Hi shaunm
... I also tried Paul's suggestion...
Take a look at /mnt/mmcblk0p1/overlays/README

But my /mnt/mmcblk0p1/ directory is empty. ...
It's probably not mounted. Try this:
Code: [Select]
mount /mnt/mmcblk0p1And check the directory again.

    [EDIT]: Corrected  mount  command.  Rich
« Last Edit: January 04, 2020, 12:08:25 PM by Rich »

Offline shaunm

  • Newbie
  • *
  • Posts: 6
Re: Configuring PCF8523 real-time clock
« Reply #8 on: January 04, 2020, 01:17:09 PM »
It's probably not mounted. Try this:
Code: [Select]
mount /mnt/mmcblk0p1And check the directory again.

    [EDIT]: Corrected  mount  command.  Rich

Thanks Rich (as you can tell I'm beginner!), I tried your suggestions, but think it is empty...

mmcblk0p1 empty
sda1 empty
mmcblk0p2 has /tce directory and inside that there is..
/tce/infobrowser.opml
mydata.tgz
/ondemand/
/optional/
piCorePlayer.dep
/slimserver/
onboot.lst
pcp_insitu_upgrade.log

Thanks for your help, I'm just going to leave it.  After playing around all day, I'm going to admit defeat on the RTC  :P
I lost my settings for the ad-hoc network by playing around today, so burned the last working version back to the SD Card and I'm back to my previous working solution.

UPDATE:
Okay, so I leave my piCorePlayer on all the time, and using the info from kmhill about setting date above, I have found a solution that I'm happy with!

For others, my PiCorePlayer just runs LMS on a Pi Zero W and has it's own network address of 10.10.10.1. It is connected to an actual physical SqueezeBox Classic.
Here's how I got the time working for me...

1. Turn Pi and Squeezebox on, wait for everything to load
2. SSH into the Pi using Putty (my ip address is 10.10.10.1)
3. use the command: sudo date -s 2020.01.04-18:00:00
4. Now, the Squeezebox screen freezes and is unresponsive. If I reset or turn off and back on the Squeezebox is gets stuck at "Obtaining an IP address"
5. Connect to Pi from web browser (my ip address is 10.10.10.1)
6. On the top menu items click LMS
7. Click the "Restart" button which is 7th button down
8. Now turn off and back on the Squeezebox Classic and it is displaying the correct time and is working again!

I hope this helps anyone else out there. And thanks again for the suggestions above.  :D