Hello,
I am developing a system that samples 3 independent data using SSADC. since the timing was important in my system, I decided to use PPI to trigger the SSADC. However, I am countering a very weird problem. When I receive data from the phone by BLE, The order of the sample data changes(if data order was Ain0 Ain 1 Ain2 in terms of data send array it changes to something like Ain2 Ain0 Ain1) I checked the application side and I don't see a problem. Is there a possible reason why this problem is occurring? Is this a bug or is there a solution? In my system, I am using Timeslot+esb to get one additional data from my slave device. Other than that nothing else is going on in the system.
There are the segmentations of my code ( Basically the Example provided)
void saadc_init(void)
{
ret_code_t err_code;
nrf_drv_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
saadc_config.resolution = NRF_SAADC_RESOLUTION_8BIT;
nrf_saadc_channel_config_t channel_0_config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN4);
channel_0_config.gain = NRF_SAADC_GAIN1_4;
channel_0_config.reference = NRF_SAADC_REFERENCE_VDD4;
nrf_saadc_channel_config_t channel_1_config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5);
channel_1_config.gain = NRF_SAADC_GAIN1_4;
channel_1_config.reference = NRF_SAADC_REFERENCE_VDD4;
nrf_saadc_channel_config_t channel_2_config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6);
channel_2_config.gain = NRF_SAADC_GAIN1_4;
channel_2_config.reference = NRF_SAADC_REFERENCE_VDD4;
err_code = nrf_drv_saadc_init(&saadc_config, saadc_callback);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(0, &channel_0_config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(1, &channel_1_config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(2, &channel_2_config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0],SAADC_SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1],SAADC_SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
}
And
void saadc_sampling_event_init(void)
{
ret_code_t err_code;
err_code = nrf_drv_ppi_init();
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_timer_init(&m_timer, NULL, timer_handler);
APP_ERROR_CHECK(err_code);
/* setup m_timer for compare event */
uint32_t ticks = nrf_drv_timer_us_to_ticks(&m_timer, 800);
nrf_drv_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);
nrf_drv_timer_enable(&m_timer);
uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&m_timer, NRF_TIMER_CC_CHANNEL0);
uint32_t saadc_sample_event_addr = nrf_drv_saadc_sample_task_get();
/* setup ppi channel so that timer compare event is triggering sample task in SAADC */
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel, timer_compare_event_addr, saadc_sample_event_addr);
APP_ERROR_CHECK(err_code);
}
And
void saadc_sampling_event_enable(void)
{
ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
APP_ERROR_CHECK(err_code);
}
And
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;
// set buffers
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
for (int i = 0; i < 3; i++)
{
value[i+counter*4] = p_event->data.done.p_buffer[i];
}
value [3+4*counter] = esb;
counter++;
}
}
Thank you,