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

nRF51822 xxAC RTC problem

Hi everyone.

I have problem with my device. I use Visual studio with visual GDB and I'm trying to use interrupts from RTC. Got from this site lot of examples and wrote some function but when i try to compile I have few Errors. But all of them ale same:
Error: use of undeclared identifier 'rtc' I use lot of function with "&rtc" for example:

static void rtc_config(void)
{
	uint32_t err_code;

	//Initialize RTC instance
	nrf_drv_rtc_config_t rtc_config;
	rtc_config.prescaler = RTC_FREQ_TO_PRESCALER(RTC_FREQUENCY);
	err_code = nrf_drv_rtc_init(&rtc, &rtc_config, rtc_handler);               //Initialize the RTC with callback function rtc_handler.
	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.
	APP_ERROR_CHECK(err_code);

	//Power on RTC instance
	nrf_drv_rtc_enable(&rtc);                                           //Enable RTC
}

My question is what im missing? I mean probably I need to Include some files where is declared rtc but which one? I have
#include "nrf_drv_clock.h"
and
#include "nrf_drv_rtc.h"
Or what and where I should wrote to manually repair this issue?

Parents
  • OK, I found out that I lost one line of code so i added it:

    const  nrf_drv_rtc_t           rtc = NRF_DRV_RTC_INSTANCE(1); 

    I have to use RTC1 because RTC0 is reserved for Soft Device. But when i Compile this i have neew Errors:

    Error: use of undeclared identifier 'RTC0_ENABLED'

    and

    'RTC0_ENABLED' undeclared here (not in a function); 

    I'm using RTC1 so why this errors are about RTC0? and how to fix it?

  • Have you set the correct RTC settings in sdk_config.h?

    // <q> RTC0_ENABLED  - Enable RTC0 instance
     
    
    #ifndef RTC0_ENABLED
    #define RTC0_ENABLED 0
    #endif
    
    // <q> RTC1_ENABLED  - Enable RTC1 instance
     
    
    #ifndef RTC1_ENABLED
    #define RTC1_ENABLED 1
    #endif
    

     

    Rafaello said:
    'RTC0_ENABLED' undeclared here (not in a function); 

     This is probably pointing to a place in your project. Where does it point? (try double clicking it).

Reply
  • Have you set the correct RTC settings in sdk_config.h?

    // <q> RTC0_ENABLED  - Enable RTC0 instance
     
    
    #ifndef RTC0_ENABLED
    #define RTC0_ENABLED 0
    #endif
    
    // <q> RTC1_ENABLED  - Enable RTC1 instance
     
    
    #ifndef RTC1_ENABLED
    #define RTC1_ENABLED 1
    #endif
    

     

    Rafaello said:
    'RTC0_ENABLED' undeclared here (not in a function); 

     This is probably pointing to a place in your project. Where does it point? (try double clicking it).

Children
  • Hi, I had both RTC0 and RTC1 ENABLED 0 
    So I changed RTC1 to ENABLED 1 like you show me. But this changed nothing. 
    Moreover I saw i had:

    // <e> RTC_ENABLED - nrf_drv_rtc - RTC peripheral driver
    //==========================================================
    #ifndef RTC_ENABLED
    #define RTC_ENABLED 0
    #endif

    So i changed it to ENABLED 1. Then error which I mentioned in previous post dissapierd. 

    But now i have this error:

    'multiple definition of 'RTC1_IRQHandler' I found that i have 2 of them.
    One is in nrf_drv_rtc.c second in app_timer.c

    Can i delete one of them without any doubts? 

  • The nRF51822 has 2 RTCs, RTC0 and RTC1. Typically, the Softdevice uses RTC0, and the app_timer uses RTC1. 

    Are you using the app_timer as well in your project? If so, both of your RTCs are already in use. If you are not using the app_timer, you can remove the app_timer files, and you should be good to go.

    If you are using the app_timer, I suggest that you try to use this to what you are trying to use the RTC1 for. 

  • Hi, I don't use app_timer, I dont know why I have this file.

    I deleted this and everything works fine.

Related