SARPi Project - Slacking on a Raspberry Pi


Install a DS3234 Real Time Clock on a Raspberry Pi running Slackware ARM

This SARPi mini-project will enable you to connect and install a DS3234 real time clock (RTC) with Slackware ARM using the SPI interface on a Raspberry Pi. There are many reasons why connecting a real time clock to the Raspberry Pi is prudent and beneficial, as the device doesn't come with a RTC installed as standard. So we thought it would be interesting, as well as educational and fun, to give our Slackware ARM system on a Raspberry Pi its own real time clock. In this mini-project we'll be installing a Ks0166 keyestudio DS3234 high precision real time clock module.

SARPi Project muse views ... This mini-project covers how to install a DS3234 RTC using the SPI interface. The most common RTC modules, such as the DS1307, DS3231, PCF8563, RV3028, (etc.) use the I2C interface. The only real difference between these interfaces are the methods used to communicate. SPI is generally quicker than I2C but requires more GPIO pin connections. For a real time clock, access speed shouldn't be an issue whatsoever. Therefore, the most suitable RTC that should be used always depends on requirements and/or personal preference.

For quick reference within this DS3234 RTC guide:
Required elements for this mini-project
Connecting the DS3234 RTC to a Raspberry Pi
Configuring Slackware ARM to use the DS3234 RTC on a Raspberry Pi
Manually setting the DS3234 RTC to the correct time & date

What you will need for this mini-project

• A Raspberry Pi with a 40-pin GPIO header running Slackware Linux.
• A DS3234-based RTC module, such as the Ks0166 keyestudio DS3234 or SparkFun DeadOn RTC Breakout - DS3234.
Suitable cables to connect the DS3234 RTC to your RPi (as required).

Connecting the DS3234 RTC to a Raspberry Pi

A total of 6 [six] connections are required. Refer to the illustration below and ensure the connections are correct. Full details of the Raspberry Pi general-purpose input/output pins can be found on the Raspberry Pi GPIO documentation page, should you need them.

SARPi Project muse views ... IMPORTANT! : Connect all the DS3234 RTC pins WITHOUT the Raspberry Pi powered on! Ensure everything is powered OFF to avoid any mishaps and/or damage during the wiring connection process!

DS3234 RTC wiring connections to Raspberry Pi GPIORaspberry Pi GPIO 40-pin header

Once the DS3234 has been connected to the Raspberry Pi and all wired pin connections have been checked and verified, insert the CR1225 battery into the DS3234 battery holder and make sure the polarity is correct.

Now it's safe to power on the Raspberry Pi and boot into the Slackware ARM operating system.

Configuring Slackware ARM to use the DS3234 RTC on a Raspberry Pi

In order for the kernel to know that there's a DS3234 RTC connected to the system, and what to do with it, at boot time, a 'dtoverlay' entry needs to be specified in the '/boot/config.txt' file. This is easily achieved using a text editor. Here we'll use 'nano', like this:

root@slackware:~# nano /boot/config.txt

If the following line within the '/boot/config.txt' file has a hash '#' in front of it - e.g. it looks like this: #dtparam=spi=on - remove the hash '#' to enable the SPI interface:

dtparam=spi=on

Somewhere within the '/boot/config.txt' file, enter the following line to load the DS3234 RTC Device Tree overlay at boot time. It can be put anywhere as long as it is on a line on its own.

dtoverlay=spi-rtc,ds3234

Save and exit the '/boot./config.txt' file, and then reboot the system...

After rebooting, check the RTC has been detected on the system and works as expected.

root@slackware:~# dmesg | grep rtc
root@slackware:~# dmesg | grep ds3234
root@slackware:~# hwclock -r

SARPi Project muse views ... NB: If you receive an error when querying the RTC with 'hwclock -r' then remember to set the time correctly on the RTC initially! See: Setting the RTC to the correct time & date section below.

The following screenshot shows the output of these commands:

DS3234 dmesg rtc | hwclock -r

This confirms that the DS3234 RTC is working as expected.

Please note that the output format of RTCs can differ, even when using the same [DS3234] controller. As long as you see the date and time that's expected it's all good.

Setting the RTC to the correct time & date

