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

SAADC callback

I have this working and producing good and accurate results, but I'm still puzzled by some of the examples in the SDK and the documentation.

I am using the processor to call for the saadc sample (i.e, not ppi) and I set the nrf_drv_saadc_buffer_converts immediately before hand:

err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], SAMPLES_IN_BUFFER);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], SAMPLES_IN_BUFFER);
err_code = nrf_drv_saadc_sample();

In the examples in the SDK (12) and elsewhere I also see another nrf_drv_saadc_buffer_convert call in the callback handler prior to reading the data in the buffer:

err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);

My question is what is the point of calling this again in the call back and why is the first argument p_event->data.done.p_buffer? I've read the documentation but it still doesn't make sense to me. Could anyone explain this as if they are speaking to a 5 year old?

Many thanks,

Parents Reply Children
  • there is my callback :

    void adcHandler(nrf_drv_saadc_evt_t const *p_event) { if (p_event->type == NRF_DRV_SAADC_EVT_DONE) { nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);

                adc_result = p_event->data.done.p_buffer[0];
                ptrFcnArray[0](adc_result); // Function which handles result in channel 0.
            
                adc_result = p_event->data.done.p_buffer[1];
                ptrFcnArray[1](adc_result); // Function which handles result in channel 1.           
    
                adc_result = p_event->data.done.p_buffer[2];
                ptrFcnArray[2](adc_result); // Function which handles result in channel 2.
    }
    

    }

Related