Real time clock not always working

Hi guys

I'm having trouble with the real time clock in my Industrino D21 G.

When starting up the device I'm getting three variations of the time:

1) The real time that I have already initialized 

2) 2000.1.30-20.14.00

3) 2165.45.45-45:85:85

 

What could be the reason for this behavior?

Are there available some functions that update the time using the cellular system?

Thank you!

 

How I'm using the library:

#include <MCP7940.h>

Setup:

RTCind.get(rtc,true); 

RTCind.start(true);

Updating the time:

RTCind.get(rtc,true);

Using the current time:

String time = String(rtc[6])+"."+String(rtc[5])+"."+String(rtc[4])+"-"+String(rtc[2])+":"+String(rtc[1])+":"+String(rtc[0])+......

 

Bjorgvin
Bjorgvin
7
| 0 0 0
Asked on 1/11/18, 7:53 PM
0
vote
240 Views

 

These two functions work well for me 

// ---------------------------------------------------------------------------
void rtcInit()
// ---------------------------------------------------------------------------

// get TOD from RTC and set system time - requires time library
  int rtc[7];
 
  // get time data
  RTCind.get(rtc, true);

  SerialUSB.print(F("\nTime "));
  
  SerialUSB.print(dayStr(rtc[3]));
  SerialUSB.print(F(" "));

  SerialUSB.print(rtc[4], DEC);
  SerialUSB.print(F(" "));
  
  SerialUSB.print(monthStr(rtc[5]));
  SerialUSB.print(F(" "));
  
  SerialUSB.print(rtc[6], DEC);
  SerialUSB.print(F(" "));
  if (rtc[2] < 10) SerialUSB.print(F("0"));
  SerialUSB.print(rtc[2], DEC);
  SerialUSB.print(F(":"));
  if (rtc[1] < 10) SerialUSB.print(F("0"));
  SerialUSB.print(rtc[1], DEC);
  SerialUSB.print(F(":"));
  if (rtc[0] < 10) SerialUSB.print(F("0"));
  SerialUSB.print(rtc[0], DEC);

  // set local time function void    setTime(int hr,int min,int sec,int day, int month, int yr);
  setTime(rtc[2], rtc[1], rtc[0], rtc[4], rtc[5], rtc[6]);
}

// ---------------------------------------------------------------------------
void rtcSet()
// ---------------------------------------------------------------------------
{

// requires time library - set time using thime library and this will then set RTC
  
  int rtc[7];
  RTCind.get(rtc, true);
  RTCind.set(MCP7940_SEC, second());
  RTCind.set(MCP7940_MIN, minute());
  RTCind.set(MCP7940_HR, hour());
  RTCind.set(MCP7940_DOW, weekday()); //RTC day 1 = MON, timelib day 1 = SUN
  RTCind.set(MCP7940_DATE, day());
  RTCind.set(MCP7940_MTH, month());
  RTCind.set(MCP7940_YR, year());
  RTCind.start(true);
}

Shane van Jaarsveldt
Shane van Jaarsveldt
22
| 0 0 0
Answered on 1/16/18, 9:02 AM
0
vote

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

42 follower(s)

Stats

Asked: 1/11/18, 7:53 PM
Seen: 240 times
Last updated: 1/16/18, 9:02 AM