Has anyone added an RTC

Pretty sure the resisters were acting as pull-ups. Sorry I misunderstood and thought perhaps the eeprom you mentioned as something on board the BPI-R2. I am running 4.14 compiled after a checkout from your repo. I do see error -110 in the dmesg output after attempting to insert the device via echo > new_device.

I might just try grabbing another module designed for a RPI where everything is expecting 3v logic based on your clarification, as I don’t have anything else to test this module out with.

Maybe you got a broken module ? I bought 4 module from the network, but I got one of it missing the ds1307… image

Hi. I am trying to use i2c1 on pin 3 &5. My “i2cdetect -y 1” not detected my I2C module. I already loaded i2c-dev and ds1307 modules.

#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: – -- – -- – -- – -- – -- – -- – -- – --

70: – -- – -- – -- – --

TIA.

I used i2c0 for testing my RTC.
Thanks for @frank-w, My module works fine now
(My RTC modules is “Tiny RTC I2C modules”)
image

Steps:

  1. I have removed pull-ups on DS1307 (@frank-w’s reply “removing pullups R2 and R3 on “tiny RTC”” )
  2. Use @frank-w’s step to compile linux image (DTS, kernel config…etc)
  3. Connect RTC modules to BPIR2 in follow way: (Notice: connect 5v to vcc, don’t use 3.3v)
    (Please confirm the DS1307 chip exist on your module :smile: ) image
  4. Use the command i2cdetect -y -r -a 0 to scan the i2c bus 0 (/dev/i2c-0) --> “0x68”
  5. modprobe rtc-ds1307
    echo ds1307 0x68 > /sys/bus/i2c/devices/i2c-0/new_device
    cat /sys/bus/i2c/devices/i2c-0/0-0068/rtc/rtc0/time
  6. Use the command date, hwclock -w and hwclock -r to test your module
1 Like

Hi. I am Frank’s 4.14.28 kernel and I can find that the I2C0 & I2C1 are exist on /dev/. However, i2cdetect -y 0/1 detected nothing. I am using 420mA Serial to I2C converter. I confirmed that my I2C module is working fine on RPI board. So I assume, I no need to worry up the pullups.

For experiment, I also tried with DS3231 RTC module. Still it is not detected anything on the I2C port.

TIA.

I have an issue on BPi-R2 and time is always behind. After one night the clock is 15minutes behind current time. I have sync (ntp) the time yesterday after boot as it was 1 week behind current time. How come the BPI-R2 is always behind current time? I have “RTC_DRV_DS1307” enable in the kernel. Do i have to buy a physical new card for RTC (Real Time Clock) ?

Is that the same as for BPI-R1, https://bananapi.gitbooks.io/bpi-accessories/content/en/rtcmodule.html?

For external rtc you need an external board like ds1307 but care about the data-levels (5v are not good for pi-pins which are operating with 3v3)

I feel like an archeologist, but, just in case… :slight_smile:

adding rtc notes to mt7623n-bananapi-bpi-r2.dts like:

&i2c0 {
        pinctrl-names = "default";
        pinctrl-0 = <&i2c0_pins_a>;
        status = "okay";

        ds1307: ds3231@68 {
                compatible = "maxim,ds3231";
                reg = <0x68>;
                status = "okay";
        };
};

will add driver autodetect on boot:

[    5.992725] i2c-dev: adapter [mediatek-hdmi-ddc] registered as minor 0
[    6.000117] i2c-dev: adapter [i2c-mt65xx] registered as minor 1
[    6.006148] i2c i2c-1: adapter [i2c-mt65xx] registered
[    6.011331] i2c i2c-1: of_i2c: walking child nodes
[    6.016164] i2c i2c-1: of_i2c: register /i2c@11007000/ds3231@68
[    6.022258] i2c i2c-1: client [ds3231] registered with bus id 1-0068
[    6.029347] i2c-dev: adapter [i2c-mt65xx] registered as minor 2
[    6.035375] i2c i2c-2: adapter [i2c-mt65xx] registered
[    6.040570] i2c i2c-2: of_i2c: walking child nodes
... rtc_ds1307 module loading...
[   21.760493] rtc-ds1307 1-0068: probe
[   21.760641] i2c-core: using bounce buffer for addr=0x68, len=1
[   21.760654] i2c-core: using bounce buffer for addr=0x68, len=2
[   21.761371] i2c-core: using bounce buffer for addr=0x68, len=2
[   21.761795] i2c-core: using bounce buffer for addr=0x68, len=1
[   21.761810] i2c-core: using bounce buffer for addr=0x68, len=8
[   21.763065] i2c-core: using bounce buffer for addr=0x68, len=1
[   21.763084] i2c-core: using bounce buffer for addr=0x68, len=7
[   21.764574] rtc-ds1307 1-0068: registered as rtc1
[   21.764783] i2c-core: using bounce buffer for addr=0x68, len=1
[   21.764797] i2c-core: using bounce buffer for addr=0x68, len=1
[   21.766003] i2c-core: driver [rtc-ds1307] registered

