How to enable the external 32MHZ crystal oscillator through the internal capacitor

I'm using a custom development board and I want to enable timer 0 through the external 32MHZ crystal oscillator. Here is my configuration:

prj.config:
# Enable the UART driver
CONFIG_CLOCK_CONTROL=y
CONFIG_CLOCK_CONTROL_NRF=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
CONFIG_SOC_ENABLE_LFXO=n
CONFIG_SOC_HFXO_CAP_INTERNAL=y
CONFIG_SOC_HFXO_CAP_INT_VALUE_X2=24
app.overlay:
&hfxo {
    status = "okay";
    load-capacitors = "internal";
    load-capacitance-femtofarad = <15000>; 
};

&timer0 {
    compatible = "nordic,nrf-timer";
    status = "okay";
    label = "MY_TIMER0";
    interrupts = <15 NRF_DEFAULT_IRQ_PRIORITY>;
    prescaler = <0>;
};

main.c:
void my_hfclk_start(void)
{
    struct onoff_manager *mgr =
        z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF);

    __ASSERT_NO_MSG(mgr != NULL);

    sys_notify_init_callback(&hfclk_cli.notify, hfclk_on_callback);

    int ret = onoff_request(mgr, &hfclk_cli);
    __ASSERT_NO_MSG(ret >= 0);
}
   if (NRF_CLOCK->HFCLKSTAT & CLOCK_HFCLKSTAT_STATE_Msk) {
            if (NRF_CLOCK->HFCLKSRC & CLOCK_HFCLKSRC_SRC_Msk) {
                printk("HFCLK source is HFXO\n");
            } else {
                printk("HFCLK source is HFINT (16 MHz)\n");
            }
        } else {
            printk("HFCLK is not running\n");
        }
        uint32_t prescaler = NRF_TIMER0->PRESCALER;
        printk("TIMER0 PRESCALER: %u\n", prescaler);
        uint32_t freq = counter_get_frequency(counter_dev);
        printk("Counter frequency: %u Hz\n", freq);
The printing result is:
HFCLK source is HFXO
TIMER0 PRESCALER: 0
Counter frequency: 16000000 Hz
I really can't find the cause of the problem, I'm using NCS V3.1.0.

 

Parents Reply Children
Related