Using External 16MHz (help with code)

Hi all! I'm a beginner developer. I start my work with nrf51822, download examples e.t.c Now I try to download my code in real PCB with external 16MHz crystal. Code worked on a kit but doesnot work on a real PCB. I think this is due to incorrect CLK. If I get datasheet right, NRF have 2 CLK generator LF and HF, In my situation, HF it is external generator 16MHz and LF generator it is should be Internal RC oscillator or a synthesized 32.768 kHz clock What should I change in the code?

code in nrf_drv_config.h file:

enter code here 
#define CLOCK_CONFIG_XTAL_FREQ          NRF_CLOCK_XTALFREQ_16MHz    
#define CLOCK_CONFIG_LF_SRC             NRF_CLOCK_LF_SRC_RC
#define CLOCK_CONFIG_LF_RC_CAL_INTERVAL RC_2000MS_CALIBRATION_INTERVAL
#define CLOCK_CONFIG_IRQ_PRIORITY       APP_IRQ_PRIORITY_LOW

And what should add in main.c for activate external clock?

Thank you for your responses!)

Parents
  • FormerMember
    0 FormerMember

    No code is needed for activating the external 16 MHz crystal. When you need the crystal, it should be sufficient to just start it.

    Could you double check that the crystal on your board is mounted correctly, i.e. not shifted by 90 degrees for example?

    Which 16 MHz crystal do you use? And what is the value of the decoupling capacitors for the crystal?

    Update 28.03.2017: The attached example shows how to easily check that the HFCLK can be started. The example is made from SDK 12.2, and should be placed in the following folder: ..\nRF5_SDK_12.2.0_f012efa\examples\peripheral : clock_122023_devzone_clock_start.zip

    The code for checking that the HFCLK is starting is the following:

    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;
    
    while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
    {
    }
    
  • FormerMember
    0 FormerMember in reply to FormerMember

    R32 shuold be removed. Could you verify that the crystal is within the specifications in the Product Specification, chapter 8.1.2. Could you also double check that the value of C17 and C18 is correctly calculated according to the formula I linked to?

Reply Children
No Data
Related