Hi everyone,
Maybe my problem has already been solved in another discussion, if so, I haven't found it yet !
I'm programming on a external board using nrf52832.
I'm developping a program based on the ble_app_rscs_ example of the SDK 14.2.
I'm trying to add saadc triggered by ppi as in the example of the SDK (peripheral -> saadc)
Here is my problem, where I try to trigger the saadc with ppi, the application get stucked and do not advertise.
But when I trigger the saadc manualy with nrf_drv_saadc_sample(), and remove those two lines :
saadc_sampling_event_init(); saadc_sampling_event_enable();
it works just fine !
So the problem comes from those two functions.
Here is my main function :
/**@brief Function for application main entry.
*/
int main(void)
{
bool erase_bonds;
//led init
nrf_gpio_cfg_output(12);
nrf_gpio_cfg_output(15);
nrf_gpio_cfg_output(17);
nrf_gpio_pin_set(12); //Green led ON
nrf_gpio_pin_set(15); //Blue led OFF
nrf_gpio_pin_set(17); //Red led OFF
// Initialize.
log_init();
timers_init();
buttons_leds_init(&erase_bonds);
ble_stack_init();
gap_params_init();
gatt_init();
advertising_init();
services_init();
sensor_simulator_init();
conn_params_init();
peer_manager_init();
//Initialize the TWI connection
twi_init();
fn_configure_LIS2DH_accelero();
//Initialize the SAADC
saadc_init();
saadc_sampling_event_init();
saadc_sampling_event_enable();
// Start execution.
NRF_LOG_INFO("Running Speed and Cadence example started.");
application_timers_start();
advertising_start(erase_bonds);
// Enter main loop.
for (;;)
{
if (NRF_LOG_PROCESS() == false)
{
power_manage();
}
}
}
I use the same saadc functions as in the nordic saadc example :
//SAADC
void timer_handler(nrf_timer_event_t event_type, void * p_context)
{
}
void saadc_sampling_event_init(void)
{
ret_code_t err_code;
err_code = nrf_drv_ppi_init();
APP_ERROR_CHECK(err_code);
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
err_code = nrf_drv_timer_init(&m_timer, &timer_cfg, timer_handler);
APP_ERROR_CHECK(err_code);
/* setup m_timer for compare event every 400ms */
uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer, 40); //Oliver : Sampling rate = 2,5Hz
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_task_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_task_addr);
APP_ERROR_CHECK(err_code);
}
void saadc_sampling_event_enable(void)
{
ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
APP_ERROR_CHECK(err_code);
}
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);
my_saadc_value = p_event->data.done.p_buffer[0];
}
}
void saadc_init(void)
{
ret_code_t err_code;
nrf_saadc_channel_config_t channel_config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN7); //NRF_SAADC_INPUT_AIN3); //FB NRF_SAADC_INPUT_AIN0);
channel_config.gain = NRF_SAADC_GAIN2; //FB change gain from 1/6 (default) to 2
err_code = nrf_drv_saadc_init(NULL, saadc_callback);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(0, &channel_config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
}
And I've included as in the saadc example :
//SAADC #define SAMPLES_IN_BUFFER 1 volatile uint8_t state = 1; static const nrf_drv_timer_t m_timer = NRF_DRV_TIMER_INSTANCE(1); static nrf_saadc_value_t m_buffer_pool[2][SAMPLES_IN_BUFFER]; static nrf_ppi_channel_t m_ppi_channel; //static uint32_t m_adc_evt_counter; nrf_saadc_value_t my_saadc_value = 0;
I've modified the sdk_config.h file in order to enable the saadc, the nrf_drv_timer1 and the ppi function.
So i don't understand wher the problem is, I suspect it to be in the ppi...
Can someone help me to solve the problem ?
Thank you,
Regards,
Olivier
