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

Problem with crystal and custom board

Hi, i build my own custom board with a NRF52832, i'm having problem with the softdevice (i think so)... my code is base on BLE s132 central and peripheral...

I developed the code and test on a NRF52 DK and it worked all right, everything was ok..

I test a simple code (toggle Leds) in my custom board and it worked ok (No softdevice)

I load the softdevice s130 and the code (central device) and my custom board get reset and start again.. I can see when the scanning led turn on and inmediatily restart and start again..

I'm going to paste my init code. Hope you can help me.

MAIN:

    int main(void)
    {
    
    	  entrada3=1;
    	  entrada4= 1;
    
        ret_code_t err_code;
  
        leds_init();
    	         
   
    		ble_stack_init();
    	 
        setear_direccion_central();
   
        db_discovery_init();
   	
    	  nus_c_init();
    		
   // Start scanning for peripherals and initiate connection to devices which
       scan_start();
     	for (;;)
    	{
    		// Wait for BLE events.
    			power_manage();
    				 }			 
    	
        }

BLE_STACK_INIT()

static void ble_stack_init(void)
{
   ret_code_t err_code;

    nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
    // Initialize the SoftDevice handler module.
	
	// THE CODE STOPS WHEN THE LINE DOWN is EXCECUTED.

    SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);

    ble_enable_params_t ble_enable_params;
    err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT,
                                                    PERIPHERAL_LINK_COUNT,
                                                    &ble_enable_params);
    APP_ERROR_CHECK(err_code);

    //Check the ram settings against the used number of links
    CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT,PERIPHERAL_LINK_COUNT);

    // Enable BLE stack.
    err_code = softdevice_enable(&ble_enable_params);
	    APP_ERROR_CHECK(err_code);

    // Register with the SoftDevice handler module for BLE events.
    err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
	    APP_ERROR_CHECK(err_code);
}

NRF_CLOCK_LFCLKSRC:

#define NRF_CLOCK_LFCLKSRC      {.source        = NRF_CLOCK_LF_SRC_XTAL ,            \
                                 .rc_ctiv       = 0,                                \
                                 .rc_temp_ctiv  = 0,                                \
                                 .xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM}

SCAN_START()

static void scan_start(void)
{
	  scantime++;
	  
    ret_code_t err_code;
    int8_t tx_power =-40;
    err_code =	sd_ble_gap_scan_stop();
		
    // It is okay to ignore this error since we are stopping the scan anyway.
    if (err_code != NRF_ERROR_INVALID_STATE)
    {
        APP_ERROR_CHECK(err_code);
    }
    sd_ble_gap_tx_power_set(tx_power);
		
    err_code = sd_ble_gap_scan_start(&m_scan_param);
		APP_ERROR_CHECK(err_code);
			
		led_scanning();

}

image description

  • Why do you say 'crystal' in the title? Do you suspect the crystal? Single step into that function and find out what's returning an error, or put a breakpoint into the error handler and find out why you're getting there and what function is returning an error code.

    Can you start the LF and HF crystals? You just need to connect up a JLink and write the registers and check they start. I had problems with one of my boards because I had a bad connection and the HF crystal wouldn't start.

  • i said crystal because i have read that to use softdevice i need the 32.768khz crystal and maybe the problem is with the softdevice... Look the las function that the program runs is

    err_code = sd_ble_gap_scan_start(&m_scan_param);
    		APP_ERROR_CHECK(err_code);
    

    i check it with a led and the value of err_code is NRF_SUCCESS so it was success the central started to scanning but just when this instruction finish, the code restart.

  • but you have a 32kHz crystal in your schematic so why did you think that was the problem? You don't need one, but if you don't have one you need to change the code, but you do have one so that's not the problem. You could however change the LF source to calibrated RC and see if the board starts that way, which might tell you if you have a problem with the crystal that you have.

    You need to work out which function is returning an error code. Attach a debugger to it, you really can't debug things like this with LEDs and guesswork.

  • ok, can you tell which lines in detail i have to change to use RC oscillators? do i have to desoldering the crystal or i can use RC even the crystal is connected to the board?

  • change the LF_CLOCK_LFSOURCE and no you don't need to desolder it.

1 2