DS3234 Software SPI Library

While trying to get the DS3234 work together with SD card on the ethernet shield, I have faced a problem. SD uses Mode0 of the SPI while DS3234 needs either Mode1 or Mode3. To get around the problem with a single hardware SPI on Arduio boards, I have decided to try to develop a software SPI interface for the real time clock. The library is fully functional and it allows to do the basic reading and setting the date and time, as well as it allows to read the temperature value from the temperature sensor built in the DS3234. Alarms functionality is not yet added but it will be availeble soon. I have tested the library with Arduino Duemilianowe and Mega 2560 and it works flawlessly together with ethernet shield and SD card reader.

The library can be downloaded from here.

After downloading simply unzip the library to the library folder of your arduino installation (by default it is in C:\arduino-1.0.3\libraries on windows machines).

To use the library you need to include it by placing the following line at the begining of your sketch:

  • #include <DS3234.h>

Before you use the functions to read/set time or read the temperatre, you need to tell the library to which pins you have connected the RTC. To do that simply use:

  • RTC.configure(MOSIpin,MISOpin,CLKpin,CSpin)

where the CLKpin is often called clock pin or SCK. CSpin might be marked on the board as SS. If for any reason the pin assignemnt would change during execution of the program, you may change the pin assignment by using the function at any time. However in probably all the cases you want to use this function only once in the setup part of the program. When the library is initialized you can use the following functions:

  • RTC.readDateTime() - this functions returns this function returns string which is the date and time in a format DD.MM.YYYY-hh.mm.ss

after using this function, the indyvidual value are stored in internal variables which you can also read as integers using the functions:

  • RTC.time_h() - returns the hour
  • RTC.time_m() - returns the minutes
  • RTC.time_s() - returns the seconds
  • RTC.date_d() - returns the day
  • RTC.date_m() - returns the month
  • RTC.date_y() - returns the year

Note that to update the results of the above functions you need to call the readDateTime(), otherwise you will only read the values saved by the last usage of readDateTime().

  • RTC.setDateTime(int d, int mo, int y, int h, int mi, int s); - this funtion allows you to set the date and time, input the year as four or two digits, the year will anyhow be interpreted as 20XX.
  • RTC.readTemp(); - this function returns string with the temperature with two decimal places. Dot is used as decimal separator.

Example sketch:

#include <DS3234.h>

void setup()




void loop()


Serial.println(String("Current date/time: ")+RTC.readDateTime());