Schorschi
Posts: 324
Joined: Thu Nov 22, 2012 9:38 pm

Pulling out hair over ds1307 on bus 0 using dtoverlay?

Tue Feb 01, 2022 2:47 am

Ok, I have used overlays before, for various devices, sensors, etc. But trying to get a ds1307 RTC device on a Pi 1 Model A is driving me to pull my hair out!

I have tried the following in config.txt...

dtoverlay=i2c-rtc,ds3231
dtoverlay=i2c-rtc,ds3231

Then I recalled that I need bus 0, so tried the following, per the dtoverlay documentation...

dtoverlay=i2c0-rtc,ds1307
dtoverlay=i2c0-rtc,ds3231

Why did I try ds3221, came across a reference on GitHub about the ds1307 once having an issue, and it was suggested ds3231 might work as a temporary fix. But not for me it seems. None of the above work, the 0x68 address for the RTC device, never show UU via i2cdetect -y 0. I never get /dev/rtc0 established. So then I tried the old method...

# modprobe rtc-ds1307
# lsmod | grep rtc
# echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device

And sure enough, I know have /dev/rtc0 as needed! And of course, i2cdetect -y 0 shows UU for address 0x68 as expected. So have I tripped over an old bug, a new bug or what? I really want to use the device tree method!

Using Pi OS 11, 32 bit of course for a Model 1A.

trejan
Posts: 4558
Joined: Tue Jul 02, 2019 2:28 pm

Re: Pulling out hair over ds1307 on bus 0 using dtoverlay?

Tue Feb 01, 2022 3:34 am

i2c0 is a parameter for the i2c-rtc overlay. It isn't a separate overlay. You need to do "dtoverlay=i2c-rtc,i2c0,ds3231"

Schorschi
Posts: 324
Joined: Thu Nov 22, 2012 9:38 pm

Re: Pulling out hair over ds1307 on bus 0 using dtoverlay?

Tue Feb 15, 2022 6:30 am

Unfortunately, that did not seem to work, although my ds1307 module works with older method of configuration, the current dtoverlay fails to take control of the device, no /dev/rtc0 device is created. Nor does i2cdetect show the typical 'UU' at the device address, which is 0x68. It appears the overlay never attempted to load or be loaded. For example...

Code: Select all

# i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- 44 -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Boot configuration...

Code: Select all

#hdmi_safe=1
hdmi_force_hotplug=1
hdmi_group=1
hdmi_mode=16
#hdmi_drive=2
config_hdmi_boost=11

# Force i2c Baud Rate To 10K To Avoid Clock Stretch...
dtparam=i2c_arm=on
dtparam=i2c_arm_baudrate=10000

# Disable SPI And 1-Wire...
#dtparam=i2s=on
#dtparam=spi=on

# Enable Audio...
dtparam=audio=on

# Disable Cameras...
#camera_auto_detect=1

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2
disable_overscan=1

[cm4]
otg_mode=1

[pi4]
arm_boost=1

[all]
dtdebug=1
enable_uart=1
gpu_mem=16
dtoverlay=i2c-rtc,i2c0,ds3231
# dmesg | grep rtc
(Nothing)

Where as, using the overlay with bus 1, ds3231 device, works as expected...

Code: Select all

# 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: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- 77

# cat /boot/config.txt
#hdmi_safe=1
hdmi_force_hotplug=1
hdmi_group=1
hdmi_mode=16
#hdmi_drive=2
config_hdmi_boost=11
dtparam=i2c_arm=on
dtparam=i2s=off
dtparam=spi=off
dtparam=audio=on
camera_auto_detect=0
display_auto_detect=0
disable_overscan=1

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2

[cm4]
otg_mode=1

[pi4]
arm_boost=1

[all]
enable_uart=1
gpu_mem=8
max_usb_current=1

dtoverlay=i2c-rtc,ds3231

# dmesg | grep rtc-ds
[   30.877057] rtc-ds1307 1-0068: registered as rtc0
[   30.878225] rtc-ds1307 1-0068: setting system clock to 2022-02-15T06:17:00 UTC (1644905820)

So... still a mystery it appears! Since the old school method, works, I know this is not a hardware issue or i2c communication issue per se.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 13013
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Pulling out hair over ds1307 on bus 0 using dtoverlay?

Tue Feb 15, 2022 9:26 am

The original model A and B are a bit of a pain as they used the opposite I2C bus to everything that followed. I'm amused you're still using one after all this time - I couldn't say when I last powered my 256MB model B up.

The overlays use i2c_arm as the bus designation, and this is always automatically mapped to whichever bus is considered to be assigned to the ARM on the respective board, therefore I2C controller 0 for an original A&B. I don't recall if the actual designations of /dev/i2c-0 and /dev/i2c-1 get swapped as well, as your kernel log implies that it sees your RTC as bus 1 address 0068.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

markbradley27
Posts: 1
Joined: Mon Jun 20, 2022 5:04 am

Re: Pulling out hair over ds1307 on bus 0 using dtoverlay?

Mon Jun 20, 2022 5:21 am

I'm having the same exact issue, also trying to use a ds1307 with an old Raspberry Pi 1 (A I think). After a fresh boot, this little session here shows that despite the i2c-rtc dtoverlay being specified in /boot/config.txt (I've tried with and without the 'i2c0' param), the kernel module isn't loaded and the rtc device isn't created. Manually loading and creating them work though, and the rtc definitely works because I set that 2014 date with an Arduino.

Code: Select all

pi@henrietta:~ $ tail -n 2 /boot/config.txt
# Added by Mark to enable the RTC.
dtoverlay=i2c-rtc,i2c0,ds1307
pi@henrietta:~ $ lsmod | grep ds1307
pi@henrietta:~ $ file /dev/rtc
/dev/rtc: cannot open `/dev/rtc' (No such file or directory)
pi@henrietta:~ $ sudo modprobe rtc-ds1307
pi@henrietta:~ $ sudo bash
root@henrietta:/home/pi# echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
root@henrietta:/home/pi# exit
exit
pi@henrietta:~ $ lsmod | grep ds1307
rtc_ds1307             28672  0
regmap_i2c             16384  1 rtc_ds1307
pi@henrietta:~ $ file /dev/rtc
/dev/rtc: symbolic link to rtc0
pi@henrietta:~ $ dmesg | tail -n 3
[ 1571.502561] rtc-ds1307 0-0068: registered as rtc0
[ 1571.505603] rtc-ds1307 0-0068: setting system clock to 2014-01-21T05:33:13 UTC (1390282393)
[ 1571.508484] i2c i2c-0: new_device: Instantiated device ds1307 at 0x68
Seems we've stumbled across a bug? Perhaps we're the only two people out there still using model 1A's?? I'd get a newer one if anyone had them in stock...

Return to “Device Tree”