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

SAADC oversampling callback is not working as expected

Hello All,

I have referred the reference example code to suit my needs. Below is my code,

saadc_evnt_done_flag = false;

saadc_init();

Periodic_func()
{
    saadc_sampling_trigger();
    while(!saadc_evnt_done_flag)

    {
        __WFE();
    }

    /* Some code to use the oversampled value */
}

void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
    if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
    {
        ret_code_t err_code;

        saadc_evnt_done_flag = true;

        m_adc_evt_counter++;
        printf("saadc_callback: adc-m_adc_evt_counter = %d\r\n", m_adc_evt_counter);
        err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
    }
}

Code is stuck at waiting for event. Didn't get callback with oversamping of 4x.

But in the same code, if I add 1 sec delay, callback is getting triggered after some time delay. Can someone help here.

Parents
  • Hi,

    As mentioned previously, if I add 1sec delay instead if waiting for the flag which needs to be updated in callback then callback is getting triggered.

    saadc_init();

    Periodic_func(){

    saadc_sampling_trigger();

    delay_ms(1000);

    /* Some code to use the oversampled value */

    }

    with this code, callback for done event is called from SAADC driver. So I am not able to understand, what is wrong with the previous code where I am waiting for flag event in callback fucntion?

Reply
  • Hi,

    As mentioned previously, if I add 1sec delay instead if waiting for the flag which needs to be updated in callback then callback is getting triggered.

    saadc_init();

    Periodic_func(){

    saadc_sampling_trigger();

    delay_ms(1000);

    /* Some code to use the oversampled value */

    }

    with this code, callback for done event is called from SAADC driver. So I am not able to understand, what is wrong with the previous code where I am waiting for flag event in callback fucntion?

Children
Related