Hi,
I’ve made many time tests using RTC powered by the onboard 32KHz XTAL.
I’ve used RTC interrupt to trigger a routine that switchs on the built LED for 1 sec (that 1sec is only a simple delay function call - not accurate).
On long hours tests, time is deriving.
I modified the CALX’apollo3 register to correct that derivation (negative value), but time is still deriving.
Have you met that kinf of problems with the internal RTC and the onboard 32KHz ?
What is the precision of that onboard 32KHz please ?
Here is the arduino code I used :
#include "RTC.h" //Include RTC library included with the Aruino_Apollo3 core
APM3_RTC myRTC; //Create instance of RTC class
void setup() {
// Error Adjustment XTAL (from personal measures)
CLKGEN->CLKKEY = CLKGEN_CLKKEY_CLKKEY_Key;
CLKGEN->CALXT = -12;
CLKGEN->CLKKEY = 0;
am_hal_rtc_int_disable( AM_HAL_RTC_INT_ALM );
myRTC.getTime();
myRTC.setTime( 12, 25, 0, 0, 11, 11, 19 ); // h m s centiemesec jourdumois mois année
// myRTC.setToCompilerTime(); //Easily set RTC using the system __DATE__ and __TIME__ macros from compiler
// Set minute alarm
am_hal_rtc_alarm_interval_set( AM_HAL_RTC_ALM_RPT_MIN );
// Enable RTC IT
am_hal_rtc_int_enable( AM_HAL_RTC_INT_ALM );
//Enable the RTC interrupt in the NVIC.
NVIC_EnableIRQ(RTC_IRQn);
// TEST
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//Serial.printf( "%04X\r\n", CLKGEN->CALXT );
myRTC.getTime();
Serial.printf("It is now ");
Serial.printf("%d:", myRTC.hour);
Serial.printf("%02d:", myRTC.minute);
Serial.printf("%02d.", myRTC.seconds);
Serial.printf("%02d", myRTC.hundredths);
Serial.printf(" %02d/", myRTC.month);
Serial.printf("%02d/", myRTC.dayOfMonth);
Serial.printf("%02d", myRTC.year);
Serial.printf(" Day of week: %d =", myRTC.weekday);
Serial.printf(" %s", myRTC.textWeekday);
Serial.println();
// Infinite loop to go sleeping
while( 1 )
{
am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP); //Sleepy time
}
}
//Called once number of milliseconds has passed
extern "C" void am_rtc_isr(void)
{
digitalWrite(LED_BUILTIN, HIGH);
// Lower the flag
am_hal_rtc_int_clear( AM_HAL_RTC_INT_ALM );
myRTC.getTime();
Serial.printf("It is now ");
Serial.printf("%d:", myRTC.hour);
Serial.printf("%02d:", myRTC.minute);
Serial.printf("%02d.", myRTC.seconds);
Serial.printf("%02d", myRTC.hundredths);
Serial.printf(" %02d/", myRTC.month);
Serial.printf("%02d/", myRTC.dayOfMonth);
Serial.printf("%02d", myRTC.year);
Serial.printf(" Day of week: %d =", myRTC.weekday);
Serial.printf(" %s", myRTC.textWeekday);
Serial.println();
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}