Jump to content
grahamf72

[Energia Library] MSP430 Real Time Clock

Recommended Posts

Attached is my latest version of the Real Time Clock library, adapted from xv4y's original library.  Some significant changes in this version are:

  • Now works with both the MSP430G2553 and the MSP430G2452 processors (with some limitations on the 2452). The library may work on other processors, but I don't have any to test with.
  • Rewrite of the logic used to detect the number of days in a month and leap year detection so that it uses considerably less RAM.
  • Option to use the built-in VLO clock. The VLO is much less accurate than the crystal - about the best that can be achieved is accuracy to within a few minutes per day. The advantage of the VLO is that it frees up 2 IO pins, and can be used if you can't solder the tiny crystal to the launchpad. If you don't need a very accurate clock, or have a means of external synchronisation, the VLO may be sufficient for your needs.
  • The #define's that configure the settings of the timer have been moved to a separate RTCconfig.h file, so they are easier to edit without having to edit the main header file.
  • Documentation has been moved from the header file into a separate .txt file.
  • Some example files have been included in the library.

Known Limitations:

Because the MSP430G2452 only has one timer, the RTC library cannot be used in conjunction with other functions that also require the timer. This includes Serial, AnalogWrite, Tone, and possibly some others. Because the MSP430G2452 doesn't have hardware serial, this means that the RTC library and Serial are completely incompatible.

RTCplus.zip

Share this post


Link to post
Share on other sites

Updated version of the library attached. Main changes are:

  • Configuration option allows the Watch-Dog Timer to be used for the RTC instead of TimerA. This also requires replacements for the functions in wiring.c. A side effect caused by limitations of the 430 hardware is that delay, millis and micros only have a resolution of 1.9mS.
  • Added helper functions to convert the hmsDMY time into UnixTime format, return day-of-week, etc.
  • Added an alarm class.
  • Improved documentation.

RTCplus.zip

Share this post


Link to post
Share on other sites

works on msp430g2553, but on msp430g2452 I get:

 

core.a(TimerSerial.cpp.o): In function `TimerSerial__TxIsr':
energia-0101E0009/hardware/msp430/cores/msp430/TimerSerial.cpp:213: multiple definition of `__isr_9'
example_Serial_Clock.cpp.o:example_Serial_Clock.cpp:76: first defined here
collect2: ld returned 1 exit status

Share this post


Link to post
Share on other sites

works on msp430g2553, but on msp430g2452 I get:

 

core.a(TimerSerial.cpp.o): In function `TimerSerial__TxIsr':

energia-0101E0009/hardware/msp430/cores/msp430/TimerSerial.cpp:213: multiple definition of `__isr_9'

example_Serial_Clock.cpp.o:example_Serial_Clock.cpp:76: first defined here

collect2: ld returned 1 exit status