If the DS3234 RTC has not already been set to the correct time (e.g. if this is the first time it's been configured on the system) then you might need to do this initially. This can be achieved in two ways: manually using the 'date' command, or by utilising a NTP server on the Internet with the 'sntp -sS' or 'ntpdate' command. NTP servers are preferred for accuracy reasons alone if an Internet connection is available.

Either of the following methods will enable you to set the date/time on the DS3234 RTC. Or most other RTCs in fact.

• Set the time and date on the DS3234 RTC manually by using the following command (pay attention to the date format):

root@myrasbox:/tmp# date MMDDHHmmYYYY && hwclock -w

The month (MM), day (DD), hour (HH), and minute (mm) values are always specified in 2 digits and have a leading zero '0' when applicable. The time is always specified as the 24 hour clock. The year (YYYY) value is always specified by 4 digits.
Example: if the time is 9:17pm on September 11, 2016 then the command would be as follows:

root@myrasbox:/tmp# date 091121172016 && hwclock -w

SARPi Project muse views ... In our example above the 'date 091121172016' command sets the time and date on our Slackware Linux system and the 'hwclock -w' command which follows then writes that date and time to the hardware clock (the DS3234 RTC).

• Set the time and date on the RTC using a NTP server with either of the following commands:

root@myrasbox:/tmp# sntp -sS pool.ntp.org && hwclock -w
root@myrasbox:/tmp# ntpdate pool.ntp.org && hwclock -w

SARPi Project muse views ... The 'sntp' and 'ntpdate' commands grab the current date and time from a NTP server (from pool.ntp.org in this example) and writes it to our Slackware Linux system. The 'hwclock -w' command which follows then writes that date and time to the hardware clock (the DS3234 RTC). The NTP server you use does not have to be the same one as in our example. There are literally hundreds of NTP servers located around the world that can be called on for this task.

NB: The 'sntp -sS' and/or 'ntpdate' command(s) can be used at any time (as 'root' user) to set the time & date on the system.

The following screenshot shows the output of these commands:

DS3234 sntp | ntpdate

The "Cannot open KoD db file /var/db/ntp-kod: No such file or directory" error can be ignored when using the 'sntp' command. The command output shows that it's successfully set the date/time accurately. When the DS3234 RTC has been detected and is working on the system, the 'hwclock -w' command option will always write the current system time to it.

Useful tip: see the 'man hwclock' documentation on your Slackware Linux system for more details on how to use the time clocks utility.

Thanks!

Thank you for reading and taking part in this SARPi mini-project. We hope you enjoyed it and found it interesting and educational.

Thanks to Phil Elwell at Raspberry Pi Ltd. for adding the DS3234 SPI RTC in the Raspberry Pi kernel Device Tree overlays after initially suggesting that it should be added as a standard overlay. Kudos and thanks to Nigel Bajema for his "Raspberry PI and your SPI Real Time Clock (RTC)" Science Gizmo (AU) blog that laid down the groundwork for the DS3234 RTC on the Raspberry Pi 2 in 2015.

Thanks also to Patrick Volkerding, and the entire Slackware Team, for producing a truly wonderful OS. Without you, and the work you do, the SARPi Project would not exist.

If you have any questions or need help, visit the Slackware Linux Forum on Linux Questions. Or get in touch on the #SARPi IRC channel on irc.libera.chat.

Back to Top


Updated: 2024-03-16 07:35:46 UTC

Disclaimer: The SARPi Project website is for non-commercial and general information purposes only. The content is provided by Penthux.NET and while we endeavour to keep information up to date and correct, we make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the website or any information, software, products, services, or related graphics which is available on the website for any purpose. Any reliance you place on such information is therefore strictly at your own risk. In no event will Penthux.NET be liable for any loss or damage including without limitation, indirect or consequential loss or damage, or any loss or damage whatsoever arising from loss of data or profits arising out of, or in connection with, the use of this website or any of its contents. Through this website you are able to visit other websites which are not under our control. Penthux.NET has no influence over the nature, content or availability of any external URLs. The inclusion of any URLs does not necessarily imply a recommendation or endorsement of any content therein. Every effort is made to ensure the SARPi Project website remains accessible. However, Penthux.NET takes no responsibility for, and will not be liable for, the SARPi Project website being temporarily unavailable due to technical issues beyond our control. SARPi Project is in no way affiliated with Slackware Linux, Inc, or the Linux Foundation, or Raspberry Pi Ltd., or any of their respective members, trustees, partners, or associates.


Accept!

SARPi Project uses cookies for website traffic data analytics purposes only. Cookies from this website do not collect or store any of your personal data.

Please read the SARPi Project website [ Cookie Policy ] for more details.