Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Including libraries for ADC usage

Hello, I am trying to develop an application using the ADC of the nrf52832. For this, I have included the "nrfx_adc.h" library into my main code. When I try compiling the project though, I get loads of errors saying that basically every variable in the "nrf_adc.h" library (which is referenced in "nrfx_adc.h") is undefined. For reference, I tried looking up the "nrf_saadc.h" library and wanted to know where those definitions are, and apparently they are in a library called "nrf52_bitfields.h". But there's none for the variables in "nrf_adc.h"!

Are they in a different file and I am just not finding them? Can I simply use the "nrfx_saadc.h" library? I've checked the main file of the ADC sample application and there seems to be some extra methods so I don't know how much of those methods I would actually need to copy into my program?

Help would be much appreciated, thanks in advance.

  • That is true, the nrx drivers are used in the newer SDK's, but you can still use the old functions, if you add the legacy layer for the driver.

    Do you need the clock driver for the ADC? The SAADC Example uses the timer driver (which runs on the high-frequency clock) along with PPI to trigger a sample task.

  • Well, I used the "serial" example as the base for my project and added the libraries and code from the "SAADC" example. Since the serial example works with some legacy libraries, I decided to replace those with the new ones, which worked fine, except in this one case where the "nrfx_clock_init" method needs to be given an event handler while the old "nrf_drv_clock_init" doesn't.

    So I'm wondering how to go about this event handler, since the serial code doesn't work anymore now.

  • You must provide a event handler for nrfx_clock_init(..), as mentioned in the comment for the function in nrfx_clock.h:

    "Event handler provided by the user, Must not be NULL."

    If you choose to use the old functions along with the glue layer (nrf_drv_clock.c/h), this will be fixed for you "behind the scenes". However if you choose to use the nrfx functions, you should look inside nrf_drv_clock.c of how to use nrfx_clock_init(..).

Related