Because the 2452 only has one timer, you cannot use TimerSerial (the default serial library on the 2452) and the RTC if the RTC is configured to use TImer A (default). You can either reconfigure the RTC to use the Watchdog Timer (#RTCUSEWDT) or use one of the SoftwareSerial libraries.

 

In the comments at the top of the example files I list which chips the examples are tested with. The examples which will work with the 2452 are the 2 basic LCD clock examples. It would be a fairly basic exercise to modify the WDT LCD example to use serial output instead of the LCD, or to modify the serial clock example to use WDT instead of Timer A.

Share this post


Link to post
Share on other sites

I'm trying to simply turn on a LED after 10 seconds just to test a bit before actualy using a real clock.

 

Problem is it doesn't work.

I'm using the serial example with this void loop():

 

void loop()
{
   if (rtc.RTC_sec==10){
     digitalWrite(P1_6,HIGH);
   }
 }

Share this post


Link to post
Share on other sites

Hi LRA,

Is that your complete code?  The reason I ask is because if that's all you've done, it definitely won't work.

 

Firstly, the RTC library needs some configuration by editing the RTCconfig.h file - there are two modes it can operate in:

The 1st mode is TimerA mode - in this mode you have to provide a timer interrupt, declare a class-instance of type RealTimeClock, and declare an interrupt routine whose job it is to increment the RealTimeClock.

 

The 2nd mode is "WDT" mode. This is the easiest to use. The library creates a class instance called "rtc", and takes care of updating it in the background. WDT mode is enabled by editing RTCconfig.h and making sure the line #define RTCUSEWDT is not commented out.  The drawback of this mode, is that the library provides replacements for the Energia mills() and delay() functions, and due to hardware limitations their resolution is reduced to about 2 milliseconds.  

 

If you are using WDT mode, the following code will work fine - note that the loop() is the same as the example you posted, but there are requirements in setup() which if not put in will stop it working.  Firstly the pinMode sets the pin to be an output. The hardware defaults to all ports being inputs.  Then the pin is explicitly forced low. Without that step, it is indeterminate what state the pin will be in at reset.

#include <RTCplus.h>

void setup()
{
  pinMode(P1_6,OUTPUT);
  digitalWrite(P1_6,LOW);
}

void loop()
{
   if (rtc.RTC_sec==10){
     digitalWrite(P1_6,HIGH);
   } 
}

This code does work - after 10 seconds the LED turns on, and then stays on until the board is reset.

Share this post


Link to post
Share on other sites

I'm sorry it was kinda a late and i was just not working right. Without the full code is a bit hard to see everytingh.

 

I just downloaded the library and pasted it in the folder. My code is this:

#include <msp430.h>
#include <RTCplus.h>

RealTimeClock rtc; //initialise the global RealTimeClock instance

void setup()
{
  pinMode(P1_6,OUTPUT);
  digitalWrite(P1_6,LOW);
  rtc.begin();      //initialise the RTC
  
  rtc.Set_Time(23,56,0); //Set the time to 23:56
#ifdef RTCWITHDATE
  rtc.Set_Date(2013,2,28); //Set the date to 28 Feb 2013
#endif
 
};

void loop()
{
   if(rtc.RTC_sec==10){
     digitalWrite(P1_6,HIGH);
   }
   delay(1000);
 };


RTC_ISR(void) {
    rtc.Inc();              // Update chunks
 };

Share this post


Link to post
Share on other sites

Ok, so you are using the TimerA mode - in your RTCconfig.h is the line #define RTCUSEWDT commented out?

 

And it may be a dumb question, but do you have the 32.768kHz crystal soldered to your launchpad and has it been verified as working?

 

Try uncommenting the #defines in the VLO Clock section of RTCconfig.h - if it works using the VLO clock, then you could have a problem with your crystal.

Share this post


Link to post
Share on other sites

Ok, so you are using the TimerA mode - in your RTCconfig.h is the line #define RTCUSEWDT commented out?

 

And it may be a dumb question, but do you have the 32.768kHz crystal soldered to your launchpad and has it been verified as working?

 

Try uncommenting the #defines in the VLO Clock section of RTCconfig.h - if it works using the VLO clock, then you could have a problem with your crystal.

 

Doh! i tought it could use the internal oscilator. 

 

Well i don't have any crystal soldered 

Share this post


Link to post
Share on other sites

Without a crystal, the library can be configured to use the VLO clock, but accuracy is not real good. The best I could manage was to within a couple of minutes per day. If your needs don't need it to be very accurate, or can come up with a way of synchronising to a external time source (eg a PC by serial) then it will probably suffice. The reason I chose VLO is because it will still run in LPM3.

Share this post


Link to post
Share on other sites

Without a crystal, the library can be configured to use the VLO clock, but accuracy is not real good. The best I could manage was to within a couple of minutes per day. If your needs don't need it to be very accurate, or can come up with a way of synchronising to a external time source (eg a PC by serial) then it will probably suffice. The reason I chose VLO is because it will still run in LPM3.

For now i was just thinking just to set the clock everyday, like in 7h i want you to do this.

 

So when my actual alarm clock (phone) goes off more or less at the same time a blue LED turn on. I don't have any buzzer and stuff so i can't actualy make a full alarm clock. So 2min per day doesn't realy matter.

 

The idea it's that a sound alarm wakes you up, but it's anoying and you just turn it off. The blue led stays on even if you turn off the sound, it should not anoy to the point you press a specific button behind the clock. The blue light will stop your production off sleeping hormones and help you wake up

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...