RTC Initialization fails (NRF_ERROR_ALREADY)

Hi,

I'm trying to use an RTC with the nRF Connect SDK (v2.9.0) and nRF52840, but nrfx_rtc_init always returns the error NRF_ALREADY_INIT. I haven't used the RTC anywhere else in my code, and I also tried using RTC0, but I still get the same error."

  const nrfx_rtc_t rtc = NRFX_RTC_INSTANCE(2);
  
    nrfx_err_t err;
    nrfx_rtc_config_t rtc_cfg = NRFX_RTC_DEFAULT_CONFIG;
    if (nrfx_rtc_init(&rtc, &rtc_cfg, rtc_event_handler))
    err = nrfx_rtc_init(&rtc, &rtc_cfg, rtc_event_handler);

The project configuration file is below:

CONFIG_NRFX_SAADC=y
CONFIG_NRFX_PPI=y
CONFIG_NRFX_TIMER4=y
CONFIG_NRFX_TEMP=y
CONFIG_NRFX_PWM0=y
CONFIG_NRFX_RTC2=y
# Enable DK LED and Buttons library
CONFIG_DK_LIBRARY=y
CONFIG_LOG=y
CONFIG_LOG_MODE_MINIMAL=y

I'm using the nrfx library because I need to link it with the PPI module, which I believe is not supported in Zephyr.

Parents
  • Hi,

     

    I ran this in hello_world:

    /*
     * Copyright (c) 2012-2014 Wind River Systems, Inc.
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <stdio.h>
    #include <nrfx_rtc.h>
    
    static const nrfx_rtc_t rtc = NRFX_RTC_INSTANCE(2);
    
    void rtc_event_handler(nrfx_rtc_int_type_t isr_type)
    {
    	(void)isr_type;
    }
    
    int main(void)
    {
    	printf("Hello World! %s\n", CONFIG_BOARD_TARGET);
      
        nrfx_err_t err;
        nrfx_rtc_config_t rtc_cfg = NRFX_RTC_DEFAULT_CONFIG;
        err = nrfx_rtc_init(&rtc, &rtc_cfg, rtc_event_handler);
    	printf("Error : %x\n", err);
    	return 0;
    }
    

     

    And it prints NRFX_SUCCESS (0xbad0000).

    This will always run nrfx_rtc_init twice, as "NRFX_SUCCESS" is not defined as 0:

        if (nrfx_rtc_init(&rtc, &rtc_cfg, rtc_event_handler))
        err = nrfx_rtc_init(&rtc, &rtc_cfg, rtc_event_handler);

     

    Kind regards,

    Håkon

  • This will always run nrfx_rtc_init twice, as "NRFX_SUCCESS" is not defined as 0:

    I thought I’d already removed the first line. Thanks, it worked!

Reply Children
No Data
Related