Hi Devzone:
I have 1 differential pair and 1 single ended pin I want to read, so I wrote code below into saadc_init function:
nrf_saadc_channel_config_t channel_config_IMON =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN4); //SINGLE END
nrf_saadc_channel_config_t channel_config_VBAT
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_DIFFERENTIAL(NRF_SAADC_INPUT_AIN3, NRF_SAADC_INPUT_AIN2); //DIFFERENTIAL
In this case AIN4 is the single ended pin and AIN2 and AIN3 are the differential pair.
I'm not quite sure how to get ADC values respectively in saadc_callback function.
Here is the function code from the example project.
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;
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
int i;
NRF_LOG_INFO("ADC event number: %d", (int)m_adc_evt_counter);
for (i = 0; i < SAMPLES_IN_BUFFER; i++)
{
NRF_LOG_INFO("%d", p_event->data.done.p_buffer[i]);
}
m_adc_evt_counter++;
}
}
My question is:
1. what value do I need to set for SAMPLES_IN_BUFFER since we have one differential pair and one single ended pin? 2 or 3?
2. in the for loop
for (i = 0; i < SAMPLES_IN_BUFFER; i++)
what value is being printed out by
NRF_LOG_INFO("%d", p_event->data.done.p_buffer[i]);
?
Is it with i=0, it is printing out the differential channel and when i=1 the single ended channel is being printed out?
Thank you.