Go Down

Topic: internal RTC (Read 4295 times) previous topic - next topic


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.

Rob Gray aka the GRAYnomad www.robgray.com


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.

Rob Gray aka the GRAYnomad www.robgray.com


OK, the DUE RTC seems to be ticking, but i'm trying to enable the "second" interrupt.  See the following sketch
Code: [Select]

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



Dec 06, 2012, 11:37 pm Last Edit: Dec 07, 2012, 12:05 am by mantoui Reason: 1
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 ...
Code: [Select]

  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


Dec 07, 2012, 06:41 am Last Edit: Dec 07, 2012, 06:45 am by M4nu Reason: 1

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:

Code: [Select]

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!



Jun 23, 2015, 11:51 pm Last Edit: Jun 23, 2015, 11:58 pm by aigarslv
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.


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 voelkner.de.
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 ;)



Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131