Due RTC issue when push reset.

Goodevening everybody.
I'm having an issue with an Arduino Due compatible board (TaijiUino Due) and the onboard RTC with DUE_RTC library.
I use this bouard since the VBU pin (backup battery pin) of the SAM3X is available to be connected to an external 3V battery in order to keep the RTC alive and keep counting time even with no power.

The RTC itself works properly and fine, I've programmed the board using the Due RTC_Simple_Sample Sketch and actually the RTC keeps time even when no USB or DC cable is connected.

Probles starts as soon as I press the onboard reset button, once I restart the board the internal date and time are resetted to 01/01/2007 00:00:00.

Do You know if there is a way to avoid that? It's not to comfortable to update the RTC date and time after every reset.

Thank You

icearrow:
Goodevening everybody.
I'm having an issue with an Arduino Due compatible board (TaijiUino Due) and the onboard RTC with DUE_RTC library.
I use this bouard since the VBU pin (backup battery pin) of the SAM3X is available to be connected to an external 3V battery in order to keep the RTC alive and keep counting time even with no power.

The RTC itself works properly and fine, I've programmed the board using the Due RTC_Simple_Sample Sketch and actually the RTC keeps time even when no USB or DC cable is connected.

Probles starts as soon as I press the onboard reset button, once I restart the board the internal date and time are resetted to 01/01/2007 00:00:00.

Do You know if there is a way to avoid that? It's not to comfortable to update the RTC date and time after every reset.

Thank You

Hello icearrow,

I don't know what code you are using but I use to use two codes. One for the initial settings and the other one to read the timestamp. Here the codes:

Code to set the day/time:

#include "Wire.h"
#define DS1307_ADDRESS 0x68
#define DS1307_I2C_ADDRESS 0x68

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

void setup(){
  Wire.begin();
  Serial.begin(9600);
  second = 0;
  minute = 43;
  hour = 16;
  dayOfWeek = 2;
  dayOfMonth = 14;
  month = 9;
  year = 15;
  setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);

}

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

byte bcdToDec(byte val)  {
  return ( (val/16*10) + (val%16) );
}

void printDate(){
  Wire.beginTransmission(DS1307_ADDRESS);
  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);
  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());
  Serial.print(month);
  Serial.print("/");
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);
}

void setDateDs1307(byte second,        // 0-59
byte minute,        // 0-59
byte hour,          // 1-23
byte dayOfWeek,     // 1-7
byte dayOfMonth,    // 1-28/29/30/31
byte month,         // 1-12
byte year)          // 0-99
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0);
  Wire.write(decToBcd(second));    // 0 to bit 7 starts the clock
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));     
  Wire.write(decToBcd(dayOfWeek));
  Wire.write(decToBcd(dayOfMonth));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));
  Wire.write(B00010000); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
  Wire.endTransmission();
}
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

Here the code to read the date/time:

#include "Wire.h"
#define DS1307_ADDRESS 0x68

void setup(){
  Wire.begin();
  Serial.begin(9600);
  }

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

byte bcdToDec(byte val)  {
  return ( (val/16*10) + (val%16) );
}

void printDate(){
  Wire.beginTransmission(DS1307_ADDRESS);
  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);
  int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());
  Serial.print(month);
  Serial.print("/");
  Serial.print(monthDay);
  Serial.print("/");
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);
}

-p

Hi Palliser,
I think you misunderstood, actually I don't use an external I2C RTC like the DS1307 but the embedded RTC.
Evrything works good exept that as soon as I hit the reset button the RTC data are setted to 01/01/2007 00:00:00.
Here the example code that I use to test the RTC:

#include <rtc_clock.h>
RTC_clock rtc_clock(XTAL);

void setup() {
  SerialUSB.begin(9600);
  rtc_clock.init();
}

void loop() {
if (SerialUSB.available()) {
    switch (SerialUSB.read()) {
      case 't':
        {
          //time update string eg: t2016,3,2,11,30,5
          int years = SerialUSB.parseInt();
          int months = SerialUSB.parseInt();
          int days = SerialUSB.parseInt();
          int hours = SerialUSB.parseInt();
          int minutes = SerialUSB.parseInt();
          int seconds = SerialUSB.parseInt();
          rtc_clock.set_time(hours, minutes, seconds);
          rtc_clock.set_date(days, months, years);
          break;
        }
      case 'c':
        {
          SerialUSB.print(rtc_clock.get_years());
          SerialUSB.print(",");
          SerialUSB.print(rtc_clock.get_months());
          SerialUSB.print(",");
          SerialUSB.print(rtc_clock.get_days());
          SerialUSB.print(",");
          SerialUSB.print(rtc_clock.get_hours());
          SerialUSB.print(",");
          SerialUSB.print(rtc_clock.get_minutes());
          SerialUSB.print(",");
          SerialUSB.println(rtc_clock.get_seconds());
          break;
        }
      default:
        SerialUSB.flush();
        break;

    }

  }

}

That is normal for the Due, as the Reset button -- as well as plugging into the Programming USB port -- sends a full reset to the CPU. That resets the RTC.

icearrow:
Goodevening everybody.
I'm having an issue with an Arduino Due compatible board (TaijiUino Due) and the onboard RTC with DUE_RTC library.
I use this bouard since the VBU pin (backup battery pin) of the SAM3X is available to be connected to an external 3V battery in order to keep the RTC alive and keep counting time even with no power.

The RTC itself works properly and fine, I've programmed the board using the Due RTC_Simple_Sample Sketch and actually the RTC keeps time even when no USB or DC cable is connected.

Probles starts as soon as I press the onboard reset button, once I restart the board the internal date and time are resetted to 01/01/2007 00:00:00.

Do You know if there is a way to avoid that? It's not to comfortable to update the RTC date and time after every reset.

Thank You

kb5pgy:
That is normal for the Due, as the Reset button -- as well as plugging into the Programming USB port -- sends a full reset to the CPU. That resets the RTC.

icearrow,

Sorry for my misunderstanding.
kb5pgy is right. Among other things, for this particular point, there is a design flaw with the reset of Due. Arduino/Atmel wired the NRSTB (Asynchronous) pin as master reset instead of NRST. By doing that, every time you press the reset button on Due, you reset the Backup region (RTC, RTT and supply controller).

In case they decide to release an newer version of Due, I hope they consider this.

-p

Hi,
Thanks for pointing this issue. Sometimes it gets so frustrating just because I reset by the button and not by power off and on again.
I'm studying a workaround with the Due Flash Programmer library to save the time at least every second. Then during the setup if the RTC date will be wrong (year = 2007) I will sum the RTC data with the last saved values.