Adafruit's RTC

Started by felipegn, May 22, 2014, 11:59:33 PM

Previous topic - Next topic

felipegn

Hello.

I would like to know if someone has tested the Adafruit's RTC in A20-OlinuXino-MICRO.

It detects the RTC (in i2c-0 in address 0x68) but i can't collect the date from it.
hwclock -r -f /dev/rtc0 gives me "select() to /dev/rtc0 to wait for clock tick timed out: Success" but it doesn't show the date.

Can someone help me?

Thank you.

bubi

Hello felipegn,
I bought the same chip (DS1307) yesterday, but I'm accessing to it directly using the i2c-tools (http://linux-sunxi.org/I2Cdev, some documentation here http://www.lm-sensors.org/wiki/i2cToolsDocumentation).
With this tool it works (you only need to know the RTC internal addresses, see the datasheet http://datasheets.maximintegrated.com/en/ds/DS1307.pdf).

Just a question, what voltage are you providing to the chip? DS1307 runs at 5V, at 3.3V it doesn't work properly. I also use a level shifter to interface it with the olinuxino.

Regards 

felipegn

Hello bubi, thanks for your response.

I will try to use this documentation you posted

I'm using 5 V to power the chip without resistors (so the i2c voltage level is 3.3 V).

Regards

dave-at-axon

I don't use the DS1307 but instead use the DS1338 which is 3.3V powered and is pin and software compatible.

Which OS are you using?

I am running Android and I had to build the Android Linux kernel to support the RTC and make sure I included the initialisation for it as I2C devices are not automatically probed.

Although the DC characteristics for the DS1307 show a high as 2.2V I've often found that trying to get 5V devices running on 5V power to work with 3.3V inputs and outputs can be troublesome. Better if you can add a level shifter. I saw this very recently with an RS485 bus device. The device was 5V powered and I tried to send data. I got garbage. Added the level shifter and I now have clean data.

herter

Hello,

In addition of this voltage issue, did you connect the resistors named Rpu in the datasheet?
Moreover can you visualize the SDA signal with a scope for instance?

bubi

Hi,

the pull-up resistors (Rpu) for the i2c are already present in the olinuxino, since they are also present in the adafruit rtc breakout (that is working at 5V) a conflict may occur.
I suggest you to remove the pull-up from the adafruit breakout and use a level shifter for avoid any damage to the olinuxino pins (that are NOT 5V tolerant)

Regards

herter

Yes, I know, that's why I would like to know if the Rpu have been removed.

bubi

I didn't understand that we meant the same thing, sorry

felipegn

Hello guys.

- I use Debian as OS
- I removed both resistors from Adafruit's RTC

I connect the olinuxino's pins to rtc's pins, and then I run the modified MOD-RTC's example.
I had to change the adress, the start buffer, etc... because it changes from one rtc to another.

It's strange because I get the correct hour, minute and second, but when it comes to month day, week day and year it's wrong. Besides, it gets delayed very fast from the current time.

Sometimes I wonder if the i2c gets the clock of the processor or somewhere else.

Thank you for your responses.

ylsantos

I am trying to make it work too, but with no success. I am using Debian as OS (the 5th image if I am not mistaken) and a different approach than yours.

First I tried to follow Adafruit's recommendations to raspberry pi with eventual modifications. It didn't work.

Then I started to look for drivers or something related to that. Besides, I looked for the config file of the system (which was supposed to be in /boot, wasn't it?). The /boot directory is empty, and I made a deep research for files with 'config', 'debconfig', 'defconfig' and other terms in their names. But I didn't find anything. Does anyone know where the configuration file is?

This file contains every function that is enabled or not. My intention is to see if the RTC lines are ok. It is something like that: CONFIG_RTC=y. And maybe enable the RTC DS1307 driver in this file (same structure than CONFIG).

As an example, I am posting below some parts of the config file of my server (Ubuntu).

/boot/config-3.2.0-48-generic

CONFIG_RTC_LIB=y
CONFIG_RTC_CLASS=y
CONFIG_RTC_HCTOSYS=y
CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
# CONFIG_RTC_DEBUG is not set

#
# RTC interfaces
#
CONFIG_RTC_INTF_SYSFS=y
CONFIG_RTC_INTF_PROC=y
CONFIG_RTC_INTF_DEV=y
# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
# CONFIG_RTC_DRV_TEST is not set

#
# I2C RTC drivers
#
CONFIG_RTC_DRV_88PM860X=m
CONFIG_RTC_DRV_DS1307=m
CONFIG_RTC_DRV_DS1374=m
CONFIG_RTC_DRV_DS1672=m
CONFIG_RTC_DRV_DS3232=m
CONFIG_RTC_DRV_MAX6900=m
CONFIG_RTC_DRV_MAX8925=m
CONFIG_RTC_DRV_MAX8998=m
CONFIG_RTC_DRV_RS5C372=m
CONFIG_RTC_DRV_ISL1208=m
CONFIG_RTC_DRV_ISL12022=m
CONFIG_RTC_DRV_X1205=m
CONFIG_RTC_DRV_PCF8563=m
CONFIG_RTC_DRV_PCF8583=m
CONFIG_RTC_DRV_M41T80=m
CONFIG_RTC_DRV_M41T80_WDT=y
CONFIG_RTC_DRV_BQ32K=m
CONFIG_RTC_DRV_S35390A=m
CONFIG_RTC_DRV_FM3130=m
CONFIG_RTC_DRV_RX8581=m
CONFIG_RTC_DRV_RX8025=m
CONFIG_RTC_DRV_EM3027=m
CONFIG_RTC_DRV_RV3029C2=m

Is my reasoning correct?

dave-at-axon

I wonder if this information would help you get it working? Assuming you are building your own kernel.

I used the DS1338 which is a 3.3V and more accurate and code compatible version of the DS1307. The DS1307 drifts like hell with temperature changes. I've found the DS1338 to be a lot more accurate in time keeping. I still sync to an external time server if there is an internet connection just to keep it more accurate. :)

https://axonjakarta.wordpress.com/2014/03/31/external-battery-backed-real-time-clock-rtc-for-a20-with-android/

This is for Android Linux but it should be the same for any linux as I2C devices are not probed so you need to add them so that the kernel knows about them.

With this I now have a battery backed real time clock on the A20.

bubi

Hi,

I tryed the tutorial by adafruit for the raspberry and it works:
https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-rtc-time

But I want the RTC is registered at boot-up

@dave-at-axon

I'm trying to follow what you suggest to do. I also found some documentation (https://www.kernel.org/doc/Documentation/i2c/instantiating-devices) and a tutorial for raspberry (http://microeletroniki.wordpress.com/2012/09/05/ds1307-with-rpi-kernel-on-bootup/)

But I'm still trying to understand what file I have to modify for the A20 (I'm on debian, kernel 3.4.79)

Under arch/arm/mach-sun7i there isn't a file containing info about board (just a core.h).
In arch/arm/plat-sunxi there is a core.c that's seems to be the right file, but it doesn't contain any i2c setup.

I'm googling to find a solution but with no result...

Thanks in advance for any suggestions

Regards

dave-at-axon

Yeah, I found that the sunxi kernel uses a different naming convention to other kernels. The touch screen I added references a boardxxxx.c file and I could not find it. The core.c file was the only one that I found that had the init code I was looking for. I don't have the Debian source so can't comment on the internals but with my core.c file there was no I2C in there to begin with.

The file layout structure is probably different but it sounds like you found the right core.c file.

If it has the following at the bottom or very similar, this is the place to put the I2C header and init calls.


ACHINE_START(SUN7I, "sun7i")
.atag_offset = 0x100,
.fixup = sun7i_fixup,
.reserve        = sun7i_reserve,
.map_io = sun7i_map_io,
.init_early = sun7i_init_early,
.init_irq = gic_init_irq,
.timer = &sun7i_timer,
.handle_irq = gic_handle_irq,
.init_machine = sun7i_init,
#ifdef CONFIG_ZONE_DMA
.dma_zone_size = SZ_256M,
#endif
.restart = sun7i_restart,
MACHINE_END


It should also have a function similar to void __init sun7i_init_early(void)

If not sure, post it here or try as an attachment and I can have a quick look.

ylsantos

Hi guys, thanks for your support.

@bubi
I tried the tutorial too. It worked, but not everything went well. For instance, I got an error message when modprobe rtc-ds1307, indicating that this device is unknown, even declaring it as the tutorial says. Besides, it stops working when the board is powered off and then up again (the information is lost). And I believe that the hwclock is not DS1307, because I am using RTC with the function MOD_RTC and the times of both are different. hwclock is showing a big delay too...

@dave-at-axon and @bubi
I didn't find the config file neither. Nor the core.c. There is not a directory /arch or /arm here...

If I want to syncronize the time from RTC since boot, the only way is to rebuild the kernel or can I modify a file to do it? When there is no Internet connection, the system starts at 00:00:00 of 01/01/2010. Changing it to RTC's data may solve the problem. Is that possible?

Thanks!!

dave-at-axon

Can you drop a link here where I can find the Debian source and I'll have a dig around it. Sorry, I work with Android so more familiar with that.