This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

rtc

Dear experts, please tell me, how can I switch the frequency source for the RTS from STAL to internal RC generator when the processor is running?
command sequence does not work:
NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) |
(1 << 16) | // Set bit 16 in LFCLKSRC to enable (use with rail-to-rail external source)
(1 << 17); // Set bit 17 in LFCLKSRC to enable use of external source instead of Xtal (SRC needs to be set to Xtal)

NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) ;

Thanks!

Parents
  • You need to stop the LFCLK, set the source and then start it up again.

    The LFCLK clock is stopped by triggering the LFCLKSTOP task.

    It is not allowed to write to register LFCLKSRC when the LFCLK is running.

    A LFCLKSTOP task will stop the LFCLK oscillator. However, the LFCLKSTOP task can only be triggered after the STATE field in register LFCLKSTAT indicates a 'LFCLK running' state.

    Before setting your clock source, you need to do this: 

    NRF_CLOCK->TASKS_LFCLKSTOP = 1; //stop the clock
    NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) ; //set your source
    
    NRF_CLOCK->TASKS_LFCLKSTART = 1; //start the clock again

Reply
  • You need to stop the LFCLK, set the source and then start it up again.

    The LFCLK clock is stopped by triggering the LFCLKSTOP task.

    It is not allowed to write to register LFCLKSRC when the LFCLK is running.

    A LFCLKSTOP task will stop the LFCLK oscillator. However, the LFCLKSTOP task can only be triggered after the STATE field in register LFCLKSTAT indicates a 'LFCLK running' state.

    Before setting your clock source, you need to do this: 

    NRF_CLOCK->TASKS_LFCLKSTOP = 1; //stop the clock
    NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos) ; //set your source
    
    NRF_CLOCK->TASKS_LFCLKSTART = 1; //start the clock again

Children
Related