I run into problem, I think for now resolved, but questions remain: Do I have to stop BLE whenever changing ADC config?
What did not work?
// main():
ble_stack_init();
err_code = radio_notification_init(6, NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE,NRF_RADIO_NOTIFICATION_DISTANCE_5500US);
APP_ERROR_CHECK(err_code);
gap_params_init();
gatt_init();
services_init();
advertising_init();
conn_params_init();
//ADC initialised when connected:
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
uint32_t err_code;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
NRF_LOG_INFO("Connected");
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
saadc_init();
I don't know why it does not work. In ble_app_proximity example, ADC config was placed after ble_stack_init().
int main(void)
{
bool erase_bonds;
// Initialize.
log_init();
timers_init();
buttons_leds_init(&erase_bonds);
power_management_init();
ble_stack_init();
adc_configure();
gap_params_init();
gatt_init();
advertising_init();
db_discovery_init();
services_init();
conn_params_init();
peer_manager_init();
What does work (after I quit my initial assumptions and moved my ADC init before ble_stack_init():
saadc_init();
//
ble_stack_init();
The problem remains: I do not like to have unnecessary peripherals configured and risk drawing current, before deciding what to turn-on, from the app request through the BLE connection! My scenario is that after disconnection, the device will be reset and start slow advertising with minimum current drawn (avoiding painstaking turning off anything used by the app request).
case BLE_GAP_EVT_DISCONNECTED: sd_nvic_SystemReset(); //to prevent current drain