Jump to content

RTC ds1307 i2C for Tinkerboard


dragonlost

Recommended Posts

The ds1307 should work on stock kernels from at least 2.6 without problem.

 

I use the ds3231's which uses the same ds1307 driver that you need to use. Its working fine for me in 4.4 and 4.13 kernels on the tinker. I use the 3231 purely because we can buy them for < £1.50 each mounted with temp sensor and battery and it works on stock kernels.

 

When you load the rtc-ds1307 module does /dev/rtc1 appear? (/dev/rtc0 is the rk808 normally)

 

Are you using the miniarm device tree, custom or in kernel?

 

Have you modified your udev rules to point at KERNEL=="rtc1" instead of KERNEL=="rtc0"? (default and hwclock rules)

 

Have you set HCTOSYS_DEVICE=rtc1 in /etc/default/hwclock?

 

 

 

Link to comment
Share on other sites

hello.

 

I use Next version for tinkerboard (kernel 4.13.3)

 

When i plug RTC (it's DS3231) in my tinkerboard, i no see RTC1 in /dev/ just RTC0.

 

with the command : i2cdetect -y 1 i see 68.

 

I need to activate something to see RTC1?

 

No have /etc/default/hwclock

 

 

edit :

 

With command :

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new-device

and ls /dev/rtc*

 

i see RTC1.

with command :

hwclock --rtc /dev/rtc1

i see time on RTC DS3231.

 

But I do not understand how to ask the Tinkerboard to use it

Link to comment
Share on other sites

Can you post the output of the following:

 

dmesg

 

lsmod | while read i ; do echo "#### Module: $i ####" ; echo $i | cut -d" " -f1 ; modinfo `echo $i | cut -d" " -f1` ; done

 

i2cdetect -l
i2cdetect -y -a 1

 

Link to comment
Share on other sites

My RTC is atached to GPIO 3 and 5

 

result of lsmod :

 

Module                            Size  Used by

snd_soc_hdmi_codec    16384  0

mali_kbase                 339968  0

dw_hdmi_i2s_audio      16384  0

uas                                20480  0

Link to comment
Share on other sites

15 minutes ago, dragonlost said:

My RTC is atached to GPIO 3 and 5

 

result of lsmod :

 

Module                            Size  Used by

snd_soc_hdmi_codec    16384  0

mali_kbase                 339968  0

dw_hdmi_i2s_audio      16384  0

uas                                20480  0

 

Extra sanity check, did you connect the RTC Ground to pin4 on the tinker?

 

Also you dont have the rtc-ds1307 kernel module loaded. If you reboot clean and "modprobe rtc-ds1307" does /dev/rtc1 appear without the "echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new-device"?

 

If yes to both then the next steps for setup are easy.

Link to comment
Share on other sites

@TonyMac32 thanks!

 

Steps to use the ds3231 as system clock:

 

1) Add "echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new-device" to /etc/rc.local (if needed and above "exit 0")

2) In /lib/udev/hwclock-set comment out the following:

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

if [ -e /run/udev/hwclock-set ]; then
    exit 0
fi

then change the HCTOSYS_DEVICE=rtc0 to be HCTOSYS_DEVICE=rtc1

3)In /lib/udev/rules.d/50-udev-default.rules change the SUBSYSTEM=="rtc" line to:

SUBSYSTEM=="rtc", KERNEL=="rtc1", SYMLINK+="rtc", OPTIONS+="link_priority=-100"

4) In your hwclock udev rule make sure you have (/lib/udev/rules.d/85-hwclock.rules):

KERNEL=="rtc1", RUN+="/lib/udev/hwclock-set $root/$name"

 

Link to comment
Share on other sites

13 minutes ago, dragonlost said:

After modprobe rtc-ds1307 i not see rtc1.

In my list of modprobe posibilty no have rtc-ds1307 just "rtc-cpcap"

Ahh, did you compile as kernel built in instead of module?

 

Also is the RTC ground pin connected to GPIO pin 4 on the tinker?

Link to comment
Share on other sites

Yes thats the correct pins sorry, I had a different board in my mind when I was thinking about it.

 

