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

using external oscillator

Hello, I'm using nRF52833, pca10100, s140.

I'm going to write a code using the external 32.768khz crystal to determine if the port is high/low every 0.5 seconds through rtc.

First of all, I saw the rtc example first, and it says that it uses 'internal lfclk' in the lfclk setting section.

What additional settings do I need to make to use external lfclk?

( I understand that external xtal can be used if NRFX_CLOCK_CONFIG_LF_SRC is set to 1, is this correct? )

I checked this, but I don't know how to set it up.  (Is this the only way to set the bit like this? 'NRF_CLOCK->LFCLKSRC |= (1 << 16) | (1 << 17);')



Also, after initializing like this, should I write the code by referring to the rtc example?

Thank you..

Parents
  • Hi,

    What additional settings do I need to make to use external lfclk?

    The way you use the driver is correct if you do not use a SoftDevice. There is just one additional thing. You also need to set CLOCK_CONFIG_LF_SRC to 1 (this takes precedence over NRFX_CLOCK_CONFIG_LF_SRC ). With that, the 32.768 kHz crystall oscillator (LFXO) will be started.

    If you use a SoftDevice the 32.768 kHz clock is started when the SoftDevice is enabled. In that case, you need to configure the SoftDevice to use the crystal. This is done by setting NRF_SDH_CLOCK_LF_SRC to 1 (which is also default in the SDK).

    Also, after initializing like this, should I write the code by referring to the rtc example?

    Yes, you can do that. As long as you initialize the lock as above, the crystal oscillator will be used for the LFCLK, which is then used by the RTC.

Reply
  • Hi,

    What additional settings do I need to make to use external lfclk?

    The way you use the driver is correct if you do not use a SoftDevice. There is just one additional thing. You also need to set CLOCK_CONFIG_LF_SRC to 1 (this takes precedence over NRFX_CLOCK_CONFIG_LF_SRC ). With that, the 32.768 kHz crystall oscillator (LFXO) will be started.

    If you use a SoftDevice the 32.768 kHz clock is started when the SoftDevice is enabled. In that case, you need to configure the SoftDevice to use the crystal. This is done by setting NRF_SDH_CLOCK_LF_SRC to 1 (which is also default in the SDK).

    Also, after initializing like this, should I write the code by referring to the rtc example?

    Yes, you can do that. As long as you initialize the lock as above, the crystal oscillator will be used for the LFCLK, which is then used by the RTC.

Children
  • Hi,

    I have one more question..

    I checked this, but I don't know how to set it up.  (Is this the only way to set the bit like this? 'NRF_CLOCK->LFCLKSRC |= (1 << 16) | (1 << 17);')

    This is the question I asked.

    In the table of picture, what is meaning of C 'external' part?

    I thought, 17th bit  should be set to ON to use external crystal.

    And if I need to turn on the bit, could you tell me the example code for how to do it?

    ( Should I use 'CLOCK_LFCLKSRC_EXTERNAL_Enabled' definition which is defined in 'nrf52833_bitfields.h' file? )

    Thank you. 

  • Hi,

    lyrics said:
    I checked this, but I don't know how to set it up.  (Is this the only way to set the bit like this? 'NRF_CLOCK->LFCLKSRC |= (1 << 16) | (1 << 17);')

    This is the question I asked.

    Before that you also asked:

    What additional settings do I need to make to use external lfclk?

    And the answer to that is none, as long as your sdk_config.h is correct.

    Writing to NRF_CLOCK->LFCLKSRC yourself as well as using the driver or SoftDevice to write to it makes no sense. Please refer to my initial answer.

    lyrics said:
    I thought, 17th bit  should be set to ON to use external crystal.

    No, it should be set to 0. This is only set to 1 if using an external clock (not just a crystal). See register documentation in product specification for details.

    lyrics said:
    And if I need to turn on the bit, could you tell me the example code for how to do it?

    It is not needed, and the best example code is to use either SoftDevice (then this follows from the SoftDevice configuration, and the clock is started when the SoftDevice is initialized), or use the driver as you have a code snippet for in your initial question.

Related