I could not find a way, where I can get the nrfx_rtc_t const *p_instance for the nrfx_rtc_init function. There is no example where it is shown where to get this struct from.
I could not find a way, where I can get the nrfx_rtc_t const *p_instance for the nrfx_rtc_init function. There is no example where it is shown where to get this struct from.
Hi,
The nrfx_rtc_t must be defined in your application. This is normally done like this:
#define RTC_INSTANCE_NUMBER 0
const nrfx_rtc_t rtc = NRFX_RTC_INSTANCE(RTC_INSTANCE_NUMBER);
Where RTC_INSTANCE_NUMBER represents the RTC instance you want to use (in this case RTC0).
You can then pass this instance to nrfx_rtc_init() like this:
nrfx_rtc_init(&rtc, .., ..);
This is shown in the RTC peripheral example in nRF5 SDK (with nrf_drv_rtc APIs, but this is a simple replacement to nrfx).
Best regards,
Jørgen
Yes, that is correct. You need to enable the RTC instance in your sdk_config.h file (given that you are using nRF5 SDK and not nRF Connect SDK):
// <e> NRFX_RTC_ENABLED - nrfx_rtc - RTC peripheral driver //========================================================== #ifndef NRFX_RTC_ENABLED #define NRFX_RTC_ENABLED 1 #endif // <q> NRFX_RTC0_ENABLED - Enable RTC0 instance #ifndef NRFX_RTC0_ENABLED #define NRFX_RTC0_ENABLED 1 #endif
Make sure that you comment out or completely remove any legacy configs for the driver in the sdk_config.h file, as these will overload the nrfx configs in the file apply_old_config.h if defined, regardless of their defined value.
// <e> RTC_ENABLED - nrf_drv_rtc - RTC peripheral driver - legacy layer //========================================================== // #ifndef RTC_ENABLED // #define RTC_ENABLED 1 // #endif // <q> RTC0_ENABLED - Enable RTC0 instance // #ifndef RTC0_ENABLED // #define RTC0_ENABLED 1 // #endif
Ah sorry, my fault. I forgot to meantion, that I am currently using the nrf Connect SDK v 2.1.0.
Then you need to set CONFIG_NRFX_RTC0=y.
Ok I changed all above as you mentioned. I did not get any Repsonse from the RTC.
static void rtc_handler(nrfx_rtc_int_type_t int_type) {
LOG_INF("%s","Intr");
set_intr_src(0x05);
}
static void rtc_config(void) {
const nrfx_rtc_t rtc = NRFX_RTC_INSTANCE(RTC_INSTANCE_NUMBER);
uint32_t err_code;
//Initialize RTC instance
nrfx_rtc_config_t rtc_config;
rtc_config.prescaler = RTC_FREQ_TO_PRESCALER(10);
err_code = nrfx_rtc_init(&rtc, &rtc_config, rtc_handler);
LOG_INF("ErrorCode: %d",err_code);
err_code = nrfx_rtc_cc_set(&rtc,0,100,true);
LOG_INF("ErrorCode: %d",err_code);
//Power on RTC instance
nrfx_rtc_enable(&rtc);
}
Ok I changed all above as you mentioned. I did not get any Repsonse from the RTC.
static void rtc_handler(nrfx_rtc_int_type_t int_type) {
LOG_INF("%s","Intr");
set_intr_src(0x05);
}
static void rtc_config(void) {
const nrfx_rtc_t rtc = NRFX_RTC_INSTANCE(RTC_INSTANCE_NUMBER);
uint32_t err_code;
//Initialize RTC instance
nrfx_rtc_config_t rtc_config;
rtc_config.prescaler = RTC_FREQ_TO_PRESCALER(10);
err_code = nrfx_rtc_init(&rtc, &rtc_config, rtc_handler);
LOG_INF("ErrorCode: %d",err_code);
err_code = nrfx_rtc_cc_set(&rtc,0,100,true);
LOG_INF("ErrorCode: %d",err_code);
//Power on RTC instance
nrfx_rtc_enable(&rtc);
}