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

SAADC issue with nRF52

SDK version: nRF5_SDK_15.0.0_a53641a

Softdevice version: s132_nrf52_6.0.0_softdevice

PDK: PCA10040

I am trying to read the ADC pin value using the SAADC module, I have softdevice enabled and running. I am adding the section of code for your reference. I find that the value being read seems to be random. For example, if I apply a signal on the pin, the value still remains the same, with or without the signal. Similary if I apply ground to the pin, still no change. I think that the pin is actually not being sampled. Any help to resolve this appreciated.  Also I find the saadc_callback function is never triggered.

void sensor_mngr_init()
{
      uint32_t err_code;

     nrf_saadc_channel_config_t channel_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);
     err_code = nrf_drv_saadc_init(NULL, saadc_callback);
     APP_ERROR_CHECK(err_code);
     channel_config.gain = NRF_SAADC_GAIN1_2;

     err_code = nrf_drv_saadc_channel_init(0, &channel_config);
     APP_ERROR_CHECK(err_code);

}


void get_sensor_data(sensor_data_struct *p_sensor_data)
{
     nrf_saadc_value_t analog_value;
     nrfx_err_t err_code;

     err_code = nrfx_saadc_sample_convert(0,&analog_value);

}

sdk_config:

#ifndef SAADC_ENABLED
#define SAADC_ENABLED 1
#endif

#ifndef NRFX_SAADC_ENABLED
#define NRFX_SAADC_ENABLED 1
#endif

#ifndef NRFX_SAADC_CONFIG_RESOLUTION
#define NRFX_SAADC_CONFIG_RESOLUTION 1
#endif

#ifndef NRFX_SAADC_CONFIG_OVERSAMPLE
#define NRFX_SAADC_CONFIG_OVERSAMPLE 0
#endif

#ifndef NRFX_SAADC_CONFIG_LP_MODE
#define NRFX_SAADC_CONFIG_LP_MODE 0
#endif

#ifndef NRFX_SAADC_CONFIG_IRQ_PRIORITY
#define NRFX_SAADC_CONFIG_IRQ_PRIORITY 7
#endif

#ifndef NRFX_SAADC_CONFIG_LOG_ENABLED
#define NRFX_SAADC_CONFIG_LOG_ENABLED 0
#endif

#ifndef NRFX_SAADC_CONFIG_LOG_LEVEL
#define NRFX_SAADC_CONFIG_LOG_LEVEL 3
#endif

#ifndef NRFX_SAADC_CONFIG_INFO_COLOR
#define NRFX_SAADC_CONFIG_INFO_COLOR 0
#endif

#ifndef NRFX_SAADC_CONFIG_DEBUG_COLOR
#define NRFX_SAADC_CONFIG_DEBUG_COLOR 0
#endif

Parents
  • Does your nrfx_saadc_sample_convert() ever return, or does it hang there forever?

     

    If it returns, and you get a new (but random) value whenever you call it, are you sure that you are measuring on the correct pin? AIN0 is pin P0.02.

     

    Have you tested the saadc example found in SDK15\examples\peripheral\saadc? Here the callback function should be called, but it is not called before it has received 5 measurements, since the size of the saadc-buffer is 5. What is the size of your saadc-buffer?

     

    Best regards,

    Edvin

Reply
  • Does your nrfx_saadc_sample_convert() ever return, or does it hang there forever?

     

    If it returns, and you get a new (but random) value whenever you call it, are you sure that you are measuring on the correct pin? AIN0 is pin P0.02.

     

    Have you tested the saadc example found in SDK15\examples\peripheral\saadc? Here the callback function should be called, but it is not called before it has received 5 measurements, since the size of the saadc-buffer is 5. What is the size of your saadc-buffer?

     

    Best regards,

    Edvin

Children
  • Hi Edwin,

      Thank you for your response. I do receive a random value whenever I call it, it does not hang.

       Maybe my pin is wrong, I was measuring pin marked as P0.03 (A0). On the board PCA10040 (1.2.4 2018.16) board that I have I find that  A0 to A5 are on P8 header. I dont see P0.02 on the board. Can you please clarify if P0.03 (A0) is correct?

       I have not yet tried the SDK15\examples\peripheral\saadc mainly because I was trying to get simple version of the SAADC blocking working with my softdevice code before I try out the non-blocking with SAADC-buffer.

  • Hi Edwin,

        I verified once more and found what you said to be right. I had the wrong pin. When I connected P0.02 (AREF) to GND I did see the value going down to zero and go up when I connected the pin to VDD. Thank you for clarifying. I consider this issue resolved.

Related