nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs

low power delay ms

Hi i want to make a low power delay ms (blocking) function for nrf52805 without softdevice and without NRFx, just writing to the registers.

void RTC1_IRQHandler(void)
{
	NRF_RTC1->TASKS_STOP=1;
	NRF_RTC1->EVENTS_COMPARE[0]=0;
}

void helperLowPowerDelayMs(uint16_t ms)
{
	NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
	NRF_CLOCK->TASKS_LFCLKSTART=1;
	while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0){};


	NRF_RTC1->TASKS_STOP=1;
	NRF_RTC1->TASKS_CLEAR=1;
	NRF_RTC1->CC[0]=ms*33;
	NRF_RTC1->EVENTS_COMPARE[0]=0;
	NRF_RTC1->INTENSET=RTC_INTENSET_COMPARE0_Enabled<<RTC_INTENSET_COMPARE0_Pos;

	NVIC_ClearPendingIRQ(RTC1_IRQn);
	NVIC_SetPriority(RTC1_IRQn,1);
	NVIC_EnableIRQ(RTC1_IRQn);
	NRF_RTC1->TASKS_START=1;
	__WFI();
	NVIC_DisableIRQ(RTC1_IRQn);
}

The RTC1 events_tick never gets set, the rtc1 event cc 0 never gets set. the isr does not execute
.

what is the problem?

Parents
  • Hi,

    Try adding

    // Enable EVENTS_COMPARE[0] generation
    NRF_RTC1->EVTENSET = RTC_EVTENSET_COMPARE0_Enabled << RTC_EVTENSET_COMPARE0_Pos;

    Might also want to add a IRQ handler.

    // IRQ handler
    void RTC1_IRQHandler(void)
    {
      volatile uint32_t dummy;
      if (NRF_RTC0->EVENTS_COMPARE[0] == 1)
      {
        NRF_RTC0->EVENTS_COMPARE[0] = 0;
    
        
        // Read back event register so ensure we have cleared it before exiting IRQ handler.
        dummy = NRF_RTC0->EVENTS_COMPARE[0];
        dummy;
      }
    }

    PS: I recommended using the nrfx driver.

Reply
  • Hi,

    Try adding

    // Enable EVENTS_COMPARE[0] generation
    NRF_RTC1->EVTENSET = RTC_EVTENSET_COMPARE0_Enabled << RTC_EVTENSET_COMPARE0_Pos;

    Might also want to add a IRQ handler.

    // IRQ handler
    void RTC1_IRQHandler(void)
    {
      volatile uint32_t dummy;
      if (NRF_RTC0->EVENTS_COMPARE[0] == 1)
      {
        NRF_RTC0->EVENTS_COMPARE[0] = 0;
    
        
        // Read back event register so ensure we have cleared it before exiting IRQ handler.
        dummy = NRF_RTC0->EVENTS_COMPARE[0];
        dummy;
      }
    }

    PS: I recommended using the nrfx driver.

Children
No Data
Related