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

Parents
  • 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;

    }

Reply
  • 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;

    }

Children
No Data
Related