# use external 32MHz crystal

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

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 close delete

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

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

Sort by » oldest newest most voted

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

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:

NRF_CLOCK->XTALFREQ = 0xFFFFFF00;


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)


to

#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
NRF_CLOCK->XTALFREQ = 0xFFFFFF00;

// Start the external high frequency crystal
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;

// Wait for the external oscillator to start up
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {}

while (true) { }
}

more

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

NRF_CLOCK->XTALFREQ &= 0xFFFFFF00;

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

more

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

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.

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.

( 2015-07-08 16:10:15 +0100 )editconvert to answer

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

[hide preview]

## Recent blog posts

• ### Difference between nRF52840 Engineering A and B reference designs

Posted 2018-01-15 12:27:08 by Martin Børs-Lind
• ### [For Hire] Expert development services of custom Hardware devices | IoT solutions | Mobile Apps

Posted 2018-01-15 09:08:42 by Ilya Surinsky
• ### Rust bindings to nrf52 series

Posted 2018-01-12 23:23:07 by Coleman McFarland
• ### Show And Tell: Poly - Building an RC Airplane The Hard Way

Posted 2018-01-05 01:17:57 by Daniel Veilleux
• ### Bluetooth on a desktop computer (Windows, Mac, Linux)

Posted 2018-01-04 17:56:57 by kbaud

## Recent questions

• ### System off draws more then 80µA

Posted 2018-01-22 22:15:19 by ruetten
• ### How to add driver to an SDK example, in Segger Embedded Studio?

Posted 2018-01-22 21:37:18 by Mark Leavitt
• ### Send more than 60 characters with each call to ble_nus_string_send

Posted 2018-01-22 21:20:21 by fkoran
• ### DFU succeeds but flash is erased

Posted 2018-01-22 20:42:54 by brett_anderson
• ### Uart example stops blinking after a while

Posted 2018-01-22 19:56:29 by oliverpoc

## Stats

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

Seen: 6,688 times

Last updated: jan. 14 '16