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 {
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?