This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
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

interrupt on HFCLKSTARTED problem

Hi, I have a problem with the HFCLKSTARTED interrupt.

I can't have it. (I'm a little bit pressed with time I have to send a document in 2 days, so if you can quick respond to my 2 simple questionS first, and maybe later have a look for the rest you will be very nice :-))

MY SIMPLE QUESTION 1 : can whe stop the HFCLK and directly going to sleep calling __wfi() ?

doing that

nRF_POWER->TASKS_LOWPWR = 1UL;    // instruction 1)
NRF_CLOCK->TASKS_HFCLKSTOP = 1;   // instruction 2)
__WFI();                          // instruction 3)

MY SIMPLE QUESTION 2 : What's happening between the instruction 2 and 3 ??? is there the time for the RC to start to execute __WFI ?

I make a program who is in low power mode and sleep calling __wfi() with HFCLK stopped.

perriodicaly it wake up with the RTC. In the RTC_irq I start the HFCLK and to save power by go directly in low power mode and sleep calling __wfi(), waiting the HFCLK

and after I normaly get the HFCLKSTARTED interrupt where I can send a data by bluethoot. But I never get it. and with the debuger I'm get blocked in the "arm_startup_nrf51.s(startup)" file.

My program:

int main()
{
   initALL();
   while(true)
   {
      NRF_POWER->TASKS_LOWPWR = 1UL;
	  if(HF_Clk_Stay_On_To_Sleep == false) NRF_CLOCK->TASKS_HFCLKSTOP = 1;
      __WFI();
   }
 }

rtc_IRQ(void)
{
	 NRF_CLOCK->TASKS_HFCLKSTART = 1;          // start HFclock
     NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;       // clear clock event
	 HF_Clk_Stay_On_To_Sleep = true;
     NRF_RTC0->TASKS_CLEAR = 1UL;              // clear RTC event
     NRF_RTC0->EVENTS_COMPARE[0] = 0;          // clear RTC event
 }

HFclock_IRQ(void)
{
	HF_Clk_Stay_On_To_Sleep = false;
	Radio_Send_Data();     // send a data by radio
}

Is there something I make wrong ? if you have an idee tell me. Thank you very much for your time.

  • Hi bibi, I need to ask you if you are using external crystal oscillator? You cannot control HFCLK RC oscillator. The system manages it automatically.

    NVIC_EnableIRQ(POWER_CLOCK_IRQn); // do this in main
    
    rtc_IRQ(void)
    {
         NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;       // clear clock event
         NRF_CLOCK->TASKS_HFCLKSTART = 1;          // start HFclock
    
         HF_Clk_Stay_On_To_Sleep = true;
         NRF_RTC0->TASKS_CLEAR = 1UL;              // clear RTC event
         NRF_RTC0->EVENTS_COMPARE[0] = 0;          // clear RTC event
     }
    
    HFclock_IRQ(void)
    {
        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;       // clear clock event
        HF_Clk_Stay_On_To_Sleep = false;
        Radio_Send_Data();     // send a data by radio
    }
    

    After __wfe() the RC clock will be automatically shutdown if no other peripherals require HF RC.

    I think the problem that you face is that you are not clearing the event in HFclock interrupt. The modified code above work. Have you enabled the interrupt by the way using NVIC_EnableIRQ(POWER_CLOCK_IRQn);

  • hello Aryan, thank you for your quick response.

    so yes the POWER_CLOCK_IRQn is enabled using NVIC.

    I'm using external 16MHz crystal oscillator for HFCLK and external 32,768KHz crystal oscillator for LFCLK.

    Something I haven't anderstand in your code is why do you makewhile(NRF_CLOCK->EVENTS_HFCLKSTARTED != 1);in the rtc_IRQ ? this is to wait the HFCLK crystal to be ready, right ?

    because I make my program to sleep during the ramping up of the HF crystal.

    in the rtc_IRQ I just want to start the HF crystal but I don't want to wait until it is ready. After HF crystal is started, I want to sleep and to be waking up when the HF crystal is ready. So to be waking up by the HFclock_IRQ.

    RTC_irq job's to start HFclock and HFclk_irq job's to do something where the HFcrystal is available like sending data by radio.

    I make a little diagram to tell you more explicitly what I would like to do. (the HFclk_irq is a little bit longer than RTC because we send a data)

    RTC_irq                                                 *
    HFclk_irq                                                               ***
    
    
    Awake                                                   *               ***
    Sleeping             *********************************** ***************   ****************
    
    
    HFcrystal_ready                                                         ***
    Hfcrystal_ramping_up                                     ***************
    LFcrystal_ready      ********************************************************************** ---> [t]
    

    THANKS YOU VERY MUCH FOR YOUR ANSWERS, YOU ARE A VERY GOOD TEAM =)

  • Hi bibi,

    you are right, you do not need to wait, so i updated the program to remove the while loop.

    your program did not clear the event NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; in HFCLK_IRQ, I think that is important to do.

    HFCLK STARTED event will only happen if the clock circuit has detected an external clock signal coming into the chip. Are you sure that your XTAL oscillator is connected and working properly?

    Rest of your program logic looks good to me (except that i cannot see what initAll() does)

    Are you working on a Nordic DK or a custom board? which SDK and SD?

  • Hi bibi, Can you please update this thread with your status

Related