This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nRF52840 SDK16 - RTC Driver general questions - instance, initialization, and channels

Hi everyone,

I want to use the RTC module in my code, and I have some questions.

1. What I have understood so far is that the nRF52840 has three RTCs (RTC0, RTC1, RTC2). RTC0 is used by the SD and RTC1 from the application timer software. So it's safer using RTC2 for events generation, right?

2. What is the id parameter when calling the NRFX_RTC_INSTANCE macro for creating an RTC instance? For example, if I use RTC2 the id value must be 2, while if I use RTC2 the id value must be 1?

3. The PRESCALER register is a 12-bit register, meaning that the maximum value is 4095, giving a tick every 125 ms. So, with the TICK event, the maximum event period is limited to 125ms?

4. Each RTC has four compare channels, right? The function to set a compare channel is nrfx_rtc_cc_set. According to the function's description, the second parameter is the channel of the instance. So the value of this parameter could be 1,2,3, or 4? For example, can I use all of the four compare channels of RTC2 like this?

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 = 327; //100Hz (10ms)
  err_code = nrf_drv_rtc_init(&rtc, &config, rtc_handler);
  APP_ERROR_CHECK(err_code);

  err_code = nrf_drv_rtc_cc_set(&rtc, 0, 1, true); // compare event occurs every 10ms at channel 0
  APP_ERROR_CHECK(err_code);
  
  err_code = nrf_drv_rtc_cc_set(&rtc, 1, 2, true); // compare event occurs every 20ms at channel 1
  APP_ERROR_CHECK(err_code);
  
  err_code = nrf_drv_rtc_cc_set(&rtc, 2, 3, true); // compare event occurs every 30ms at channel 2
  APP_ERROR_CHECK(err_code);
  
  err_code = nrf_drv_rtc_cc_set(&rtc, 3, 4, true); // compare event occurs every 40ms at channel 3
  APP_ERROR_CHECK(err_code);

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

Thanks

Nick

  • Thank you ovrebekk, 

    Yes I know about the legacy layer (I forgot to mention it in the stack scketch).

    So in fact when you develop applications in the nRF5 SDK you will use the nrf_drv API in your application, which is then redirected to the nrfx implementation, which will again use the HAL files underneath.

    I was thinking the opposite :) The new implementation (nrfx) has additional functionalities and I should use the nrfx API when I develop applcations. 

  • Hi

    You can use the nrfx interface if you want, but in general it is easier to enable the nrf_drv layer in the nRF5 SDK since this is the default driver interface in the SDK.

    Also, the functionality of the nrf_drv drivers and the nrfx drivers is more or less identical, for most functions the only difference is the name. 

    Best regards
    Torbjørn

Related