0

I have an mcp79310 RTC chip installed on gpio pins 22 & 23, and I am attempting to use it with dtoverlay=i2c-rtc-gpio,mcp7941x,i2c_gpio_sda=22,i2c_gpio_scl=23 in /boot/config.txt and adding rtc-mcp7941x to /etc/modules.

After rebooting, upon checking with $ timedatectl I get this result:

Failed to query server: Failed to read RTC: Invalid argument

Running $ i2cdetect -y 11 shows:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- UU 
70: -- -- -- -- -- -- -- --     

So nothing seems to be wrong so far. Checking $ dmesg|grep rtc shows:

[    4.299290] i2c-gpio i2c-gpio-rtc@0: using lines 22 (SDA) and 23 (SCL)
[    5.733573] rtc-ds1307 11-006f: registered as rtc0

With this failure to read the RTC, I removed the dtoverlay for it and added the i2c-gpio dtoverlay in /boot/config.txt:

dtoverlay=i2c-gpio,i2c_gpio_sda=22,i2c_gpio_scl=23

After rebooting, I tested the RTC chip directly using i2cget & i2cset (per this article - https://tom.meinlschmidt.org/2014/02/19/mcp7940-rtc-with-pi/), and it works perfectly.

After further experimentation, if I start up the Raspi with the dtoverlay=i2c-gpio enabled, but dtoverlay=i2c-rtc-gpio disabled, then disable the first dtoverlay and re-enable the second, and then reboot, the RTC works perfectly when queried by timedatectl.

In other words, if I booting, starting the RTC chip without tying it to the rtc dtoverlay, then reboot with the rtc dtoverlay it works. If I remove the RTC battery and power down, then on power-up I have to go through the same two-step boot process to get it working again.

Any ideas on how to fix this problem?

UPDATE: The problem seems to resolve after about 30 secs from the finish of boot up. I believe it may happen when timedatectl syncs its system clock (I am using chrony for NTP). If I try setting it up manually after startup:

# echo mcp7941x 0x6f > /sys/class/i2c-adapter/i2c-11/new_device

It starts working right away after I call hwclock -r. If I put the same code into /etc/rc.local it still takes about 30 secs before the RTC works.

Here's a schematic:

enter image description here

1 Answer 1

0

You need to add pull-ups to 3V3 to GPIO 22 and 23. The I2C bus requires pull-ups on SDA and SCL.

For reference the Pi has 1k8 resistors fitted between 3V3 and GPIO 2 and 3V3 and GPIO 3.

1
  • I do have pullups - 10k. I added a schematic to show.
    – Scott
    Commented Dec 10, 2021 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.