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

HFCLKSTAT and an external crystal

I've got a custom board here, the debugger is reporting that HFCLKSTAT is 0x00010000. Which I think is translating as using the RC oscillator rather than the external crystal. Any suggestions on what to check?

Parents
  • Hi Jim,

    you're right. HFCLKSTAT value of 0x00010000 indicates that the internal 16 MHz RC oscillator is generating the 16 MHz clock. To use the external 16 MHz crystal as the 16 MHz clock source instead, you can trigger the HFCLKSTART task. Note that the CLOCK peripheral is blocked by the softdevice when the softdevice is enabled. After the crystal has started (startup time can vary) HFCLKSTAT should change to 0x00010001.

    The following code can be used to start the clock and make sure it's running:

    NRF_GPIO->DIRSET = (1 << DEBUG_PIN); // Use LED or other accessible pin if you want to observe the application state
    NRF_GPIO->OUTCLR = (1 << DEBUG_PIN); 
    
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART    = 1;
    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
    {
        // Wait for started event to occur. Note: will spin forever if crystal isnt working
        __NOP();
    }
    
    // 16 MHz XTAL has now started
    NRF_GPIO->OUTSET = (1 << DEBUG_PIN); 
    
Reply
  • Hi Jim,

    you're right. HFCLKSTAT value of 0x00010000 indicates that the internal 16 MHz RC oscillator is generating the 16 MHz clock. To use the external 16 MHz crystal as the 16 MHz clock source instead, you can trigger the HFCLKSTART task. Note that the CLOCK peripheral is blocked by the softdevice when the softdevice is enabled. After the crystal has started (startup time can vary) HFCLKSTAT should change to 0x00010001.

    The following code can be used to start the clock and make sure it's running:

    NRF_GPIO->DIRSET = (1 << DEBUG_PIN); // Use LED or other accessible pin if you want to observe the application state
    NRF_GPIO->OUTCLR = (1 << DEBUG_PIN); 
    
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART    = 1;
    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
    {
        // Wait for started event to occur. Note: will spin forever if crystal isnt working
        __NOP();
    }
    
    // 16 MHz XTAL has now started
    NRF_GPIO->OUTSET = (1 << DEBUG_PIN); 
    
Children
Related