Has anyone added an RTC

I ordered one of these which should be suitable

I’ll probably turn my attention to other issue; until the hardware shows up. Thanks for all the pointers guys.

i have this at home, but currently not enough time to test it

https://www.elecrow.com/wiki/index.php?title=Tiny_RTC

i have to solder a level-shifter between sda/scl because the module works with 5V and the Bananapi with 3v3

i’ve found a way to get it work without levelshifter (removing pullups R2 and R3 on “tiny RTC”): https://electronics.stackexchange.com/questions/98361/how-to-modify-ds1307-rtc-to-use-3-3v-for-raspberry-pi

http://www.hobbyist.co.nz/sites/default/files/docs/RTC/Tiny_RTC_schematic.pdf

On R2 board, there is no audio chip, so you can use the i2c1(GPIO57 and GPIO 58) which are on the 40-pin header.

1 Like

how use i2c bus? Ubuntu sayed - Error: No i2c-bus specified!

Which image and kernel do you use? Official kernel may have no i2c-support (dts-nodes missing/disabled,kernel-module not included).

Have you tried the 2nd and 3rd line from here?

i use ubuntu 1.2.1 from here BPI-R2 new image : ubuntu 16.04 V1.2.1 BT and WIFI AP mode are working fine 2017-11-27

i assume that you are using the default kernel in that image (not replaced).

as of https://github.com/BPI-SINOVOIP/BPI-R2-bsp/blob/master/linux-mt/arch/arm/boot/dts/mt7623n-bpi-r2.dts i2c0-i2c2 are enabled in dts,

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

&i2c1 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c1_pins_a>;
	status = "okay";

	wm8960: [email protected] {
		compatible = "wlf,wm8960";
		reg = <0x1a>;
	};
};

&i2c2 {
	pinctrl-names = "default";
	pinctrl-0 = <&i2c2_pins_a>;
	status = "okay";
};

i2c is also enabled in Kernel-config: https://github.com/BPI-SINOVOIP/BPI-R2-bsp/blob/master/linux-mt/arch/arm/configs/mt7623n_evb_bpi_defconfig

#
# I2C support
#
CONFIG_I2C=y
CONFIG_I2C_BOARDINFO=y
CONFIG_I2C_COMPAT=y
CONFIG_I2C_CHARDEV=m 

have you tried the 2 lines i’ve mentioned?

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
modprobe rtc-ds1307

which device do you want to connect? do you have /sys/class/i2c-adapter/*?

i dont tried. i have connect rtc module and display oled ssd1306 128x32, but modules in mailed to my country, from china.

when does this error occur? Remember most i2c-device operating with 5v…bpi/rpi with 3v3…you can damage your board

so, ive added an rtc ds1307 (with removed pullups) to i2c0 (I2C_SDA0=pin3,I2C_SCL0=pin5, 5v=pin4,gnd=pin6)

modprobe i2c-dev

“i2cdetect -y 0” shows only address 0x50 (eeprom), not the 0x68 from the clock, i tried the connections on the other side (first 7pol, then the 5pol-connector), same behaviour. Tried with another module (had 2), also the same.

now i tried to add the rtc and ignoring that it was not found:

modprobe rtc-ds1307
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
cat /sys/class/i2c-dev/i2c-0/device/0-0068/rtc/rtc0/time
00:00:10
hwclock -w
cat /sys/class/i2c-dev/i2c-0/device/0-0068/rtc/rtc0/time
17:13:05

the shown time is in UTC (my local time is UTC+1)

i2cdetect shows now address 0x68 as UU like expected…i assume that the lir2032 on my boards was discharged, try to load it

i can read the rtc also via

hwclock -r

then the time is shown with timezone-setting (in CET=UTC+1)

tried reboot, but here bpi-r2 do not loose clock (disconnected lan of course so that ntp will fail) :frowning: so i have to completely switch it off

created a script:

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

and still loading the battery

after a while i have powered down the r2 some minutes, these are now missing in the clock (clock is now ~5minutes behind)

[20:27] [email protected]:~# ./rtc.sh                                                                                           
Fri 09 Mar 2018 08:32:15 PM CET  -0.559925 seconds                                                                        
[20:27] [email protected]:~# date                                                                                               
Fri Mar  9 20:27:52 CET 2018                                                                                              
[20:27] [email protected]:~# hwclock -s                                                                                         
[20:32] [email protected]:~# 

as you see i have set the clock of bpi-r2 to the value of external rtc

Well I having no luck. I removed the pull up resisters on the clock modules i ordered earlier in the thread. I have it wired up in the same way you suggest but I am not communicating with it.

I am running 4.14 checked out from your repo and compiled locally. I looked at the DTS and it appears the i2c bus is configured there. I have added support for the ds1307 to the config as well.

I am not sure this is a hardware issue through because i2cdetect does not show any devices. It looks like you indicate I should see a device at 0x50 and I don’t see that.

Any thoughts and help much appreciated.

If you have this ultra compact rtc,there is no such eeprom-chip on it so you can’t see adress 0x50 of this

Have you tried to access by creating the device like me (no search). Which pins do you use? Which kernel? are you sure that the resistors are pullups? i have more resistors in my board (some for loading-circuit)

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: [email protected] {
                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 /[email protected]/[email protected]
[    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