This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

lfclk, rtc issue on SDK13

I am trying to set up RTC2 by following an example github.com/.../saadc_low_power I ported it to my project which is running a softdevice on nRF52. It works perfectly fine on SDK11 but has problems on SDK13.0 / 13.1. Seems like nrf_drv_clock_init() or nrf_drv_rtc_init() has conflict with the BLE stack. Any idea what has changed from SDK11 to SDK13?

  • Could you describe the conflicts and problems in more detail? And provide some code snippets showing setup/configuration? I'm not aware of any major changes in these modules.

  • Here I ported it to the ble_app_hts_c project in Nordic example codes. lfclk_config() and rtc_config() are the two functions added. It is going to crash in ble_stack_init() in the following order. If I put the two clock functions after ble_stack_init(), they failed. Looks the three functions are fighting each other. It works fine in SDK11 though.

    int main(void)
    {
    ...
    lfclk_config();                                  //Configure low frequency 32kHz clock
    rtc_config();                                    //Configure RTC. 
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);
    buttons_leds_init(&erase_bonds);
    nrf_log_init();
    APPL_LOG("Temperature collector example\r\n");
    ble_stack_init();
    ...
    }
    static void lfclk_config(void)
    {
        ret_code_t err_code = nrf_drv_clock_init();                        //Initialize the clock source specified in the nrf_drv_config.h file, i.e. the CLOCK_CONFIG_LF_SRC constant
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_clock_lfclk_request(NULL);
    }
    
    static void rtc_config(void)
    {
        uint32_t err_code;
    
        //Initialize RTC instance
        err_code = nrf_drv_rtc_init(&rtc, NULL, rtc_handler);              //Initialize the RTC with callback function rtc_handler. The rtc_handler must be implemented in this applicaiton. Passing NULL here for RTC configuration means that configuration will be taken from the nrf_drv_config.h file.
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_rtc_cc_set(&rtc,0,RTC_CC_VALUE,true);           //Set RTC compare value to trigger interrupt. Configure the interrupt frequency by adjust RTC_CC_VALUE and RTC2_CONFIG_FREQUENCY constant in the nrf_drv_config.h file
        APP_ERROR_CHECK(err_code);
    
        //Power on RTC instance
        nrf_drv_rtc_enable(&rtc);                                          //Enable RTC
    }
    
  • Have you tried checking for error codes using this method? Aslo, what is your LFCLK settings? Are you testing this on the nRF52 DK or a custom board?

  • Thx, Jørgen. I used the method to check the error code. It is 0x1001 = NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION in function ble_stack_init() --> SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL); clock_lf_cfg is from NRF_CLOCK_LFCLKSRC -- default setting in pca10040.h I develop this on an nRF52 base Murata (which I work for) module and I have to port the project to eclipse/GCC due to code size limit in Keil. It doesn't look like a hardware or toolchain issue to me though, since SDK11 works fine on the same platform. Seems like softdevice in SDK13 takes over RTC and application can't access it anymore.

  • Could you upload your sdk_config.h file, and the declaration of the RTC instance, rtc (used in nrf_drv_rtc_init())?

Related