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
  • Hi,

    I was not able to reproduce this on a nRF52832DK without LF crystal.

    But, could you try to add this errata 132 delay, before starting the LFCK, and see if it fixes the issue? Similar to how it's done here.

  • Hi,

    I have just tested your fix and it doesn't change anything.

    My code :

        /* Start LFCLK with external 32kHz XTAL */
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
        NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
        __DSB();
        nrfx_clock_anomaly_132();
        NRF_CLOCK->TASKS_LFCLKSTART = 1;
        __DSB();
        while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
        {
        }

    If I hit the reset button on a board without 32kHz crystal it boot in approx. seconds.

    Also I have noticed something on boards with a crystal :

    Just after flashing, crystal startup time takes more than 250ms, between 380ms and 500ms. After reset the 32kHz crystal start in 250ms. Is this something expected ?

    Vincent

Reply
  • Hi,

    I have just tested your fix and it doesn't change anything.

    My code :

        /* Start LFCLK with external 32kHz XTAL */
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
        NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
        __DSB();
        nrfx_clock_anomaly_132();
        NRF_CLOCK->TASKS_LFCLKSTART = 1;
        __DSB();
        while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
        {
        }

    If I hit the reset button on a board without 32kHz crystal it boot in approx. seconds.

    Also I have noticed something on boards with a crystal :

    Just after flashing, crystal startup time takes more than 250ms, between 380ms and 500ms. After reset the 32kHz crystal start in 250ms. Is this something expected ?

    Vincent

Children
Related