Use DS3231 RTC with BBB

Hi,

I’m connecting a DS3231 RTC from AdaFruit but am following the instructions for the 1307:
https://learn.adafruit.com/adding-a-real-time-clock-to-beaglebone-black?view=all

Should I follow these connections except connect the Vcc to the BBB P9-3 VDD_3V3B instead of P9-5 VCC_5V ?

Thanks,
David

Which adafruit module?

Regards,

Adafruit DS3231 Precision RTC Breakout

[

Adafruit DS3231 Precision RTC Breakout

The datasheet for the DS3231 explains that this part is an “Extremely Accurate I²C-Integrated RTC/TCXO/Crystal”…

](https://www.adafruit.com/product/3013)

Thanks,
David

Okay, that one is safe to be plugged into v3.3

Then setup a U-Boot overlay like:

https://github.com/beagleboard/bb.org-overlays/blob/master/src/arm/BB-I2C2-RTC-DS1338.dts

But with the correct port, and device name…

Then you’ll get it bootup as rtc0 and everything date/ntp/etc will just work, without any other special scripts…

Regards,

I’m using the Adafruit RTC module that uses the DS3231 as well and had it working with a Beaglebone Black Wireless around a year ago, but it’s been on the shelf until yesterday. I had expected to bring it out, hook it up, and get back to using it, but it’s not being seen on I2C2 at address 0x68 using i2cdetect. And the code that worked isn’t working now. Something has changed, but I’ve not changed the code and double-checked my connections. Power is P9_4, ground is P9-2, SDA is P9_20 and SCL is P9_19. I’ve double-checked these connections with an ohmmeter back to the actual chip pins. The dts I am using is listed below. When I look through this, it seems this RTC should become rtc0 once the overlay loads. Am I reading this correctly? I’ve ordered a second module in case this one has bitten the dust while in storage. The battery reads 3V and change so I think that’s good.

Version.sh output follows the dts listing

/*
 * Copyright (C) 2019 Tomas Arturo Herrera Castro <taherrera@uc.cl>
 *
 * Based on BB-I2C2-RTC-DS1338.dts:
 *
 * Copyright (C) 2018 Tim Small <tim@seoss.co.uk>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This was code was writen by Chilean Software and Hardware developer
 * company Southern Lake Technologies for a custom-made datalogger.
 *
 * http://www.sltech.cl
 *
 * compiled using: dtc -O dtb -o BB-I2C2-RTC-DS3231.dtbo -b 0 -@ BB-I2C2-RTC-DS3231.dts
 *
 * tested on element14 BeagleBone Industrial
 *
 */

/dts-v1/;
/plugin/;

/{
        compatible = "ti,beaglebone", "ti,beaglebone-black", "ti,beaglebone-green";

        /* identification */
        part-number = "BB-DS3231";
        version = "00A0";

        #address-cells = <1>;
        #size-cells = <0>;   

        /*
         * Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
         */
        fragment@0 {
                target-path="/";
                __overlay__ {

                        chosen {
                                overlays {
                                       BB-I2C2-RTC-DS3231 = __TIMESTAMP__;
                                }; 
                        };
                };
        };

        fragment@1 {
                target-path="/";
                __overlay__ {
                        aliases {
                                rtc0 = &extrtc;
                                /* The OMAP RTC implementation in the BBB is
                                 * buggy, so that it cannot be used as a
                                 * battery-backed RTS, so that it loses its
                                 * contents when power is removed from the
                                 * Beaglebone...
                                 *
                                 * We move the omap built-in RTC to rtc1, so
                                 * that userspace defaults to using the DS1338.
                                 *
                                 * The omap RTC must remain enabled because it
                                 * is also used during the reboot process on the
                                 * BBB.
                                 */
                                rtc1 = "/ocp/rtc@44e3e000";
                        };
                };
        };

        fragment@2 {
                target = <&i2c2>;
                __overlay__ {
                        status = "okay";
                        #address-cells = <1>;
                        #size-cells = <0>;

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

Output of version.h

git:/opt/scripts/:[b39ec679648a6be8f25f48bd1c9784c1fc5a0c46]
eeprom:[A335BNLTBWA51824BBWG0524]
model:[TI_AM335x_BeagleBone_Black_Wireless]
dogtag:[BeagleBoard.org Debian Buster IoT Image 2020-04-06]
bootloader:[eMMC-(default)]:[/dev/mmcblk1]:[U-Boot 2019.04-00002-g07d5700e21]:[location: dd MBR]
UBOOT: Booted Device-Tree:[am335x-boneblack-uboot-univ.dts]
UBOOT: Loaded Overlay:[AM335X-PRU-RPROC-4-19-TI-00A0]
UBOOT: Loaded Overlay:[BB-ADC-00A0]
UBOOT: Loaded Overlay:[BB-BBBW-WL1835-00A0]
UBOOT: Loaded Overlay:[BB-BONE-eMMC1-01-00A0]
UBOOT: Loaded Overlay:[BB-HDMI-TDA998x-00A0]
UBOOT: Loaded Overlay:[BB-I2C2-RTC-DS3231]
UBOOT: Loaded Overlay:[BB-W1-P9.12-00A2]
kernel:[4.19.94-ti-r42]
nodejs:[v10.15.2]
/boot/uEnv.txt Settings:
uboot_overlay_options:[enable_uboot_overlays=1]
uboot_overlay_options:[uboot_overlay_addr4=/lib/firmware/BB-W1-P9.12-00A0.dtbo]
uboot_overlay_options:[uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-19-TI-00A0.dtbo]
uboot_overlay_options:[enable_uboot_cape_universal=1]
uboot_overlay_options:[dtb_overlay=/lib/firmware/BB-I2C2-RTC-DS3231.dtbo]
pkg check: to individually upgrade run: [sudo apt install --only-upgrade <pkg>]
pkg:[bb-cape-overlays]:[4.14.20200403.0-0rcnee0~buster+20200403]
pkg:[bb-wl18xx-firmware]:[1.20200322.0-0rcnee0~buster+20200322]
pkg:[kmod]:[26-1]
pkg:[librobotcontrol]:[1.0.4-git20190227.1-0rcnee0~buster+20190327]
pkg:[firmware-ti-connectivity]:[20190717-2rcnee1~buster+20200305]
groups:[debian : debian adm kmem dialout cdrom floppy audio dip video plugdev users systemd-journal bluetooth netdev i2c gpio pwm eqep remoteproc admin spi iio docker tisdk weston-launch xenomai cloud9ide]
cmdline:[console=ttyO0,115200n8 bone_capemgr.uboot_capemgr_enabled=1 root=/dev/mmcblk1p1 ro rootfstype=ext4 rootwait coherent_pool=1M net.ifnames=0 lpj=1990656 rng_core.default_quality=100 quiet]
dmesg | grep remote
[   11.181690] remoteproc remoteproc0: 4a334000.pru is available
[   11.201529] remoteproc remoteproc1: 4a338000.pru is available
[   65.032537] remoteproc remoteproc2: wkup_m3 is available
[   65.606501] remoteproc remoteproc2: powering up wkup_m3
[   65.606536] remoteproc remoteproc2: Booting fw image am335x-pm-firmware.elf, size 217168
[   65.606831] remoteproc remoteproc2: remote processor wkup_m3 is now up
dmesg | grep pru
[   11.181690] remoteproc remoteproc0: 4a334000.pru is available
[   11.181874] pru-rproc 4a334000.pru: PRU rproc node pru@4a334000 probed successfully
[   11.201529] remoteproc remoteproc1: 4a338000.pru is available
[   11.201717] pru-rproc 4a338000.pru: PRU rproc node pru@4a338000 probed successfully
dmesg | grep pinctrl-single
[    0.930296] pinctrl-single 44e10800.pinmux: 142 pins, size 568
dmesg | grep gpio-of-helper
[    0.943564] gpio-of-helper ocp:cape-universal: ready
lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

yeah it should, what does:

dmesg | grep rtc

and

dmesg | grep ds3

Regards,

dmesg | grep rtc output

debian@beaglebone:/var/lib/cloud9$ dmesg |grep rtc
[    1.347129] rtc-ds1307 2-0068: SET TIME!
[    1.349698] rtc-ds1307 2-0068: registered as rtc0
[    1.353020] omap_rtc 44e3e000.rtc: registered as rtc1
[    1.642717] [drm] Cannot find any crtc or sizes
[    1.672588] rtc-ds1307 2-0068: setting system clock to 2000-01-01 00:56:42 UTC (946688202)
[    2.664185] [drm] Cannot find any crtc or sizes
[   58.182319] PM: bootloader does not support rtc-only!

dmesg | grep ds3 did not output anything

It’s working correctly, set as rtc0…

I forget the command, but systemd-timesync should properly set the Time eventually if you just let it idle…

edit: maybe:

sudo hwclock -w

Regards,

Got it. Thank you!

I was trying to work with it as an I2C device using C and not finding the device. I could swear the code used to work, so I don’t know what’s wrong. Could it be that the overlay takes over the RTC, so it doesn’t show up as an I2C device anymore? That would be just fine with me - better really.

This is normal, by using the overlay, the kernel has full control over the device, so in i2c-tools it should show up as “UU”…

Regards,

I’m used to seeing UU and have that at address 0x50. But the clock is at 0x68 and there’s nothing there. I even ran the tools on all three buses just to be sure I wasn’t mistaking the bus it’s connected to.