Hello,
I use the LAIRD module BL652 with an nRF52832.
My project used the RTC as date/hour counter. I used this RTC to increment a counter each 125 ms of RTC interrupt. I use a external Crystal of 32.768 kHz to supply the RTC, this Crystal have 20 ppm (and we test with a 5 ppm Crystal too). We have a lot of time shifting with this functionality, as 10 seconds of delay by day with a 20 ppm Crystal, as 2 seconds of delay by day with a 5 ppm Crystal.
The product go and out from sleep mode, each second by a timer and each 125 ms with this RTC interrupt.
My RTC configuration is :
static void rtc_config(void)
{
uint32_t err_code;
//Initialize RTC instance
nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG;
config.prescaler = 4095; // To have 125 ms : 4095;
err_code = nrf_drv_rtc_init(&rtc, &config, rtc_handler);
APP_ERROR_CHECK(err_code);
//Enable tick event & interrupt
nrf_drv_rtc_tick_enable(&rtc,true);
// Désactiver la comparaison
nrf_drv_rtc_cc_disable(&rtc, 0);
//Power on RTC instance
nrf_drv_rtc_enable(&rtc);
}
Into the "rtc_handle" function, I increment a counter to count each 125 ms. With this, I can manage the date and the hour of the product.
The define part for the RTC is :
#define RTC_ENABLED 1 #define RTC2_ENABLED 1 #define RTC_DEFAULT_CONFIG_FREQUENCY 32768 #define RTC_DEFAULT_CONFIG_IRQ_PRIORITY 7 #define RTC_DEFAULT_CONFIG_RELIABLE 0 #define NRF_MAXIMUM_LATENCY_US 2000
To define the external Crystal, I have this part :
#define CLOCK_ENABLED 1 #define CLOCK_CONFIG_LF_SRC 1 #define CLOCK_CONFIG_IRQ_PRIORITY 7 #define NRF_SDH_CLOCK_LF_SRC 1 #define NRF_SDH_CLOCK_LF_XTAL_ACCURACY 7 #define NRF_SDH_CLOCK_LF_RC_CTIV 0 #define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 0
So, for me, I have a good configuration to use the external Crystal !!! but perhaps, a "Crystal calibration" is required !! but I Don't know how enable this calibration.
How can I have a better accurancy with a external Crystal ??
How can I do to reduce this shifting ??
If someone else have another idea to mange the date/hour, I take it.
Best regards,
Damien