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

SAADC and S140 - NRF PDK

My code hit weak handler when I try to modify the examples/peripheral/saadc to run with softdevice s140 on nrf82840 PDK. All I did was adding a BLE Stack initialization before calling saadc_init, saadc_sampling_event_init and saadc_sampling_event_enable. With DEBUG enabled it looks like the code is failing at nrf_drv_timer_init but not information is given through log utility.

Here is the ble_stack_init:

static void ble_stack_init(void)
{
    uint32_t err_code;

    nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;

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

    ble_enable_params_t ble_enable_params;
    err_code = softdevice_enable_get_default_config(NRF_BLE_CENTRAL_LINK_COUNT,
            NRF_BLE_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(NRF_BLE_CENTRAL_LINK_COUNT, NRF_BLE_PERIPHERAL_LINK_COUNT);

    // Enable BLE stack.
    ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_GATT_MAX_MTU_SIZE;

    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);

    // Register with the SoftDevice handler module for System events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
}

and the main function:

int main(void)
{
    ret_code_t err_code;

    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_INFO("Initializing BLE stack\r\n");

    ble_stack_init();

    saadc_init();
    saadc_sampling_event_init();
    saadc_sampling_event_enable();

    while (1)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            sd_app_evt_wait();
        }
    }
}

It's most likely something related to interruption priorities or resources taken by SD. I use SDK 12.

EDIT: I also should mention that I like the approach with PPI (Timer -> SAADC), so that timer triggers adc sampling task and in the result I have a continuous sampling with some specified interval (miliseconds).

Related