Feather nRF52840 RTC (Real Time Counter)

Hi,

For the Adafruit Feather nRF52840 board I cannot find any information about the RTC. On the Feather board the 32kHz crystal is connected to the RTC clock input (P0.00 and P0.01). My question is how to control the RTC? I want to put the SoC to sleep and after some time wake-up by the RTC. I have found examples for the SLEEP OFF mode (wake-up by pin change) but not for the SLEEP ON mode (wake-up by RTC).

Thanks,

Tjerk

  • I now have code for the RTC0 interrupt (see below). However, after calling initRTC the IRQHandler is not triggered. What should I do to get the interrupt working?

    Thanks,

    Tjerk

    ---------------------------------------------------------------------------------------------------------------------------------------------

    #include <nrf.h>

    extern "C" void RTC0_IRQHandler(void) {
        if (NRF_RTC0->EVENTS_TICK) {
            NRF_RTC0->EVENTS_TICK = 0;  // Clear the event
            
        }
    }


    // Code for controlling the internal 24-bit RTC (Real Time Counter) with 12-bit prescaler
    // RTC is clocked by the on-board 32kHz crystal

    void initRTC()
    {

        // Start the LFCLK source
        NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal;  // Use external crystal

        NRF_CLOCK->TASKS_LFCLKSTART = 1;  // Start LFCLK
        // Wait for LFCLK to start
        while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;  // Clear the event

        // Clear RTC registers
        NRF_RTC0->TASKS_STOP = 1;
        NRF_RTC0->TASKS_CLEAR = 1;
        NRF_RTC0->PRESCALER = 327;  // Prescaler to get a 1ms tick
        NRF_RTC0->EVTENSET = RTC_EVTENSET_TICK_Msk;  // Enable TICK event
        NRF_RTC0->INTENSET = RTC_INTENSET_TICK_Msk;  // Enable interrupt for TICK event

        // Clear any pending interrupts
        NVIC_ClearPendingIRQ(RTC0_IRQn);

        // Enable the RTC interrupt in the NVIC
        NVIC_EnableIRQ(RTC0_IRQn);

        // Start the RTC
        NRF_RTC0->TASKS_START = 1;

    }

  • Hello,

    Could you please tell me which SDK version you are using here? Please take a look at this old Devzone thread; it discusses something very similar.

    Kind regards,
    Abhijith

  • Dear Abhijith,

    I do not know which SDK version is used but I am using PlatformIO with the following configuration:

    [env:nrf52840]
    platform = nordicnrf52
    board = adafruit_feather_nrf52840
    framework = arduino
    Kind regards,
    Tjerk
  • Hello,

    There have been some changes with certain SDK versions. Please let me know if the thread I referred to was helpful.

    Kind regards,
    Abhijith

  • Hi,

    Now I am using SDK version 17.1.0 but am getting errors compiling the RTC example:

    In file included from src\RTC.cpp:5:0:
    include/nrf_drv_clock.h:100:1: error: 'ret_code_t' does not name a type; did you mean '__mode_t'?

    Best regards,

    Tjerk

Related