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

ble_app_proximity, saadc channel data

nRF5_SDK_11.0.0_89a8197\examples\ble_peripheral\ble_app_proximity

main.c

void saadc_event_handler(nrf_drv_saadc_evt_t const * p_event) {

if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
{

... adc_result = p_event->data.done.p_buffer[0];

In this example, it read adc result from p_event->data.done.p_buffer[0].

If i want use two or more adc channel. How can I read the adc result ?

Thanks!

  • Hi

    I want to point out the SAADC examples that are available on Nordic's Github. There is an example there that enables scan mode, which is multi-channel sampling. You might also want to take a look at the saadc_low_power example that shows how to use several other useful SAADC features. In the comment in the saadc_low_power example, I also try to explain how different features of the code example works.

    The SAADC is double buffered. When you call nrf_drv_saadc_buffer_convert function, you are allocating a buffer for the SAADC. When you call it twice, like done in the SAADC initialization in the saadc_low_power, then you are allocating two buffers for the SAADC. The NRF_DRV_SAADC_EVT_DONE event of the nrf_drv_saadc driver, maps to the END event specified in the nRF52832 PS, which is triggered when a SAADC buffer is full. When you receive this event, you can process the data in the buffer, meantime the SAADC samples to the second buffer. You must call the nrf_drv_saadc_buffer_convert function in the SAADC handler to again allocate another buffer before the SAADC finishes filling up the second buffer. Then the SAADC can continue sampling without interruption.

    When sampling on multiple channels, which you do by enable more than one channel (scan mode), then the SAADC will sample on all channels when you call the SAADC SAMPLE task once (by calling the nrf_drv_saadc_sample() driver function). So if you enable three channels and trigger the SAMPLE task, you will get three values in the buffer, one value for each channel. You must therefore set buffer size as a multiple of the number of channels you have enabled. If you e.g. enable 3 channels, you must have buffer size of 3, 6, 9, 12, ... . If you have buffer size of e.g. 6, then you will receive an NRF_DRV_SAADC_EVT_DONE event every second time you trigger the SAMPLE task. If you would however set buffer size to 2, and have 3 enabled channels, then the SAADC would write two values to the first buffer and one value to the second buffer, making the SAADC channel values appear like they are in random order, and the result will be hard to manage.

Related