hello Nordic
i am working with the nrf52840 , sdk 16.0, s140
i am using the peripheral ble_app_blinky example as a base
i added saadc and twi, (spi and uart will be added later)
i palne to sample the saadc at high frequency (32kHz) so i need to be using the nrf _drv_timer, i have some other counters in the system which i will use the app_timer for them because the lfclk is fine for them
the flow is do the sampling first and then do the connection of the ble, they will not work simultaneously.
i get a fault in the "nrf_drv_timer_init() function.. specificaly it falls in the following line in the "nrfx_timer.c" file
for (i = 0; i < p_instance->cc_channel_count; ++i)
{
nrf_timer_event_clear(p_instance->p_reg,
nrf_timer_compare_event_get(i));
}
i am not sure why ???
i added my saadc init as well if it may help (all the initiations of the ble is untouched and remain as they are in the sample (just moved it to a different module to clear my main.c a bit)
{
ret_code_t err_code;
nrf_drv_saadc_config_t saadc_config;
nrf_saadc_channel_config_t channel_config_0;
nrf_gpio_cfg_output(ARDUINO_13_PIN); // FOR DEBUG
//Configure SAADC
saadc_config.resolution = NRF_SAADC_RESOLUTION_14BIT; //Set SAADC resolution to 12-bit. This will make the SAADC output values from 0 (when input voltage is 0V) to 2^12=2048 (when input voltage is 3.6V for channel gain setting of 1/6).
saadc_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED; //DIABLED - //Set oversample to 4x. This will make the SAADC output a single averaged value when the SAMPLE task is triggered 4 times.
saadc_config.interrupt_priority = APP_IRQ_PRIORITY_LOW; //Set SAADC interrupt to low priority.
saadc_config.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE;
//Configure SAADC channels:
channel_config_0.reference = NRF_SAADC_REFERENCE_VDD4; //Set internal reference of fixed 0.6 volts
channel_config_0.gain = NRF_SAADC_GAIN1_4; //Set input gain to 1/6. The maximum SAADC input voltage is then 0.6V/(1/6)=3.6V. The single ended input range is then 0V-3.6V
channel_config_0.acq_time = NRF_SAADC_ACQTIME_10US; //Set acquisition time. Set low acquisition time to enable maximum sampling frequency of 200kHz. Set high acquisition time to allow maximum source resistance up to 800 kohm, see the SAADC electrical specification in the PS.
channel_config_0.mode = NRF_SAADC_MODE_SINGLE_ENDED; //Set SAADC as single ended. This means it will only have the positive pin as input, and the negative pin is shorted to ground (0V) internally.
channel_config_0.resistor_p = NRF_SAADC_RESISTOR_DISABLED; //Disable pullup resistor on the input pin
channel_config_0.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
channel_config_0.burst = NRF_SAADC_BURST_ENABLED;
err_code = nrf_drv_saadc_init(&saadc_config, saadc_callback);
APP_ERROR_CHECK(err_code);
channel_config_0.pin_p = AUDIO_PIEZO_ADC_INPUT_PIN;
err_code = nrf_drv_saadc_channel_init(0, &channel_config_0);
APP_ERROR_CHECK(err_code);
channel_config_0.pin_p = AUDIO_MIC_ADC_INPUT_PIN;
err_code = nrf_drv_saadc_channel_init(1, &channel_config_0);
APP_ERROR_CHECK(err_code);
channel_config_0.pin_p = AUDIO_PIEZO_ADC_INPUT_PREAMPLYFIER_INPUT_PIN;
err_code = nrf_drv_saadc_channel_init(2, &channel_config_0);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], CONVERTED_ADC_SAMPELS_BUFF_SIZE);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], CONVERTED_ADC_SAMPELS_BUFF_SIZE);
APP_ERROR_CHECK(err_code);
// samling event configurations - set ppi:
err_code = nrf_drv_ppi_init();
APP_ERROR_CHECK(err_code);
// samling event configurations - set timer:
sd_clock_hfclk_request();
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32; // ?? WHAT IS THIS WIDTH ??
err_code = nrf_drv_timer_init(&m_timer, &timer_cfg, NULL); //timer_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, TICS_FOR_32KHZ, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);
nrf_drv_timer_enable(&m_timer);
// samling event configurations - get handlers address:
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();
// samling event configurations - ppi timer event to start saadc sampling:
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);
hope to read from you soon
best regards
Ziv