OK so if you ONLY do the command: "echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new-device"   from a clean boot then you can read the RTC? Is that correct? You can read it without loading a kernel driver module?

Link to comment
Share on other sites

5 minutes ago, botfap said:

Yes thats the correct pins sorry, I had a different board in my mind when I was thinking about it.

 

OK so if you ONLY do the command: "echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new-device"   from a clean boot then you can read the RTC? Is that correct? You can read it without loading a kernel driver module?

yes from clean boot and i load the command  : "echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new-device", i see rtc1 in device and i can read it with hwclock --rtc /dev/rtc1

Link to comment
Share on other sites

Thats good, it means the driver is compiled into the kernel.

 

Do the following:

 

1) Add "echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new-device" to /etc/rc.local, above the "exit 0" line at the bottom

 

2) In /lib/udev/hwclock-set comment out the lines below then change the HCTOSYS_DEVICE=rtc0 line to be HCTOSYS_DEVICE=rtc1

if [ -e /run/systemd/system ]; then 
	exit 0
fi 
if [ -e /run/udev/hwclock-set ]; then
exit 0
fi

 

3) In /lib/udev/rules.d/50-udev-default.rules change the SUBSYSTEM=="rtc" line to:

SUBSYSTEM=="rtc", KERNEL=="rtc1", SYMLINK+="rtc", OPTIONS+="link_priority=-100"

 

4) In your hwclock udev rule make sure you have (/lib/udev/rules.d/85-hwclock.rules):

KERNEL=="rtc1", RUN+="/lib/udev/hwclock-set $root/$name"

Link to comment
Share on other sites

1 hour ago, botfap said:

2) In /lib/udev/hwclock-set comment out the following:


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

if [ -e /run/udev/hwclock-set ]; then
    exit 0
fi

I do not understand why it is necessary to comment his lines?

Link to comment
Share on other sites

7 minutes ago, dragonlost said:

I do not understand why it is necessary to comment his lines?

Becuase /run/systemd/system will always exist and that if statement terminates the script if it finds /run/systemd/system

 

You can leave the second one in if you want, /run/udev/hwclock-set doesnt and wont exist, its just not relevant.

Link to comment
Share on other sites

53 minutes ago, botfap said:

Thats good, it means the driver is compiled into the kernel.

 

Do the following:

 

1) Add "echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new-device" to /etc/rc.local, above the "exit 0" line at the bottom

 

2) In /lib/udev/hwclock-set comment out the lines below then change the HCTOSYS_DEVICE=rtc0 line to be HCTOSYS_DEVICE=rtc1


if [ -e /run/systemd/system ]; then 
	exit 0
fi 
if [ -e /run/udev/hwclock-set ]; then
exit 0
fi

 

3) In /lib/udev/rules.d/50-udev-default.rules change the SUBSYSTEM=="rtc" line to:


SUBSYSTEM=="rtc", KERNEL=="rtc1", SYMLINK+="rtc", OPTIONS+="link_priority=-100"

 

4) In your hwclock udev rule make sure you have:

KERNEL=="rtc1", RUN+="/lib/udev/hwclock-set $root/$name"

 

 

I made the changes you gave me but it does not work.

The rtc1 is detected but does not update the system clock at startup.
On the other hand, the rtc0 does not do it either.

The rtc1 is on time. The rtc0 is in 2013. The system clock is staying at the time it was before extinction.

to test I disconnected the networks and I left off for 20min. Then I rode without networks.

Link to comment
Share on other sites

--systz sets the time zone and only needs to be called once per boot, it wont show you any time changes

--hctosys sets the system time from the rtc

--systohc sets the rtc clock with the system time (after ntp sync for example)

 

What happens if you run just:

 

/lib/udev/hwclock-set /dev/rtc1

 

Link to comment
Share on other sites

17 minutes ago, botfap said:

--systz sets the time zone and only needs to be called once per boot, it wont show you any time changes

--hctosys sets the actual time from the rtc

--systohc sets the rtc clock with the system time (after ntp sync for example)

 

What happens if you run just:

 


/lib/udev/hwclock-set

 

hwclock: Cannot access the Hardware Clock via any known method

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines