Go Down

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

mkl0815

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?

Graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

icearrow

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.

Graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

mantoui

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 {
        ticks++;
        us = micros() - us0;
    }
}

void setup() {

    pinMode(BOARD_LED_PIN,OUTPUT);
Serial.begin(9600);
// 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_SetTime(RTC,hr,min,sec);
RTC_SetDate(RTC,yr,m,day,wk);
RTC_EnableIt(RTC,(1<<2));     // pps
// NVIC_EnableIRQ(RTC_IRQn);
delay(3000);
print_time();
}

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);
        Serial.println(str);
print_time();
        delay(5000);
    }
}

void print_time() {
char str[64];

RTC_GetTime(RTC,&hr,&min,&sec);
RTC_GetDate(RTC,&yr,&m,&day,&wk);
sprintf(str,"%d/%d/%d %02d:%02d:%02d",m,day,yr,hr,min,sec);
Serial.println(str);
}



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. 

thoughts?

Go Up