Arduino Due RTC library

Hi All,

I want to implement RTC in arduino due. I referred the latest version RTC library of Marklange. But in my arduino Not having external oscillator. So i select the internal oscillator RTCDue rtc(RC). when I programming through port, arduino due isn't running. After i programming the code in arduino due, it will not happen.

Please give solution for above mention problem and also give any suggest for RTC library for arduino due.

Best Regards,
Anitha.L

RTC is a very simple peripheral. Reading RTC chapter of Sam3x datasheet should provide all relevant informations.

An example code to output Time:

/*******************************************************/
/*     Time Output from embedded RTC clock             */
/*******************************************************/

const char* daynames[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};

uint8_t val_sec = 50,
        val_min = 59,  // For 9 min write 9 not 09  !
        val_hour = 9,
        val_cent = 20,
        val_year = 19,
        val_month = 12,
        val_day = 01,
        val_date = 24,
        val;

void setup()
{
  Serial.begin(250000);

  //  24 hour mode selected by default
  //RTC->RTC_MR = ~RTC_MR_HRMOD;

  RTC->RTC_CR |= RTC_CR_UPDTIM | RTC_CR_UPDCAL;         // Stop RTC
  
  while (!(RTC->RTC_SR & RTC_SR_ACKUPD));               // Wait until Time and Calendar can be updated
  RTC->RTC_SCCR = RTC_SCCR_ACKCLR ;

  // Update Time fields (Hour, Minute, Second)
  RTC->RTC_TIMR = (uint32_t)(((val_sec % 10) |   (val_sec / 10 << 4))  << RTC_TIMR_SEC_Pos) |
                  (uint32_t)(((val_min % 10) |   (val_min / 10 << 4))  << RTC_TIMR_MIN_Pos) |
                  (uint32_t)(((val_hour % 10) |  (val_hour / 10 << 4)) << RTC_TIMR_HOUR_Pos);

  //  Update Calendar fields(century, year, month, date, day)
  RTC->RTC_CALR = (uint32_t)(((val_cent % 10) |   (val_cent / 10 << 4))   << RTC_CALR_CENT_Pos) |
                  (uint32_t)(((val_year % 10) |  (val_year / 10 << 4))   << RTC_CALR_YEAR_Pos) |
                  (uint32_t)(((val_month % 10) | (val_month / 10 << 4))  << RTC_CALR_MONTH_Pos) |
                  (uint32_t)(((val_day % 10) |   (val_day / 10 << 4))    << RTC_CALR_DAY_Pos) |
                  (uint32_t)(((val_date % 10) |  (val_date / 10 << 4))   << RTC_CALR_DATE_Pos);

  RTC->RTC_CR &= ~(RTC_CR_UPDTIM | RTC_CR_UPDCAL);   // Start RTC
  printf("                     \n");
}

void loop()
{
  val = (RTC->RTC_TIMR & RTC_TIMR_SEC_Msk);
  val = (val & 0x0F) + ((val >> 4) * 10);
  printf("seconds = %d\t", val);

  val = (RTC->RTC_TIMR & RTC_TIMR_MIN_Msk) >> RTC_TIMR_MIN_Pos;
  val = (val & 0x0F) + ((val >> 4) * 10);
  printf("minutes = %d\t", val);

  val = (RTC->RTC_TIMR & RTC_TIMR_HOUR_Msk) >> RTC_TIMR_HOUR_Pos;
  val = (val & 0x0F) + ((val >> 4) * 10);
  printf("hours = %d\n", val);
  delay(1000);
}

You can get time and date from the uploading Date and Time:

void setup() {
  Serial.begin(250000);
  char compilationDate[] = __DATE__;
  char compilationTime[] = __TIME__;
 
  printf(
    "Compilation date: %s\n"
    "Compilation time: %s\n",
    compilationDate,
    compilationTime
  );
}

void loop() {
  }