use external 32MHz crystal

David.Xu gravatar image

asked 2015-04-07 09:55:45 +0200

Hi, Nordic Engineers. Now, i use a external 32mhz crystal on my board. i have add code"NRF_CLCOK->XTALFREQ = 0X00", but the BLE radio seems not work. Led flick is ok. Why? Would you like to give some advice?

edit retag flag offensive close delete report spam


I am sure after setup the external crystal selection, the register XTALFREQ is "0x00" with keil debugger.

David ( 2015-04-09 09:47:54 +0200 )editconvert to answer

3 answers

Sort by » oldest newest most voted
stefanbirnir gravatar image

answered 2015-04-15 16:38:17 +0200

updated 2016-01-14 12:16:24 +0200

Hi David

There are two registers with the name XTALFREQ, one in the CLOCK section and one in the UICR section. The purpose of the XTALFREQ in the CLOCK section is to select the high frequency crystal source, 16MHz or 32MHz. This has a reset value of 0xFF which makes the chip start the 16MHz clock by default. However, you can modify the default value in the UICR->XTALFREQ register before starting the application with the following:

nrfjprog.exe --snr <your_jlink_debugger_serial_number> --memwr 0x10001008 --val 0xFFFFFF00

This will make 32MHz crystal to be used by default instead of 16MHz crystal.

Verify that UICR address 0x10001008 is written by reading the memory content with:

nrfjprog.exe --snr <your_jlink_debugger_serial_number> --memrd 0x10001008 --n 16

Or you can include code in your SystemInit function as Locky pointed out to start 32MHz crystal instead of 16MHz crystal, something like:


What is the value of your load capacitors? For info, look at sections 3.6.1 in the nRF51822 PS v3.1 and in table 23.

Update 8.7.2015 For safe operation with 32MHz crystal, apply both of the above, i.e. write to UICR and to the NRF_CLOCK->XTALFREQ register.

Note: The chip will use 16MHz clock frequency even though 32MHz crystal is chosen. The 32MHz input frequency is divided with two before applying it to the nRF51 peripherals.

Update 14.1.2016 Also change the definition at the top of the system.nrf51.c file from

#define __SYSTEM_CLOCK      (16000000UL)


#define __SYSTEM_CLOCK      (32000000UL)

A normal application that does not use softdevice starts up using the 16MHz internal RC oscillator and does not use the external 16MHz/32MHz crystal unless it is explicitly enabled in the application code. When using softdevice, the external crystal is enabled during radio operation, as the radio requires accuracy of an external crystal. In order to test that the 32MHz crystal works you can enable it explicitly with the following code:

int main(void)
    // Set the external high frequency clock source to 32 MHz

    // Start the external high frequency crystal

    // Wait for the external oscillator to start up

    while (true) { }
edit flag offensive delete publish link more
Locky083 gravatar image

answered 2015-04-07 21:30:47 +0200

flynn gravatar image

updated 2015-06-15 10:13:43 +0200

Try this instead:


Are you sure you have the correct Loading Capacitors on the 32MHz crystal?

edit flag offensive delete publish link more
ReinhardKoe gravatar image

answered 2015-07-08 15:07:47 +0200

We experienced similar behaviours on one of our evaluation boards. The reason for this was an quite old hardware revision of the chip on the board, where there was a known bug described in the Product Anomaly Notice nRF51822-PAN v2.0 on page 16. Maybe this helps.

edit flag offensive delete publish link more


Thanks for pointing this out. The anomaly is valid for nRF51 first revision. However, writing to UICR->XTALFREQ as described above is a valid workaround for that anomaly. The anomaly does however describe an alternative workaround where you can write to UICR->XTALFREQ from code.

Stefan Birnir Sverrisson ( 2015-07-08 16:10:15 +0200 )editconvert to answer

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

User menu

    or sign up

Recent questions

Question Tools



Asked: 2015-04-07 09:55:45 +0200

Seen: 6,092 times

Last updated: Jan 14 '16