Jump to content
OzGrant

DS3231 RTC Library for 5529

Recommended Posts

Haven't tackled that yet on the '430 but I'm using that chip in an AVR/Arduino project in my wife's car - it's amazing and 100% true to its claim. Except it hasn't lost 1 minute in the past 3 years it's been there (exposed to temps ranging from 5F to 120F inside the trunk)

 

Sent from my Galaxy Note II with Tapatalk 4

Share this post


Link to post
Share on other sites

G'day Spirills,

 

Yup the DS3231 sure has lots of features, the one I'm proposing to use is the alarm interrupt, set to a define a period that will be used to initiate a new diatalog poll. But at this stage can't even get the device to be detected by my i2c scanner.

 

Anyway will keep plugging away.

 

Grant

 

 

Share this post


Link to post
Share on other sites

When compiling with  #include <DS3232RTC.h>  (  github.com/JChristensen/DS3232RTC) get a  the following error:

 

   ..\DS3232RTC.cpp:249:20: error: '_BV' was not declared in this scope

 

Where does energia pick up the code for the _BV macro??

 

I can probably replace the _BV with a coded left shift, but have seen the _BV used previously by Energia

Share this post


Link to post
Share on other sites

the _BV is a macro defined here http://www.atmel.com/webdoc/AVRLibcReferenceManual/group__avr__sfr_1ga11643f271076024c395a93800b3d9546.html. (I searched a solution during 3 hours)

I was having the same problem with this library, so I've added these lines:

#define _BV(bit) \
(1 << (bit)) 
in DS3231RTC.h and tcharam! it works.
 
I've to added time.h (It was found here http://www.pjrc.com/teensy/td_libs_Time.html)in /<User>/Documents/Energia/Libraries
 
I was setting to: Wire.begin();  and Wire.setModule(0); cause I'm used the SCL(0) and SDA(0) in my launchpad. References here: http://energia.nu/wordpress/wp-content/uploads/2014/01/tm4c123pinmap.png
 
I'm using Tiva C 123GXL.
 
This example works with me and I hope it works with you:
/*
 * TimeRTC.pde
 * Example code illustrating Time library with Real Time Clock.
 * This example is identical to the example provided with the Time Library,
 * only the #include statement has been changed to include the DS3232RTC library.
 */

#include <DS3232RTC.h>    //http://github.com/JChristensen/DS3232RTC
#include <Time.h>         //http://www.arduino.cc/playground/Code/Time  
#include <Wire.h>         //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)

void setup(void)
{
  Wire.begin();
  Wire.setModule(0);
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus() != timeSet) 
    Serial.println("Unable to sync with the RTC");
  else
    Serial.println("RTC has set the system time");      
}

void loop(void)
{
  digitalClockDisplay();  
  delay(1000);
}

void digitalClockDisplay(void)
{
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(' ');
  Serial.print(day());
  Serial.print(' ');
  Serial.print(month());
  Serial.print(' ');
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits)
{
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(':');
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

This library will be useful to me, because I need the alarm function to wake up the launch pad. 

Share this post


Link to post
Share on other sites

@@B@tto Typically an external RTC would be used for better accuracy and/or current consumption. The DS3231 is very accurate and although I haven't compared the specs between the 3231 and the native RTC in the 5529, I am guessing that the OP might be using it for better accuracy. Not sure how power consumption compares between the two.

Share this post


Link to post
Share on other sites

Hum, RTC_A his pretty accurate "as it". As you can measure internal temp and integrate correction directly in the peripheral, I guess you can be very accurate :)

Share this post


Link to post
Share on other sites

I had a chance to compare the two approaches only on accuracy and not power consumption.  On the power side I have in the past compared an internal RTC on an ARM3 CPU vs. a generic RTC and, IIRC, the generic RTC was about a tenth of the power consumption. Obviously this will vary based on CPU platform and the model of the external RTC.

 

With regard to accuracy, the commercial version of the DS3231 has a built in compensated crystal and is spec'd at +/-2ppm Max. over the entire 0-40C temp range. No adjustments or calibrations required. What I was curious about is if the 5529 internal RTC and compensation mechanism could rival that kind of accuracy.  I took a quick look at the ADC, temp sensor and internal reference specifications since the accuracy of the compensation mechanism would obviously be a limiting factor in the overall accuracy.  I didn't calculate total error but just looked at the non linearity of the ADC and the temp drift of the reference (50ppm/C).  I didn't find the non linearity of the temp sensor or its drift specs. The real issue with calibration actually was the granularity of the RTC compensation registers which had a step size of -2ppm or +4ppm and a minimum adjustment of -4ppm or +8ppm. 

 

Even with all that in mind, what fits that application is all that really matters. If one is periodically syncing to a NTP server (or WWV :D ) then using an external RTC is a waste of money.  

 

Perhaps @@spirilis can comment as he has used the DS3231 in a long term application and has first hand knowledge of the part. He likely did a far better job calculating the tradeoffs than I just did.

Share this post


Link to post
Share on other sites

As F5529 already has an RTC peripheral, what's the gain of using an external RTC ? 

...

Getting @@spirilis to send his wife over to make sure yours is calibrated?

He even said:

"... hasn't lost 1 minute in the past 3 years it's been there (exposed to temps ranging from 5F to 120F inside the trunk)"

Why he put her in the trunk and how she managed to measure things is another story though. :D

 

*edit- Just realized this doesn't make sense without some context.

Haven't tackled that yet on the '430 but I'm using that chip in an AVR/Arduino project in my wife's car - it's amazing and 100% true to its claim. Except it hasn't lost 1 minute in the past 3 years it's been there (exposed to temps ranging from 5F to 120F inside the trunk)

Share this post


Link to post
Share on other sites

I had a chance to compare the two approaches only on accuracy and not power consumption.  On the power side I have in the past compared an internal RTC on an ARM3 CPU vs. a generic RTC and, IIRC, the generic RTC was about a tenth of the power consumption. Obviously this will vary based on CPU platform and the model of the external RTC.

 

With regard to accuracy, the commercial version of the DS3231 has a built in compensated crystal and is spec'd at +/-2ppm Max. over the entire 0-40C temp range. No adjustments or calibrations required. What I was curious about is if the 5529 internal RTC and compensation mechanism could rival that kind of accuracy.  I took a quick look at the ADC, temp sensor and internal reference specifications since the accuracy of the compensation mechanism would obviously be a limiting factor in the overall accuracy.  I didn't calculate total error but just looked at the non linearity of the ADC and the temp drift of the reference (50ppm/C).  I didn't find the non linearity of the temp sensor or its drift specs. The real issue with calibration actually was the granularity of the RTC compensation registers which had a step size of -2ppm or +4ppm and a minimum adjustment of -4ppm or +8ppm. 

 

Even with all that in mind, what fits that application is all that really matters. If one is periodically syncing to a NTP server (or WWV :D ) then using an external RTC is a waste of money.  

 

Perhaps @@spirilis can comment as he has used the DS3231 in a long term application and has first hand knowledge of the part. He likely did a far better job calculating the tradeoffs than I just did.

I did no calculation of anything.... this was my first custom-board production Arduino-based project, it sounded good and I used it, no regards at all given to the power consumption or other alternatives :-D

 

It did end up working nicely though.

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...