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

saadc_init fails with NRFX_ASSERT generated from err_code = nrf_drv_saadc_channel_init(0, &channel_config)

I am using SDK 15.3, SES 4.3 and SD 130.  I've added the saadc example code into my code which is comprised of the ble_central, nordic UART and saadc.

I've changed the timer instance from 0 to 1 and 2 because of the softdevice:

static const nrf_drv_timer_t m_timer = NRF_DRV_TIMER_INSTANCE(1);

#define SAMPLES_IN_BUFFER 5
volatile uint8_t state = 1;

static const nrf_drv_timer_t m_timer = NRF_DRV_TIMER_INSTANCE(1); // Eric - changed from 0 to 1 since 0 is used by SD
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;

//  APP_TIMER_DEF(saadc_timer);   // Eric - added this line. Code doesn't seem matter.
void saadc_timer_handler(nrf_timer_event_t event_type, void *p_context) {
  saadc_callback();
  printf("saadc timer timed out");
}

I thought that the app_timers used timer instance 1 and they are working fine. I've also tried timer instance 2 but it didn't solve anything.  

Please tell me what I am missing here.

  • Additional info:

    The error is generated in line 10 below.  This corresponds to line 297 of nrfx_saadc.c.

    nrfx_err_t nrfx_saadc_channel_init(uint8_t                                  channel,
                                       nrf_saadc_channel_config_t const * const p_config)
    {
        NRFX_ASSERT(m_cb.state != NRFX_DRV_STATE_UNINITIALIZED);
        NRFX_ASSERT(channel < NRF_SAADC_CHANNEL_COUNT);
        // Oversampling can be used only with one channel.
        NRFX_ASSERT((nrf_saadc_oversample_get() == NRF_SAADC_OVERSAMPLE_DISABLED) ||
                    (m_cb.active_channels == 0));
        NRFX_ASSERT((p_config->pin_p <= NRF_SAADC_INPUT_VDD) &&
                    (p_config->pin_p > NRF_SAADC_INPUT_DISABLED));
        NRFX_ASSERT(p_config->pin_n <= NRF_SAADC_INPUT_VDD);
    
        nrfx_err_t err_code;
    

  • Hi,

    How did you declare channel_config? If you get an assert on line 10 of the code snippet you posted, the analog input is not set correctly in the config struct.

    Best regards,
    Jørgen

  • Hi Jorgen,

    I set the analog input as follows:

    #define SYS_V 30 // pin #42 - P0.30/AIN6 - P2

    // Set up Sys_V as standard input w/ no pullup.
    nrf_gpio_cfg_input(SYS_V, NRF_GPIO_PIN_NOPULL);

    void saadc_init(void) {
    ret_code_t err_code;
    nrf_saadc_channel_config_t channel_config =
    NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(SYS_V); // PS uses SYS_V (Pin 30-AIN6) for Sys_Pwr monitoring

    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);
    // We only want to sample when we need the voltage info... Not continually

    saadc_sampling_event_enable();
    NRF_LOG_INFO("SAADC HAL simple example started.");

  • The SAADC does not take a GPIO pin number as input, you need to use one of the pins in the nrf_saadc_input_t enum. In your case, that should be NRF_SAADC_INPUT_AIN6.

Related