Hello,
My setup is pca10040, sdk 14.2, s132.
I have tried firstly the blocking mode function and it is not reacting. After that I used SAADC module in a non blocking mode. I use code part from proximity example. On every button press GPIOTE port event calls SAADC initialization, reading SAADC, uninitializing. This works fine except while advertising over BLE or connected mode. saadc_event_handler is not called when connected or advertising. What can be the problem here?
void DIGITAL_PRESS_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { if(nrf_gpio_pin_read(BUTTON_1) == BUTTONS_ACTIVE_STATE) { button press = 8; peripherals_init(); } void saadc_event_handler(nrf_drv_saadc_evt_t const * p_event) { if (p_event->type == NRF_DRV_SAADC_EVT_DONE) { uint16_t batt_lvl_in_milli_volts; uint8_t percentage_batt_lvl; uint32_t err_code; adc_result = p_event->data.done.p_buffer[0]; err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, 1); APP_ERROR_CHECK(err_code); batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) + DIODE_FWD_VOLT_DROP_MILLIVOLTS; percentage_batt_lvl = battery_level_in_percent(batt_lvl_in_milli_volts); } } void saadc_init(void) { ret_code_t err_code = nrf_drv_saadc_init(NULL, saadc_event_handler); APP_ERROR_CHECK(err_code); nrf_saadc_channel_config_t config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0); err_code = nrf_drv_saadc_channel_init(0, &config); APP_ERROR_CHECK(err_code); err_code = nrf_drv_saadc_buffer_convert(&adc_buf[0], 1); APP_ERROR_CHECK(err_code); } void peripherals_init(void) { ret_code_t err_code; saadc_init(); err_code = nrf_drv_saadc_sample(); APP_ERROR_CHECK(err_code); } void peripherals_UNinit(void) { nrf_drv_saadc_uninit(); NRF_SAADC->INTENCLR = (SAADC_INTENCLR_END_Clear << SAADC_INTENCLR_END_Pos); NVIC_ClearPendingIRQ(SAADC_IRQn); }
I perceive that code jumps on button press connected, advertising to err_code = nrf_drv_saadc_sample(); and in there to nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE); after this I do not receive any callback in saadc_event_handler.