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

lfclk initialization trouble when switching between ble and esb

Hello,

In my application I want to switch between using bluetooth low energy and enhanced shockburst (esb). I have tried using the timeslot api to run both of them together, but although it works very well, waiting for available timeslots severely limits the speed at which I can send data to my esb receiver.

To get around this problem I would like to switch between protocols - that is, I want to disable the BLE protocol before enabling the ESB protocol. The problem that I am running into is that I cannot initialize the low frequency clock. Because I have the SOFTDEVICE_PRESENT flag defined but the softdevice disabled, the nrf_drv_clock_init() function throws an error.

I know that the low frequency clock is not needed to use the ESB protocol, but I need my application timers to continue to run.

I have already seen this post, but I cannot remove the SOFTDEVICE_PRESENT flag because I need to use the softdevice when I am in bluetooth mode.

I have also seen this post. This does not fix my problem either. I am already handeling the HFCLK manually. My problem is with the LFCLK.

Is it not possible to switch between BLE and ESB while still using the application timers? Is the timeslot api my only option?

I am using SDK version 11.0.0.

thanks in advance for your thoughts!

  • FormerMember
    0 FormerMember

    If the softdevice is disabled when you use ESB (you have called sd_ble_disable(..) ), it will, for the application, be the same as if the softdevice wasn't present. The tag SOFTDEVICE_PRESENT means if the softdevice is present and enabled. In your case, since the softdevice is disabled, "SOFTDEVICE_PRESENT" should be false. You should then be able to initialize the LFCLK when using ESB.

  • Thanks for the quick response! It looks like the nrf_drv_clock_init() function might not work quite the way that you describe, but your answer did lead me to what I believe will be a workable solution.

    The nrf_drv_clock_init() function raises an NRF_ERROR_SOFTDEVICE_NOT_ENABLED error if the SOFTDEVICE_PRESENT tag is defined but the softdevice is not enabled. Simply disabling the softdevice does not allow that code to execute, but this seems to be intentional.

    The key is that disabling the softdevice does not disable the LFCLK. As long as I startup in bluetooth mode before switching into ESB mode, the LFCLK will be properly configured such that it will work both when the softdevice is enabled and when it is not.

  • here is th logic in the nrf_drv_clock_init() function for reference

    #ifndef SOFTDEVICE_PRESENT
        m_clock_cb.p_lf_head      = NULL;
        m_clock_cb.lfclk_requests = 0;
        nrf_clock_xtalfreq_set(CLOCK_CONFIG_XTAL_FREQ);
        nrf_clock_lf_src_set((nrf_clock_lfclk_t)CLOCK_CONFIG_LF_SRC);
        nrf_drv_common_irq_enable(POWER_CLOCK_IRQn, CLOCK_CONFIG_IRQ_PRIORITY);
    #if CALIBRATION_SUPPORT
        m_clock_cb.cal_state = CAL_STATE_IDLE;
    #endif // CALIBRATION_SUPPORT
    #else // SOFTDEVICE_PRESENT
        uint8_t is_enabled;
        result = sd_softdevice_is_enabled(&is_enabled);
        if((result == NRF_SUCCESS) && !is_enabled)
        {
            result = NRF_ERROR_SOFTDEVICE_NOT_ENABLED;
        }
    #endif // SOFTDEVICE_PRESENT
        m_clock_cb.module_initialized = true;
        return result;
    
  • FormerMember
    0 FormerMember in reply to FormerMember

    I'm sorry that my answer was not correct, but it's good that you have found a solution. As stated in the documentation for sd_softdevice_disable(..), the "LFCLK source chosen in sd_softdevice_enable will be left running" after the softdevice has been disabled.

Related