Adafruit PiRTC - PCF8523 RTC: hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
mike_veolectra
 
Posts: 3
Joined: Mon May 13, 2024 3:05 pm

Adafruit PiRTC - PCF8523 RTC: hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument

Post by mike_veolectra »

"If you are getting an error message like this when trying to read/write to the RTC, make sure you have a good coin cell battery installed."
I have use five different "Energizer CR1220 Low Drain 3V lithuim Batteries" - all have had a minimum of 3.2 Volts.
No Luck - PLEASE ADVISE!
OS: Raspbian GNU/Linux 12 (bookworm)

--- /lib/udev/hwclock-set
--- DOES NOT HAVE ALL INFORMATION SHOWN IN TUTORTIAL "https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-rtc-time"

#!/bin/sh
# Reset the System Clock to UTC if the hardware clock from which it
# was copied by the kernel was in localtime.

dev=$1

#if [ -e /run/systemd/system ] ; then
# exit 0
#fi

#/sbin/hwclock --rtc=$dev --systz
/sbin/hwclock --rtc=$dev --hctosys

____________________________________________________
COMMAND LINE: sudo hwclock -r --verbose
hwclock from util-linux 2.38.1
System Time: 1715689241.189133
Trying to open: /dev/rtc0
Using the rtc interface to the clock.
Last drift adjustment done at 1715687826 seconds after 1969
Last calibration done at 1715687826 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
ioctl(4, RTC_UIE_ON, 0): Invalid argument
Waiting in loop for time from /dev/rtc0 to change
hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument
...synchronization failed

User avatar
mikeysklar
 
Posts: 15436
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafruit PiRTC - PCF8523 RTC: hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument

Post by mikeysklar »

Have you disabled the fake hardware clock?

Did you run:

Code: Select all

sudo hwclock -w
before running:

Code: Select all

sudo hwclock -r

Code: Select all

sudo apt-get -y remove fake-hwclock
sudo update-rc.d -f fake-hwclock remove
sudo systemctl disable fake-hwclock

User avatar
mike_veolectra
 
Posts: 3
Joined: Mon May 13, 2024 3:05 pm

Re: Adafruit PiRTC - PCF8523 RTC: hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument

Post by mike_veolectra »

Yes I have disabled and removed the fake hardware clock.

sudo hwclock -w
--- NO ERROR

sudo hwclock -r
ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument

User avatar
mikeysklar
 
Posts: 15436
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafruit PiRTC - PCF8523 RTC: hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument

Post by mikeysklar »

Okay, I'll do some testing with my Pi4's today. I'm guessing this is a bookworm change we need to adapt to.

User avatar
mike_veolectra
 
Posts: 3
Joined: Mon May 13, 2024 3:05 pm

Re: Adafruit PiRTC - PCF8523 RTC: hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument

Post by mike_veolectra »

I have tried with Bookworm and Bullseye

User avatar
mikeysklar
 
Posts: 15436
Joined: Mon Aug 01, 2016 8:10 pm

Re: Adafruit PiRTC - PCF8523 RTC: hwclock: ioctl(RTC_RD_TIME) to /dev/rtc0 to read the time failed: Invalid argument

Post by mikeysklar »

I had to order a STEMMA breakout version of PCF8523 RTC.

However, I did have a Adafruit Adalogger on hand which also has built in RTC so I wired that up to my Pi5.

Note that I am using a battery (are you)?
IMG_2647.jpeg
IMG_2647.jpeg (209.81 KiB) Viewed 515 times

I see it on the i2c bus:

Code: Select all

(env) pi@pi5:~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

The clock shows up so if I load the kernel module and want to read and write this is how I did it:

Code: Select all

pi@pi5:~ $ sudo modprobe rtc-pcf8523
pi@pi5:~ $ sudo bash -c "echo pcf8523 0x68 > /sys/class/i2c-adapter/i2c-1/new_device"
pi@pi5:~ $ sudo hwclock -r
2024-05-16 09:43:27.088998-07:00
pi@pi5:~ $ sudo hwclock -w

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Clock Kits (discontinued)”