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

How to identify adc value from its adc channel?

I use nRF52840 and SDK16 with S140 softdevice. I need 3 ADC ports. The initial code as follows.

static void adc_configure(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_AIN1);

err_code = nrf_drv_saadc_channel_init(0, &config);
APP_ERROR_CHECK(err_code);

config.pin_p = NRF_SAADC_INPUT_AIN0;
err_code = nrf_drv_saadc_channel_init(1, &config);
APP_ERROR_CHECK(err_code);

config.pin_p = NRF_SAADC_INPUT_AIN4;
err_code = nrf_drv_saadc_channel_init(2, &config);
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_saadc_buffer_convert(&adc_buf[0], 1);
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_saadc_buffer_convert(&adc_buf[1], 1);
APP_ERROR_CHECK(err_code);
}

I call the function of nrf_drv_saadc_sample() once 2 seconds.  And the event handler will be called 3 times. The function of saadc_event_handler will display the channel information.

But it shows as follows: How to identify adc value from which channel? Why the channel isn't display 0/1/2?

<info> app: channel=156

<info> app: channel=158

<info> app: channel=156

void saadc_event_handler(nrf_drv_saadc_evt_t const * p_event)
{
NRF_LOG_INFO("channel=%d", p_event->data.limit.channel);

....
}

Related