Has anyone added an RTC

Hi guys I am having all sorts of fun with this! Thanks for all the hard work on the kernel frank-w that has been a huge time saver.

One thing that is driving me nuts though is the lack of clock. Obviously ntp / netdate make setting the time from network pretty trivial but ultimately this device might be the first network component I bring up and I have a number of early boot scripts and things I’d like to run before I bring up an external interface; it would be nice to have a correct system date. Any suggestions on a clock? Has anyone else got something working? I would assume the best way is i2c bus? unless there is something ready made out there with a uart interface?

the most common RTC-module for arduino is ds1307 and working over i2c…i did nothing till now with i2c on bpi-r2 yet…i currently do not know if the names (i2c0,i2c1) are right for GPIO-header, because i2c1 is used also for internal audio-chip

maybe i2c1 is internal only and i2c0+i2c2 are routed to gpio-header

@garywang please can you bring light in the dark?

i2c0, i2c1 should be all available on the 40 pins-header (DIP40).

currently, i2c1 is not connected to anything in bpi-r2. so it’s free to use i2c1 on the board

and thus something is needed to be corrected

actually, the internal audio-chip is put on another daughterboard as mt7623n’s extension and is accessed via i2c1.

and i2c2 is routed to MIPI slot which I thought it is NOT easy to rework the hardware to connect any i2c slave.

1 Like

So here some infos about kernel-config and circuit: https://microeletroniki.wordpress.com/2012/09/05/ds1307-with-rpi-kernel-on-bootup/

thanks for the tips. I have to mail order pretty much everything as far as electronics go where I am. So its time consuming to be wrong about parts.

It’s still confusing…is audio-chip connected to i2c1 or not? Do we have to pay attention to anything if we want to use i2c1 on gpio-header to not ran into issues depending on audio-chip?

audio chip is not found on the bpi-r2. so it shouldn’t cause any problem if you use i2c1.

but if you have the plan to have a future audio extension, it should be better to use i2c0.

the extension is via another board as the daughterboard I meant in last reply

ok, i see the code on garys github for bpi-r2 so i assumed that this audio-chip is existent on R2…

can you give advice which steps need to be done to get rtc running?

these are for rpi:

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

i think first line must be changed because the on R2 there is no BCM-Chip :wink: does it need a chip-specific driver or only i2c-dev?

here i’ve found a (german) tutorials how to search and access I2C-devices: https://frank-mankel.de/kategorien/10-bananapi/80-bananapi-i2c-bus http://www.netzmafia.de/skripten/hardware/RasPi/RasPi_I2C.html

found also a english tutorial for another RTC here: [BPI-M3] BPI RTC (DS3231) Module and how to use maybe it should work on r2 the same way, some debugging-infos: https://raspberrypi.stackexchange.com/questions/43821/cannot-perform-echo-command-to-load-driver-for-rtc-module/46634 http://forum.lemaker.org/thread-4276-1-1-my_humble_experience_with_rtc_and_bananapi.html

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: wm8960@1a {
		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] root@bpi-r2:~# ./rtc.sh                                                                                           
Fri 09 Mar 2018 08:32:15 PM CET  -0.559925 seconds                                                                        
[20:27] root@bpi-r2:~# date                                                                                               
Fri Mar  9 20:27:52 CET 2018                                                                                              
[20:27] root@bpi-r2:~# hwclock -s                                                                                         
[20:32] root@bpi-r2:~# 

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)