0

Trying to get an RTC to load at boot. I've enabled i2c, that works fine for other components.

/etc/modules contains:

snd-bcm2835
i2c-bcm2835
i2c-dev 
rtc-ds3231

/etc/rc.local contains:

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

i2cdetect -y 1 shows UU in the 68 slot

I can set the date using hwclock with -r, '-w', and -s successfully

if I reboot, I get from hwclock -r

hwclock: The Hardware Clock registers contain values that are either invalid (e.g. 50th day of month) or beyond the range we can handle (e.g. Year 2095).

I can then write, read and sync with it again fine.

Any suggestions?! I've tried replacing the RTC module, but the same thing happens. Same if I remove the battery from the RTC.

If I remove the battery, the first time I boot it will show the date in the year 2000, but after that it'll go back to the error.

1

The answers involving modprobe and removing fake hwclock are not needed for Stretch era Rasbian and beyond. Here's the steps that work for me as a reference:

  1. Install tools:

    sudo apt-get install -y i2c-tools   
    sudo apt-get install -y python-smbus
    
  2. Update /boot/config.txt (Note: you can turn I2C 'on' via sudo raspi-config, but you need the overlay too to properly load the driver).

    sudo sh -c "echo dtoverlay=i2c-rtc,ds3231 >> /boot/config.txt"
    sudo sh -c "echo dparam=i2c_arm=on >> /boot/config.txt"
    
  3. Update /lib/udev/hwclock-set file (sudo nano /lib/udev/hwclock-set) and "comment out" the following lines ("comment out" means put a # at the beginning of each of the lines, so they become comments and are ignored by the system). They should like like:

    # if [ -e /run/systemd/system ] ; then
    # exit 0
    # fi
    
  4. Reboot system

    sudo reboot
    
  5. Review I2C is working, and get current timestamp from RTC:

    sudo i2cdetect -y 1 # will show 68 if I2C is on, but UU if overlay is actually active.
    sudo hwclock -r
    
  6. Review and update reading from hw clock.

    sudo hwclock -D -r
    date # Get latest date from internet 
    sudo hwclock -w # write that date to HW clock
    sudo hwclock -r # read the value of hw clock again
    

References: https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-rtc-time https://www.raspberrypi.org/forums/viewtopic.php?t=161133

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.