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

Any way to control wether ext. 32k XTAL works properly?

Hello all,

Our product based on nRF51 is on preproduction stage. We use both 16MHz and 32kHz external crystals. The question is: Is there any way to check programatically if 32kHz crystal soldered/soldered properly/works fine?

We noticed that on SD110 v8.0.0 device works even without external 32k crystal with software defined as

if (NRF_SUCCESS !=(err_code=sd_softdevice_enable((uint32_t)NRF_CLOCK_LFCLKSRC_XTAL_75_PPM, softdevice_assert_callback)))...

However, in that case the current consumption increased significantly. And it could cause problems in post production testing.

Best regards,

  • This might not be the best way, but it looks like the failure mode for failure to synchronize on a clock source is that the device will hang at sd_softdevice_enable(...). This can be captured to reset the system.

    If you were to set a non-volatile flag prior to calling sd_softdevice_enable, then you could check on boot if the flag is set. If it is, then you were not able to enable the SD with that clock. Otherwise, once you successfully enable the SD using that clock source, you could clear the flag.

    Of course, then there is a race condition whereby a power cut at just the wrong time could disable your low-power crystal until you reset the flag.

  • Thank you,chalecampb. However, my device become useless without softdevice. So tha main point I want to clarify is to distinct what clock used by softdevice after sd_softdevice_enable call. If external crystal is failed it seems that SD run clock from internal generator prescaled from 16Mhz crystal (so it have to be active all time in this case and this fact causes high current). If I found how to check what clock type is currently in use I will sort out devices vith failure.

  • You can always read registers that are in use by the softdevice, so you can check the LFCLKSRC register in the CLOCK peripheral to see which source is currently selected for the LFCLK.

  • If you call sd_softdevice_enable() with LFCLKSRC_XTAL and there is no external crystal, the code will be stuck waiting for the crystal to start.

    You can start a watchdog timer (WDT) before initializing the stack. This will reset the chip if a reload register is not set before a certain amount of time. In NRF_POWER->RESETREAS you can check what caused a reset. Remember that the NRF_POWER->RESETREAS register is cumulative, which means that the register is not cleared if the reset source is not power-on-reset or brown out reset. You can clear a field in the register by writing a "1" to it.

    This code will setup a watchdog:

    NRF_WDT->CRV = 32768*10;   //ten seconds
    NRF_WDT->RREN = (WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos);
    NRF_WDT->TASKS_START = 1;
    

    You have to reload it regulary to avoid resetting:

    NRF_WDT->RR[0] = 0x6E524635;
    

    Check the reset reason like this (does not clear the register value):

    if(NRF_POWER->RESETREAS & (POWER_RESETREAS_DOG_Detected <<    POWER_RESETREAS_DOG_Pos))
    {
        printf("Chip was reset by watchdog!\n");
    }
    
  • Are you sure the code works with NRF_CLOCK_LFCLKSRC_XTAL_75_PPM? It should not work for any LFCLFSRC_XTAL.

Related