DS1307 real-time clock on the MSP430 Launchpad with Energia

Note: This article is a blurb. Help expand it.



The following procedure will show you how to set up your launchpad with Energia and should work for both the MSP-430F5529 and the MSP-430G2553.

Where to Get Parts

The parts in this tutorial can be acquired:



I will be using the DS1307 chip + breakout board from Adafruit.

Breakout-Board Assembly

The MSP430 systems operate on 3.3 Volt logic, and Arduino-based systems use 5V logic. The original Adafruit break-our board is made for 5 Volt logic, but can be modified to work with 3.3Volt logic, by omitting the 2.2kΩ pull-up resistors that come with the kit. Solder the pins, the DS1307 IC, the capacitor and the crystal. When the board is fully assembled, it should look like:


The F5529 board uses the P3.0 (SDA0) and P3.1 (SCL) pins for I2C communication. For more information, see the F5529 board pinout here.

Connect the Launchpad and the RTC breakout board according to the following diagram:

The RTC is powered by the 5 volt line. The SQW pin is not connected in this tutorial, but can be used to receive a square wave output at varying frequencies. The SDA and the SCA pins are connected through a 1.8 kΩ pull-up resistor each to the P3.0 and P3.1 pins, respectively.


Energia Installation

  1. Download the latest Energia version from here(in my case I used the Windows Binary release).
  2. Extract the .zip file into a working folder.

RTC Library Installation

  1. Download the elpaso RTC Library from github. There are many others out there, but this one worked for me.
  2. Extract the .zip file into the /Energia/libraries/RTCLib folder.
  3. Restart Energia to make sure that the libraries are loaded. You can check if a library is set up, by clicking on Sketch->Import Library...->RTCLib, which will add the line #include <RTClib.h> to your sketch.

Sketch Creation

Copy and paste the following sketch into Energia. The code will show you the current time and a time 7 days and 30 seconds into the future to ensure that the math works.

#include <Wire.h>
#include <RTClib.h>

void setup () {

// following line sets the RTC to the date & time this sketch was compiled
//RTC.adjust(DateTime(__DATE__, __TIME__));

void loop () {
DateTime now =;
Serial.print(now.year(), DEC);
Serial.print(now.month(), DEC);
Serial.print(, DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(now.minute(), DEC);
Serial.print(now.second(), DEC);
Serial.print(" since 2000 = ");
Serial.print("s = ");
Serial.print(now.get() / 86400L);
// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now.get() + 7 * 86400L + 30);
Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print(future.month(), DEC);
Serial.print(, DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(future.minute(), DEC);
Serial.print(future.second(), DEC);

Uploading Sketch

The first time you try to read data from the RTC (or after the battery has been removed for more than 3 seconds) you should see the date of 2000/01/01 and it will not change. This happens after evry reset. You must first set the date before it starts to work.

The line RTC.adjust() is currently commented out. This line sets the time of the RTC to the current computer time, so make sure that the computer time is correct. Once you run the code, you will see the time change every 3 seconds.

Important: Make sure to comment out the RTC.adjust() line and uploading the sketch before removing power to the RTC. Otherwise, the time will be reset every time the RTC gets power to whatever time the code was generated

The Serial Monitor output can be accessed by pressing [Ctrl]+[Shift]+[M] and should show something like this:


In this tutorial you were shown how to interface the DS1307 with the MSP430F5529 board.