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

Trying to use nrfx drivers to read an analog value under ncs 1.6.0

Hello

I am following a beginners tutorial on youtube and trying to implement simplest possible example of reading an analog value.

I want to use the nrfx library to do this and I am running SES under NCS 1.6.0

It seems like the nrfx library has changed compared to the SDK version used in the tutorial and I get some strange errors when trying to compile.

#include <zephyr.h>
#include <sys/printk.h>
#include <nrfx_saadc.h>


void initialize_saadc(void) 
{
  nrfx_err_t err_code;
  
  // Configure the ADC channel as single ended (not differential) and using input pin AIN2 (P0.04)
  const nrfx_saadc_channel_t * channel_config = NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN2, 0);


  // Initialize the SAADC channel using the configuration created above
  err_code = nrfx_saadc_channel_config(channel_config);

  if (err_code == NRFX_SUCCESS) printk("SAADC Channel Configured Successfully \n");


  // Initialize the SAADC. We will use blocking mode (the processor will wait for the ADC to complete the sampling)
  err_code = nrfx_saadc_init(NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY);

  if (err_code == NRFX_SUCCESS) printk("SAADC Channel Initialized Successfully \n");
}





int main(void)
{
  nrf_saadc_value_t adc_val;

  initialize_saadc();

  while (1)
  {

  nrfx_saadc_sample_convert(0, adc_val);

   }

}

I have two main errors:

1. The Macro NRFX_SAADC_DEFAULT_CHANNEL_SE has some issues not recognizing the field values. The errors are referring to the .h file.

2. The nrfx_saadc_sample_convert function is no longer present in the documentation for the driver and is not recognized either. I'm not sure why or what the replacement is.

I would appreciate any help on this beginners question.

A reference to a simple working example would also be great.

Thanks

/Jonas

Parents Reply Children
Related