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

Crystal initialization problem

I'm experimenting problems with a nRF51822 custom board. Recently I managed to run the blinky sample project. Now I'm trying to test a BLE project, but I'm having problems with my external crystal. I have the 16MHz and the 32KHz crystals (There are details of the board on a previous post here).

I was starting the 32KHz crystal with this code

NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRCCOPY_SRC_Xtal << CLOCK_LFCLKSRCCOPY_SRC_Pos);
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);

In the checking while the program get stuck. I thought that I had problems with the crystal itself, so I tried to use the 16MHz instead, with the same result.

NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
NRF_CLOCK->TASKS_HFCLKSTART = 1;	
while (!NRF_CLOCK->EVENTS_HFCLKSTARTED);

Then I tried just to simulate (By the way, I'm using Keil 5) and I was surprise to see that the code stop at the same place. I noticed that the simulation is giving constantly the following error:

*** error 65: access violation at 0x40000100 : no 'read' permission

So, if I understand well, I'm having problems to read the status of the NRF_CLOCK. What I'm doing bad? I'm missing something?

Some more information:

  1. I'm not using the softdevice.
  2. It's possible, that the board has some mistakes. It's hand made.
  3. I don't have a lot of experience with microprocessors

Thank you for your time. I'm really stuck here, don't know how to fix this.

  • An actualization. I tried to force the code, and just go ahead changing the 32kHz crystal start like this

    NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRCCOPY_SRC_Xtal << CLOCK_LFCLKSRCCOPY_SRC_Pos);
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 1;
    while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
    

    Anyway, the code get stucks in the line while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);. It is supposed to read (or write) to the address 0x40000000 (the NRF address). But the memory at 0x40000000 and after shows complete empty (only 00). I was expecting to see the peripheral data at 0x400xx000 but The debugger show only 00. I'm really very stuck here. Please help.

  • What do you mean by you are testing a BLE project, but you are not using a SoftDevice?

  • The board is the OpenBeacon Physical-Web Tag. I'm trying the example code from here. And with the library that openbeacon provide, instead of the Nordic packages (and the Softdevice). I'm really don't sure that I'm doing the right thing. Just experimenting here. (from the openbeacon site: "our beaconing firmware is implemented on the bare SoC: no annoying SoftDevice that limits your possibilities", I don't have nothing against the SoftDevice :) So, the thing is that the code get stuck in the check of the 32 kHz crystal. For now, it works commenting that line, but I'm not sure if the beacon is working with the 32 kHz crystal, or the 16 MHz cristall, or the internal one! How can I check that? Thank you!

  • I'm not familiar with the OpenBeacon code, and I'm not sure why you get the access violation. I found this, but Memory Map is not available in my Keil. You said you got blinky working, so I suggest you put the clock code into that, without any OpenBeacon code.

  • It's sound ok for me, I will try to test the crystal without the Openbeacon libraries. And for the map memory, I will leave it for another day. I really don't know where to start! Anyway thank you, I hope you will here of me today in the afternoon.

Related