internal RTC

According to the datasheet, the SAM3X has an internal RTC. There is also a 32.768Khz oscillator attached to the XOUT32 and XIN32 pins. Is there a possibility to use the internal RTC with the Arduino libraries?

Yes there is a possibility, as to whether or not anyone has done that work yet I don't know but I very much doubt it because some other basic stuff has not been implemented yet.

They may just leave it for a bright young lad to port an existing RTC library.


Ok, but what about the RTC battery?
When we turn off the DUE also the RTC will go off, sounds like whe need to syncronize it every time we turn on the DUE.

Yes, there's no provision for a backup battery so having the RTC is of limited value I think.

It's a shame because the SAM has really good features for shutting itself and the entire PCB down.


OK, the DUE RTC seems to be ticking, but i’m trying to enable the “second” interrupt. See the following sketch

// due rtc   32khz
//  pps interrupt
//   RTC        (0x400E1A60U)  rtc registers

#define BOARD_LED_PIN 13
volatile static unsigned long ticks,us;
static unsigned long us0;
static uint8_t hr,min,sec,day,m,wk;
static uint16_t yr;

void RTC_Handler() {
    if (us0 == 0) us0 = micros();
     else {
        us = micros() - us0;

void setup() {

// pmc_set_writeprotect(false);
// pmc_enable_periph_clk(RTC_IRQn);
	hr=1; min =2; sec=3; m=4; day=5; wk=6; yr=2012;
	RTC_EnableIt(RTC,(1<<2));     // pps 
// NVIC_EnableIRQ(RTC_IRQn);

void loop() {
    // compare micros to pps
    int ppm;
    char str[32];

    while(1) {
        ppm = ticks*1000000 - us;
        ppm = 1.e6 * ppm/ (float)us;
        sprintf(str,"%ld %ld %d",ticks,us,ppm);

void print_time() {
	char str[64];

	sprintf(str,"%d/%d/%d %02d:%02d:%02d",m,day,yr,hr,min,sec);

I get no ticks in the RTC_Hander() as the code is. If i uncomment the NVIC_Enable, it hangs.

my first try the DUE interrupts etc.


Now seeing the other RTC thread, I incorporated some of that code, and now I'm getting into the RTC_Handler working. Code reports that RTC is within 3ppm of system clock -- makes me wonder if code is really using the 32Khz crystal ?

Here are some frequency offsets for other MCU crystals, resonators, RTC ...

  processor    oscillator       spec       measured(ppm)
  avr 328p    16Mhz resonator  0.5%     -1330        uno
               16MHz resonator  0.5%     -1422        breadboard 328p
                16MHz crystal    50ppm    -42          breadboard 328p
  avr 328p    11Mhz crystal     ?             -23          3.74v batteries
  avr 328p    11Mhz crystal     ?       -16          5v
  avr 128      14Mhz             ?       1738         no schematic, resonator?

  DUE         12MHz*x crystal    ?       -4
  DUE RTC     32Khz   crystal    ?       3           work in progress
  maple       8MHz*9 crystal    ?        -5
  propeller   5Mhz*16 crystal   ?        -40         board1 (quickstart)
  propeller   5Mhz*16 crystal   ?        -98         board2 (quickstart)

  ds1307 RTC  32khz   cyrstal  20ppm    23           external "watch" crystal
  ds3132 RTC  32khz   cyrstal   2ppm     1           chronodot TCXO i2c
  ds3134 RTC  32khz   cyrstal   2ppm     1           TCXO SPI

  maple RTC   32khz   cyrstal   20ppm     -41         breadboard 512hz ticks
  bad         32khz   crystal   20ppm   -891019      breadboard 512hz ticks

  avr 328  RC  8Mhz     RC      1%       2100         OSCCAL units 3000 ppm
  avr 328p RC  8Mhz     RC      1%       2700         OSCCAL units 5000 ppm
  avr 328p RC  8Mhz     RC      1%       4061         OSCCAL units 4000 ppm
  maple LSI    40KHz    RC     50%     -19659         calibrate with prescale

  beagle      24MHz*x                    -5          ntp drift
  raspberry   19MHz*x                   -16          ntp drift
  dell desk                             -26          ntp drift
  dell laptop                           -14          ntp drift


Why du you use the RTC creating ticks? The SAM3X has a 24 bit system tick timer. It creates 1 ms ticks. In the arduino software it is already implemented --> millis() // returns the current system time.

ticks from the RTC were only used to measure frequency accuracy of the 32khz crystal

Oh sorry I understand you wrong. Back to your problem. I think you have to clear the second clear bit (RTC_SCCR_SECCLR). This is a small example which i did before:

void RTC_Handler(void)
  uint32_t ul_status = rtc.rtc_get_status(RTC);
  rtc.rtc_get_time(RTC, &hour, &minute, &second);
  /* Second increment interrupt */
  if ((ul_status & RTC_SR_SEC) == RTC_SR_SEC) 
    rtc_time = "Time: ";
    rtc_time += String(hour);
    rtc_time += ":";
    rtc_time += String(minute);
    rtc_time += ":";
    rtc_time += String(second);
    rtc.rtc_clear_status(RTC, RTC_SCCR_SECCLR);
  /* Time or date alarm */
  if ((ul_status & RTC_SR_ALARM) == RTC_SR_ALARM) 
    rtc.rtc_clear_status(RTC, RTC_SCCR_ALRCLR);


I need a source of such a 32kHz crystal that cooperates with our Sam3x8e. (Low power design. not that trivial as it seems, I read... One seems to have to count Capacitances, of the PCB strands as well. )

Can you give me a link to the product in the shop you bought it? Or some detailes like manufacturer and part number?

What is the size of the capacitors you used?

Thank you!


CM315D32768DZCT is used in Due

32kHz crystal is used as an accurate slow clock source, SAM3X8E has an oscillator built-in but it is not accurate... You can try running your project without external oscillator.

Hello! Thanks, aigarslv!

I used the casing, SMD 1206, and the specs you provided via the digikey link: 9pF, 70kOhm. Now I can find some sources of the crystal / quartz.

Then I found, in sch of Due, that the accompanying capacitors shall have 22pF. This is some problem, as they are in 0402 casing, 1mm x 0,5mm.

If you are not some aesteticist, you can probably solder anything to the tiny pads. Me, I'm trying to find a supplyer of such a capacitor where I do not have to buy one for 4EUR (ebay GB, uff), or 7EUR and get a bunch of 1000. (7EUR inc. pp, so why not ;)

For german users, perhaps in need of some other parts, we tend to buy at reichelt, conrad or Latter one has our quartz: MicroCrystal Uhrenquarz CM7V-T1A-Serie CM7V-T1A 32.768kHz 9pF +/-20ppm TA QC According to datasheet, it has a series resistance of typ. 50kOhm and max. 70kOhm. This is the same for the digikey part. Ebay decoelectrix sells them as well.

I can try soldering SMD 0805 casing on the 0402 pads for the capacitor, since they are more available. But length from 1mm (0402 original) to 1.6mm (the available ones) difference is quite a jump...

If anyone would be willing to solder these parts on top of his or her DUE I would be ordering the 1000pack and some more crystals...

Datasheet of Due Processor says "down to 2.5µA in Backup Mode", where it supplies RTC, RTT and wake-up logic.

But this makes only sense if we drill up the pcb to support V_Backup (via button cell) to keep the clock going on battery. Or some recarcheable or SuperCap/GoldCap. I.e., seperate the pin and feed it via Backup power source.

Anyone already digging in this?

It would make sense, if I buy the 1000pack 22pF's, to "get it round" by putting the other needed parts aside of this, the crystal, some Power source like SuperCap, Resistor/Diodes for charging it, any thing needed for switching over to normal Vcc;

Anyone any wishes: how long should it keep going in the "watch mode"? Should it be able to do any usefull things aside of this, like temperature and acceleration logging once a minute or so ;) ?

Then we need a library and example sketch that would set up the super low power RTC mode ;)



There is a library for the Due's internal RTC:

Hello there,

I looked into this a little so far and it looks like the external oscillator is 20ppm while a good external RTC is only 2ppm. That's ten times better.

In fact, i have been testing an external RTC over a month now, and the accuracy is at least as good as 1/2 second per month max. That's only 6 seconds per year. The projected accuracy is more like 60 seconds per year but that is over the full temperature range. At room temperature it's much better and i am seeing about 6 seconds per year accuracy which is more than good enough.

By contrast, 20ppm is about 600 seconds per year (10 minutes) but that is probably over the full temperature range too, so figure maybe 1 minute per year accuracy.

So it's 6 seconds per year vs 60 seconds per year, take your pick. The external RTC's made by Maxim are very good (2ppm) so that's what i went with. The RTC boards that contain the Maxim chip also have a battery for battery backup, so when the power goes out there is no loss of time keeping.

Note the good boards DO NOT have an external crystal mounted on the board because the crystal on those better chips is mounted right inside the IC chip itself. The boards with the little cylindrical external crystals are much much less accurate, not even worth the effort.