Page 1 of 1

How to set up i2c for rtc?

Posted: Fri Feb 15, 2019 11:31 pm
by njsss
I have used adafruit RTC pcf8523 with raspberry pi. Now I am trying to get it to work on CM3+.

I tried to edit the config.txt to set it on pins 22/23 or 23/24 (as appeared default in i2c-gpio)

Code: Select all

# Add new I2C
#dtoverlay=i2c-gpio,i2c_gpio_sda=22,i2c_gpio_scl=23
#dtoverlay=i2c1-bcm2708,sda1_pin=22,scl1_pin=23,pin_func=6
dtoverlay=i2c-gpio
dtoverlay=i2c-rtc,pcf8523

The device was detected as an i2c, but doesn't appear to be recognized.

Code: Select all

$ i2cdetect -y 3

shows 68 at location 68, but probe return error

Code: Select all

$ dmesg | grep pcf8523

rtc-pcf8523: probe of 1-0068 failed with error -121
failed to access rtc

Code: Select all

$ sudo hwclock -D -r

hwclock from util-linux 2.29.2
hwclock: cannot open /dev/rtc: No such file or directory
No usable clock interface found.
hwclock: Cannot access the Hardware Clock via any known method.
Finally it doesn't seem the gpios were changed after all.

Code: Select all

$ sudo raspi-gpio get

GPIO 0: level=1 fsel=0 func=INPUT
GPIO 1: level=1 fsel=0 func=INPUT
GPIO 2: level=1 fsel=4 alt=0 func=SDA1
GPIO 3: level=1 fsel=4 alt=0 func=SCL1
GPIO 4: level=1 fsel=0 func=INPUT
......
GPIO 22: level=0 fsel=0 func=INPUT
GPIO 23: level=1 fsel=0 func=INPUT
GPIO 24: level=1 fsel=0 func=INPUT
How to fix it? Thanks!

Re: How to set up i2c for rtc?

Posted: Sat Feb 16, 2019 7:50 am
by DougieLawson
njsss wrote:
Fri Feb 15, 2019 11:31 pm

Code: Select all

$ dmesg | grep pcf8523

rtc-pcf8523: probe of 1-0068 failed with error -121
Your RTC hardware is broken or not wired to the I2C sda/scl pins correctly.
https://pinout.xyz/pinout/i2c

Re: How to set up i2c for rtc?

Posted: Sat Feb 16, 2019 9:52 am
by 6by9
I2c-rtc is set up to talk to an rtc on i2c_arm, not an i2c_gpio device.
Documentation of overlays is in the readme https://github.com/raspberrypi/linux/bl ... ays/README

There's also an i2c-rtc-gpio overlay that is the same as i2c-rtc but using i2c_gpio. Switch to using that and it should work.

Re: How to set up i2c for rtc?

Posted: Mon Feb 18, 2019 5:02 pm
by njsss
6by9 wrote:
Sat Feb 16, 2019 9:52 am
I2c-rtc is set up to talk to an rtc on i2c_arm, not an i2c_gpio device.
Documentation of overlays is in the readme https://github.com/raspberrypi/linux/bl ... ays/README

There's also an i2c-rtc-gpio overlay that is the same as i2c-rtc but using i2c_gpio. Switch to using that and it should work.
Thank you, it works! Now I need to figure out how to add other i2c to the same pins.