nrfx 4.5.0
Loading...
Searching...
No Matches
SAADC simple blocking

SAADC simple blocking

The sample demonstrates a simple functionality of the nrfx_saadc driver operating in the blocking mode.

Requirements

The sample supports the following development kits:

Board Support
nrf52dk_nrf52832 Yes
nrf52833dk_nrf52833 Yes
nrf52840dk_nrf52840 Yes
nrf5340dk_nrf5340 Yes
nrf54l15dk_nrf54l15 Yes
nrf9160dk_nrf9160 Yes

Overview

Application initializes the nrfx_saadc driver and starts operating in the blocking mode. Program works as a simple state machine and starts in state m_current_state == STATE_SINGLE_CONFIG. In this state the following configurations apply:

  • STATE_SINGLE_CONFIG - SAADC driver is configured to work with only one channel ( m_single_channel ) in the blocking mode. Afterward, m_current_state changes to STATE_SINGLE_SAMPLING.
  • STATE_SINGLE_SAMPLING - sampling on a single channel ( m_single_channel ) is performed specified number of times ( SAMPLING_ITERATIONS ), and then m_current_state changes to STATE_MULTIPLE_CONFIG.
  • STATE_MULTIPLE_CONFIG - SAADC driver is configured to work with multiple channels ( m_multiple_channels ) in the blocking mode. Afterward, m_current_state changes to STATE_MULTIPLE_SAMPLING.
  • STATE_MULTIPLE_SAMPLING - sampling on multiple channels ( m_multiple_channels ) is performed specified number of times ( SAMPLING_ITERATIONS ).

Before every sampling a calibration in the blocking manner is performed. Sampling is then invoked by the nrfx_saadc_mode_trigger() function.

In the sample there are GPIOTE tasks configured to toggle the specified ( m_out_pins ) loopback pins. Those tasks are triggered between successive samplings to verify the functionality of the SAADC on the nonconstant analog signal.

‍For more information, see SAADC driver - nrfx documentation.

Wiring

To run the sample correctly, connect pins as follows:

  • LOOPBACK_PIN_1A with LOOPBACK_PIN_1B,
  • LOOPBACK_PIN_2A with LOOPBACK_PIN_2B,
  • LOOPBACK_PIN_3A with LOOPBACK_PIN_3B.

Building and running

To run this sample, build it for the appropriate board and then flash it as per instructions in Building and running section.

Sample output

You should see the following output:

- "Starting nrfx_saadc simple blocking example."
- "Single channel SAADC test."
- "Calibration in the blocking manner finished successfully."
- "Sampling 1 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 2 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "Calibration in the blocking manner finished successfully."
- "Sampling 3 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 4 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "Calibration in the blocking manner finished successfully."
- "Sampling 5 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 6 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "Calibration in the blocking manner finished successfully."
- "Sampling 7 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 8 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "Multiple channels SAADC test."
- "Calibration in the blocking manner finished successfully."
- "Sampling 1 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "[CHANNEL 1] Sampled value == ([0-9]{3})"
- "[CHANNEL 2] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 2 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "[CHANNEL 1] Sampled value == -?[0-9]"
- "[CHANNEL 2] Sampled value == -?[0-9]"
- "Calibration in the blocking manner finished successfully."
- "Sampling 3 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "[CHANNEL 1] Sampled value == ([0-9]{3})"
- "[CHANNEL 2] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 4 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "[CHANNEL 1] Sampled value == -?[0-9]"
- "[CHANNEL 2] Sampled value == -?[0-9]"
- "Calibration in the blocking manner finished successfully."
- "Sampling 5 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "[CHANNEL 1] Sampled value == ([0-9]{3})"
- "[CHANNEL 2] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 6 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "[CHANNEL 1] Sampled value == -?[0-9]"
- "[CHANNEL 2] Sampled value == -?[0-9]"
- "Calibration in the blocking manner finished successfully."
- "Sampling 7 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "[CHANNEL 1] Sampled value == ([0-9]{3})"
- "[CHANNEL 2] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 8 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "[CHANNEL 1] Sampled value == -?[0-9]"
- "[CHANNEL 2] Sampled value == -?[0-9]"

On nRF54L15 DK, in order to keep the loopbacks consistent for all the samples, just two channels are used so the output should look something like:

- "Starting nrfx_saadc simple blocking example."
- "Single channel SAADC test."
- "Calibration in the blocking manner finished successfully."
- "Sampling 1 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 2 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "Calibration in the blocking manner finished successfully."
- "Sampling 3 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 4 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "Calibration in the blocking manner finished successfully."
- "Sampling 5 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 6 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "Calibration in the blocking manner finished successfully."
- "Sampling 7 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 8 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "Multiple channels SAADC test."
- "Calibration in the blocking manner finished successfully."
- "Sampling 1 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "[CHANNEL 1] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 2 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "[CHANNEL 1] Sampled value == -?[0-9]"
- "Calibration in the blocking manner finished successfully."
- "Sampling 3 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "[CHANNEL 1] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 4 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "[CHANNEL 1] Sampled value == -?[0-9]"
- "Calibration in the blocking manner finished successfully."
- "Sampling 5 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "[CHANNEL 1] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 6 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "[CHANNEL 1] Sampled value == -?[0-9]"
- "Calibration in the blocking manner finished successfully."
- "Sampling 7 / 8"
- "[CHANNEL 0] Sampled value == ([0-9]{3})"
- "[CHANNEL 1] Sampled value == ([0-9]{3})"
- "Calibration in the blocking manner finished successfully."
- "Sampling 8 / 8"
- "[CHANNEL 0] Sampled value == -?[0-9]"
- "[CHANNEL 1] Sampled value == -?[0-9]"