I have ds3231, but it uses ds1307 driver so it’s possible to use ds1307 dts notes

I’ve attached DS3231 HW-022 to bpi-r2, on gpio 1, 3, 5, 7, 9 :

image

And read specification :

The module itself can adapt to 3.3V and 5V systems without level shifting, which is super convenient!

Modified your script a bit for i2c-1, but guess it’s not working!

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: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

hwclock -r
2020-12-03 13:35:48.304171+01:00

Following from dmesg :

[  217.045826] i2c /dev entries driver
[  217.085742] rtc-ds1307 1-0068: registered as rtc1
[  217.086037] i2c i2c-1: new_device: Instantiated device ds1307 at 0x68
[  310.540830] mediatek-hdmi-ddc 11013000.i2c: i2c ack err!
[  310.540875] mediatek-hdmi-ddc 11013000.i2c: ddc failed!
[ 1383.733606] i2c i2c-1: Failed to register i2c client ds1307 at 0x68 (-16)
[ 1396.525472] i2c i2c-1: Failed to register i2c client ds1307 at 0x68 (-16)

What did I wrong? Can I damage my board with this module?

Which script did you mean? @DeadMeat have changed dts which needs recompiling kernel also for adding the driver.

You can damage board if your module uses 5v levels…bpi has 3.3v

Now it’s seems to me working :

[  312.306782] rtc-ds1307 1-0068: SET TIME!
[  312.309498] rtc-ds1307 1-0068: registered as rtc1
[  312.311286] i2c i2c-1: new_device: Instantiated device ds3231 at 0x68

I used your script :

#!/bin/bash
modprobe i2c-dev
modprobe rtc-ds1307
echo ds3231 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
#cat /sys/class/i2c-dev/i2c-1/device/1-0068/rtc/rtc1/time
#read rtc
hwclock -r
#set system-clock to rtc-value
hwclock -w -f /dev/rtc1
hwclock -r -f /dev/rtc1
hwclock -s -f /dev/rtc1 

Output from date && hwclock -r :

Thu Dec  3 14:18:37 CET 2020
2020-12-03 14:18:38.393795+01:00

Ah, long time ago…march 2018 (Has anyone added an RTC) Good to head it works now…what have you changed? I see in your log that maybe a collision with hdmi-ddc happened

What does it mean? Collision of hdmi-ddc?

Modifying this line :

echo ds3231 0x68 > /sys/class/i2c-adapter/i2c-1/new_device

and this in the end :

hwclock -w -f /dev/rtc1
hwclock -r -f /dev/rtc1
hwclock -s -f /dev/rtc1 

which kernel do you use?

Linux bpi-r2 5.4.80-bpi-r2-main

i hope with hdmi merging we can workaround this i2c issue (my 5.9+)

so you have changed the line to i2c-1 and then it worked?

Exactly, because attached it to i2c-1. But it applies time after kernel modules loaded. Does it make sense? It should know time from startup, shouldn’t it? I got it from a friend of mine, didn’t read any of its advantage. What is your suggestion regarding hdmi problem?

Name in dts does not matter…devices are numbered by creation…hdmi-ddc creates an own i2c which maybe come first and so catches i2c0…next one i2c0 (if enabled) gets i2c1, and so on…

Of course it works only after driver is loaded via module :slight_smile:

Hello Frank!

After a successfull RTC project I decided attaching a tiny oled screen(SSD1306) to R2. If I change the rtc shield to oled screen, I’m able to activate and put some important infos on it. It means, only one i2c bus is being activated this time and only through these gpio’s : image

The main problem is, I can not use the second i2c bus at the same time:

What should I do to achieve this behavior?

Have you tried i2c2 instead of i2c1? Afair hdmiddc also adds an i2c bus which is maybe i2c1