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

nrf52 + ADC + Bluetooth problem

Hello everyone,

I've noticed that the Bluetooth and ADC work great together BUT I'm having issues when trying to turn on & off the Bluetooth.

I've tested the on & off API for the Bluetooth and they work as expected. However, when I try to switch the Bluetooth off, and then back on my firmware crashes, if the ADC is on.

I'm using nRF5_SDK_17.0.2_d674dde, the ble_peripheral/ble_app_uart and here is my code in main:

int main(void){

    user_adc_init();
    
    user_bluetooth_init();
    nrf_delay_ms(5000);
    user_bluetooth_deinit();
    nrf_delay_ms(5000);
    user_bluetooth_init();
    nrf_delay_ms(5000);
    user_bluetooth_deinit();
    nrf_delay_ms(5000);
    user_bluetooth_init();
    nrf_delay_ms(5000);
    user_bluetooth_deinit();
    nrf_delay_ms(5000);

    while(1){ }
    
}

Here is the source for the BLE API:

volatile uint32_t ble_enabled = 0;

void user_bluetooth_init(void){
	ret_code_t err;
	const nrf_clock_lf_cfg_t sd_lf_config =	{
			.source       = NRF_SDH_CLOCK_LF_SRC,
			.rc_ctiv      = NRF_SDH_CLOCK_LF_RC_CTIV,
			.rc_temp_ctiv = NRF_SDH_CLOCK_LF_RC_TEMP_CTIV,
			.accuracy     = NRF_SDH_CLOCK_LF_ACCURACY
	};
	static uint32_t first_time = 1;

	if(!ble_enabled){
		DEBUGOUT("BLE start\n");

		ble_enabled = 1;
		central_connected = 0;

		if(first_time){
			timers_init();
			ble_stack_init(first_time);
			gap_params_init();
			gatt_init();
			services_init();
			advertising_init();
			conn_params_init();
			first_time = 0;
		}
		else{
			DEBUGOUT("BLE start\n");

			err = sd_softdevice_enable(&sd_lf_config, fault_handler);
			APP_ERROR_CHECK(err);

			// Configure the BLE stack using the default settings.
			// Fetch the start address of the application RAM.
			uint32_t ram_start = 0;
			err = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
			APP_ERROR_CHECK(err);

			// Enable BLE stack.
			err = nrf_sdh_ble_enable(&ram_start);
			APP_ERROR_CHECK(err);
		}

		user_bluetooth_advertising_start();
	}
}

void user_bluetooth_deinit(void){
	if(ble_enabled){
		ble_enabled = 0;
		sd_softdevice_disable();
		DEBUGOUT("BLE stop\n");
	}
}

Here is the source for the ADC API:

void user_adc_init(void){
	nrfx_saadc_config_t adc_init_struct;
    nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5);

    adc_init_struct.resolution = NRF_SAADC_RESOLUTION_12BIT;
    adc_init_struct.oversample = NRF_SAADC_OVERSAMPLE_DISABLED ;
    adc_init_struct.interrupt_priority = 1;
    adc_init_struct.low_power_mode = 0;

    nrf_drv_saadc_init(&adc_init_struct, saadc_callback);
    nrf_drv_saadc_channel_init(0, &channel_config);
    nrf_drv_saadc_buffer_convert(m_buffer_pool, CONFIG_USER_ADC_SAMPLES_CHARGE_PUMP);
}

I could try and use direct register access, but this is a brand new project and I don't want to mess things up from the beginning. I want to use only library functions.

Regards,

L. B.

Parents Reply Children
No Data
Related