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

Parents
  • Vincent G. said:
    Did you get any answers from your team ?

    The team has not seen this issue before. We are investigating the issue.

    But waiting more that 250µS doesn't seem to be a reliable way to detect the absence of crystal.

    We are still looking into this, but as a workaround to detect whether a crystal is mounted, we might suggest something like this:

    If LFCLKSTARTED event has not come after 1 second, conclude that no crystal is connected
    If LFCLKSTARTED event has come within 1 second, measure LFCLK frequency
    If LFCLK frequency is not "close" to 32768Hz then conclude that no crystal is connected

    The 1 second wait may be shortened, but it depends on the crystal.

  • Hi Sigurd,

    Thanks for the workaround.

    Keep me posted if you get any info about the issue from your team.

    Best regards,

    Vincent

  • Hi,

    We suspect that the noise injection on XL1(P0.00) and/or XL2(P0.01) could be enough to trigger the event EVENTS_LFCLKSTARTED, and be propagated to the clock output even if no crystal is mounted, and even if XL1/XL2 is grounded. The clock oscillator was not designed for this use-case. The behavior might vary from chip-to-chip, and seems to also depend on the noise level on VDD. 

Reply
  • Hi,

    We suspect that the noise injection on XL1(P0.00) and/or XL2(P0.01) could be enough to trigger the event EVENTS_LFCLKSTARTED, and be propagated to the clock output even if no crystal is mounted, and even if XL1/XL2 is grounded. The clock oscillator was not designed for this use-case. The behavior might vary from chip-to-chip, and seems to also depend on the noise level on VDD. 

Children
Related