This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem when switching role from peripheral to central on S120

Hi,

I am now on implementing a dynamic change between the 2 possible roles central and peripheral. I try to do this like described here: nordicsemi.com/question/35367... But when trying to switch from peripheral to central, I always get an error on the SOFTDEVICE_HANDLER_INIT() function. My ble_stack_init() function looks like this:

static uint32_t ble_stack_init(uint8_t role)
{
uint32_t err_code;
	ble_uuid128_t base_uuid = DEVICE_PERIPHERAL_BASE_UUID;

	// Initialize the SoftDevice handler module.
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL);

// Enable BLE stack 
	ble_enable_params_t ble_enable_params;
    memset(&ble_enable_params, 0, sizeof(ble_enable_params));

	if(role == BLE_GAP_ROLE_PERIPH) ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT;
	else if (role == BLE_GAP_ROLE_CENTRAL) ble_enable_params.gatts_enable_params.service_changed = false;
#ifdef S120  
  ble_enable_params.gap_enable_params.role              = role;
#endif    
	err_code = sd_ble_enable(&ble_enable_params);
    APP_ERROR_CHECK(err_code);
	
	if(role == BLE_GAP_ROLE_PERIPH)
	{
		err_code = sd_ble_uuid_vs_add(&base_uuid, &m_base_uuid_type);
		APP_ERROR_CHECK(err_code);
	}
	
	err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
	APP_ERROR_CHECK(err_code);
	
	if(role == BLE_GAP_ROLE_PERIPH)
	{
		// Register with the SoftDevice handler module for BLE events.
		err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
		APP_ERROR_CHECK(err_code);
	}
	return err_code;
}

Before I call this ble_stack_init() function, I disable the softdevice with:

err_code = sd_softdevice_disable();

SOFTDEVICE_HANDLER_INIT() returns error code 4097. For me this does not look like a valid error code. The documentation for that function says, that SOFTDEVICE_HANDLER_INIT should be called only once. So, how to achive the switch between the roles? Is there a working example with the S120 where the role is switched somewhere in the application?

Regards, BTprogrammer

Parents
  • Finally got it. There was an error when initialising some timers on another point of the project. For these timers, the wrong interrupt priority was used. This priority was reserved for the softdevice. Changed the interrupt priority and the role switching worked.

  • The error code told you that by the way. 4097 is 0x1001

    #define 	NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION   (NRF_ERROR_SDM_BASE_NUM + 1)
    
    #define 	NRF_ERROR_SDM_BASE_NUM   (0x1000)
    

    regrettably not all error codes in the SDK/softdevice are unique, but I think that one is.

Reply
  • The error code told you that by the way. 4097 is 0x1001

    #define 	NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION   (NRF_ERROR_SDM_BASE_NUM + 1)
    
    #define 	NRF_ERROR_SDM_BASE_NUM   (0x1000)
    

    regrettably not all error codes in the SDK/softdevice are unique, but I think that one is.

Children
No Data
Related