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

Wrong UART speed with external oscillator

Hello,

This is in continuation of my previous question about the wrong UART speed. I got it working by starting the HF oscillator. However now the latest revision of our custon nrf52 board has external LF oscillator instead of xtal. I found a support question about enabling it:

devzone.nordicsemi.com/.../

And used that to enable the LF oscillator. However when using softdevice I can't put "3" as the source in to sd_softdevice_enable. If I do, the code to start HF will not work (sd_clock_hfclk_is_running returns false every time). If I use NRF_CLOCK_LF_SRC_Xtal, the UART baud rate is off by really lot: 115200 => 125000.

Thanks in advance, Petri L.

My "with sd" code is below:

   // XXXX NOTE: Not in nrf SDK!
   #define NRF_CLOCK_LF_SRC_BYPASS 3 

   // Low frequency clock source to be used by the SoftDevice
   #define NRF_CLOCK_LFCLKSRC      {.source        = NRF_CLOCK_LF_SRC_BYPASS,            \
                                 .rc_ctiv       = 0,                                \
                                 .rc_temp_ctiv  = 0,                                \
                                 .xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM}

    nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
    
    // Initialize the SoftDevice handler module.	
    SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);

    // Start HF clock    
    (void) sd_clock_hfclk_request();
    uint32_t hfclk_running=0;
    do
    {
        (void) sd_clock_hfclk_is_running(&hfclk_running);
    }
    while(!hfclk_running);

EDIT:

Here's the code that initializes the LF clock bypass:

void hardware_init(void)
{
    // Setup board clock source, LF is given by external LF oscillator 
    // see: devzone.nordicsemi.com/.../
    uint32_t clkSrc = NRF_CLOCK->LFCLKSRC;
    app_trace_log("Before: NRF_CLOCK->LFCLKSRC: 0x%08x\r\n", clkSrc);
    clkSrc |= ((1<<16) + (1<<17)); // Set BYPASS = 1, EXTERNAL = 1
    app_trace_log("After:  NRF_CLOCK->LFCLKSRC: 0x%08x\r\n", clkSrc);
    NRF_CLOCK->LFCLKSRC = clkSrc;
}
Parents Reply Children
Related