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
  • Hi,

    That video showcases the nRF5 SDK, while the nRF5340 only uses the newer nRF Connect SDK. With NCS, using the nrfx driver directly is a lot more complicated than using the zephyr api for the driver. Have you looked at the adc sample located at zephyr/samples/drivers/adc? This overlay file should get the sample working with the nrf5340dk: 8357.nrf5340dk_nrf5340_cpuapp.overlay

    Rename the file to just "nrf5340dk_nrf5340_cpuapp" if it is downloaded with a different name.

  • Hello Öivind,

    First I would like to complement all the support personnel at Nordic for your always pleasant and helpful support. I really appreciate it.

    We are using the nrf5340 in a development project at my company. It is a fantastic piece of hardware. We selected it for two reasons: 1. It has the possibility of developing custom wireless protocols. 2. It has very powerful low level peripherals.

    For 1. we are using the nrfx libraries. For 2. I am trying to do the same but it has been difficult due to the shift to Zephyr and ncs. 

    The controller I am writing for 2. will require very fast PWM response (where Zephyr level was too slow) and which I finally solved with the support from Nordic in this ticket and I would really like to keep the ADC development on the same level and not bring in Zephyr. In fact I have tried to go down further to an even lower level in this ticket 

    Many thanks!

    /Jonas

Reply
  • Hello Öivind,

    First I would like to complement all the support personnel at Nordic for your always pleasant and helpful support. I really appreciate it.

    We are using the nrf5340 in a development project at my company. It is a fantastic piece of hardware. We selected it for two reasons: 1. It has the possibility of developing custom wireless protocols. 2. It has very powerful low level peripherals.

    For 1. we are using the nrfx libraries. For 2. I am trying to do the same but it has been difficult due to the shift to Zephyr and ncs. 

    The controller I am writing for 2. will require very fast PWM response (where Zephyr level was too slow) and which I finally solved with the support from Nordic in this ticket and I would really like to keep the ADC development on the same level and not bring in Zephyr. In fact I have tried to go down further to an even lower level in this ticket 

    Many thanks!

    /Jonas

Children
Related