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

External 32kHz crystal detection

Hi,

In my current project I have two type of boards. Some have the external 32kHz crystal mounted and some not.

I am trying to detect the presence of the external crystal by trying to start it and checking EVENTS_LFCLKSTARTED and LFCLKSTAT.

My code is the following :

    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
    __DSB();
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    __DSB();
    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
    {
    }

When the crystal is connected; the MCU wait a little in the while() and later by checking LFCLKSTAT and LFCLKSRC I have the following :

LFCLKSTAT = 65537 (Src=Xtal Stat=Running)

LFCLKSRC = 1 (Src=Xtal).

Which is the expected behavior.

The problem is when I test this on the board WITHOUT the crystal, the MCU wait several seconds  in the while and later by checking LFCLKSTAT and LFCLKSRC I have the following :

LFCLKSTAT = 65537 (Src=Xtal Stat=Running)

LFCLKSRC = 1 (Src=Xtal).

--> This is absolutely not the expected behavior.

I have also done the test on an NRF52840. And it never goes out of the while loop. And by checking LFCLKSTAT and LFCLKSRC I have the following :

LFCLKSTAT = 0x00 (Src=RC Stat=Not Running)

LFCLKSRC = 1 (Src=Xtal).

Which is expected.

Are you aware of this behavior and do you have a way to detect if a 32kHz crystal is mounted on a board with NRF52832?

I have read this ticket : https://devzone.nordicsemi.com/f/nordic-q-a/53362/how-to-check-nrf52840-external-low-frequency-crystal-32khz-is-connected-or-not

But waiting more that 250µS doesn't seem to be a reliable way to detect the absence of crystal. Especially if after some time the MCU state it is running on LFXO even if it is not mounted on the board.

Best regards,

Vincent

Related