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

An error with NRF_SAADC_CHANNEL_COUNT define

Hi

I am using the SDK 15.2.0 and developing for a NRF52832 using Segger.

I have a problem with the define NRF_SAADC_CHANNEL_COUNT in "nrf_saadc.h". It is set to 8.

The enum defining the channels e.g "NRF_SAADC_INPUT_AIN7" is defined as value 8. The "NRF_SAADC_INPUT_VDD" is defined with value 9.

The problem is that the asserts in nrfx_saadc.c is written as "channel < NRF_SAADC_CHANNEL_COUNT".

Am I looking wrong at this or is this a mistake in the driver?

Hope you can help Slight smile

Best regards
Mikkel

  • Hello,

    The NRF_SAADC_CHANNEL_COUNT is not compared to the pin number in the channel config. It is compared to the channel, so this shouldn't be a problem.

    Check out how it is set up in the examples\peripheral\saadc example:

        nrf_saadc_channel_config_t channel_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);
        // this does:
        // channel_config.pin_p = NRF_SAADC_INPUT_AIN0;
            
        err_code = nrf_drv_saadc_init(NULL, saadc_callback);
        APP_ERROR_CHECK(err_code);
    
        // Init channel 0:
        err_code = nrf_drv_saadc_channel_init(0, &channel_config);
        APP_ERROR_CHECK(err_code);
        
        // nrf_drv_saadc_channel_init(ch, config)
        //it is "ch" that is compared with NRF_SAADC_CHANNEL_COUNT. ch should not contain your pin number.
        

    So the channels you have to keep track of yourself. If you want to use NRF_SAADC_INPUT_VDD:

    channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_VDD);

    nrf_drv_saadc_channel_init(ch_num, &channel_config);

    Now the pin number is stored in channel_config, but the channel number has to be a number between 0 and 7, since this is how many physical channels the ADC has.

    Best regards,

    Edvin

  • Hi Edvin

    Thank you for the answer. Ahh I do now understand.
    So that the ch_num should just be any number between 0-7 that I keep track of myself.

    I though that the AINx was the channel number, and that exceeded the 8 channels. So that was confusing.

Related