SAADC legacy driver

nRF5 SDK v17.0.2

Successive Approximation Analog-to-Digital Converter (SAADC) peripheral legacy driver. More...

Data Structures

struct nrfx_saadc_config_t
SAADC driver configuration structure. More...
struct nrfx_saadc_done_evt_t
SAADC driver done event data. More...
struct nrfx_saadc_limit_evt_t
SAADC driver limit event data. More...
struct nrfx_saadc_evt_t
SAADC driver event structure. More...

Macros

#define NRFX_SAADC_LIMITH_DISABLED (2047)
Value to be set as high limit to disable limit detection.
#define NRFX_SAADC_LIMITL_DISABLED (-2048)
Value to be set as low limit to disable limit detection.
#define NRFX_SAADC_DEFAULT_CONFIG
Macro for setting nrfx_saadc_config_t to default settings. More...
#define NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE (PIN_P)
Macro for setting nrf_saadc_channel_config_t to default settings in single-ended mode. More...
#define NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_DIFFERENTIAL (PIN_P, PIN_N)
Macro for setting nrf_saadc_channel_config_t to default settings in differential mode. More...

Typedefs

typedef void(* nrfx_saadc_event_handler_t )( nrfx_saadc_evt_t const *p_event)
SAADC driver event handler. More...

Functions

nrfx_err_t nrfx_saadc_init ( nrfx_saadc_config_t const *p_config, nrfx_saadc_event_handler_t event_handler)
Function for initializing the SAADC. More...
void nrfx_saadc_uninit (void)
Function for uninitializing the SAADC. More...
uint32_t nrfx_saadc_sample_task_get (void)
Function for getting the address of a SAMPLE SAADC task. More...
nrfx_err_t nrfx_saadc_channel_init (uint8_t channel, nrf_saadc_channel_config_t const *const p_config)
Function for initializing an SAADC channel. More...
nrfx_err_t nrfx_saadc_channel_uninit (uint8_t channel)
Function for uninitializing an SAADC channel. More...
nrfx_err_t nrfx_saadc_sample (void)
Function for starting the SAADC sampling. More...
nrfx_err_t nrfx_saadc_sample_convert (uint8_t channel, nrf_saadc_value_t *p_value)
Blocking function for executing a single SAADC conversion. More...
nrfx_err_t nrfx_saadc_buffer_convert ( nrf_saadc_value_t *buffer, uint16_t size)
Function for issuing conversion of data to the buffer. More...
nrfx_err_t nrfx_saadc_calibrate_offset (void)
Function for triggering the SAADC offset calibration. More...
bool nrfx_saadc_is_busy (void)
Function for retrieving the SAADC state. More...
void nrfx_saadc_abort (void)
Function for aborting the ongoing and buffered conversions. More...
void nrfx_saadc_limits_set (uint8_t channel, int16_t limit_low, int16_t limit_high)
Function for setting the SAADC channel limits. When limits are enabled and the result exceeds the defined bounds, the limit handler function is called. More...

Detailed Description

Successive Approximation Analog-to-Digital Converter (SAADC) peripheral legacy driver.

Macro Definition Documentation

#define NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_DIFFERENTIAL ( PIN_P,
PIN_N
)
Value:

Macro for setting nrf_saadc_channel_config_t to default settings in differential mode.

Parameters
PIN_P Positive analog input.
PIN_N Negative analog input.
#define NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE ( PIN_P )
Value:

Macro for setting nrf_saadc_channel_config_t to default settings in single-ended mode.

Parameters
PIN_P Analog input.
#define NRFX_SAADC_DEFAULT_CONFIG
Value:

Macro for setting nrfx_saadc_config_t to default settings.

Typedef Documentation

typedef void(* nrfx_saadc_event_handler_t)( nrfx_saadc_evt_t const *p_event)

SAADC driver event handler.

Parameters
[in] p_event Pointer to an SAADC driver event. The event structure is allocated on the stack, so it is valid only within the context of the event handler.

Enumeration Type Documentation

SAADC driver event types.

Enumerator
NRFX_SAADC_EVT_DONE

Event generated when the buffer is filled with samples.

NRFX_SAADC_EVT_LIMIT

Event generated after one of the limits is reached.

NRFX_SAADC_EVT_CALIBRATEDONE

Event generated when the calibration is complete.

NRFX_SAADC_EVT_DONE

Event generated when the buffer is filled with samples.

NRFX_SAADC_EVT_LIMIT

Event generated when one of the limits is reached.

NRFX_SAADC_EVT_CALIBRATEDONE

Event generated when the calibration is complete.

NRFX_SAADC_EVT_BUF_REQ

Event generated when the next buffer for continuous conversion is requested.

NRFX_SAADC_EVT_READY

Event generated when the first buffer is acquired by the peripheral and sampling can be started.

NRFX_SAADC_EVT_FINISHED

Event generated when all supplied buffers are filled with results.

Function Documentation

void nrfx_saadc_abort ( void )

Function for aborting the ongoing and buffered conversions.

Note
NRFX_SAADC_EVT_DONE event will be generated if there is a conversion in progress. Event will contain number of words in the sample buffer.
Warning
This function must not be called from the context of event handler of the SAADC driver or from the context of interrupt with priority equal to or higher than priority of the SAADC interrupt.
nrfx_err_t nrfx_saadc_buffer_convert ( nrf_saadc_value_t * buffer ,
uint16_t size
)

Function for issuing conversion of data to the buffer.

This function is non-blocking. The application is notified about filling the buffer by the event handler. Conversion will be done on all enabled channels. If the SAADC is in idle state, the function will set up EasyDMA for the conversion. The SAADC will be ready for sampling and wait for the SAMPLE task. It can be triggered manually by the nrfx_saadc_sample function or by PPI using the NRF_SAADC_TASK_SAMPLE task. If one buffer is already set and the conversion is ongoing, calling this function will result in queuing the given buffer. The driver will start filling the issued buffer when the first one is completed. If the function is called again before the first buffer is filled or calibration is in progress, it will return with error.

Parameters
[in] buffer Result buffer.
[in] size Buffer size in words.
Return values
NRFX_SUCCESS The conversion was successful.
NRFX_ERROR_BUSY The driver already has two buffers set or the calibration is in progress.
nrfx_err_t nrfx_saadc_calibrate_offset ( void )

Function for triggering the SAADC offset calibration.

This function is non-blocking. The application is notified about completion by the event handler. Calibration will also trigger DONE and RESULTDONE events.

The function will fail if the SAADC is busy or calibration is already in progress.

Return values
NRFX_SUCCESS The calibration was started successfully.
NRFX_ERROR_BUSY The SAADC driver is busy.
nrfx_err_t nrfx_saadc_channel_init ( uint8_t channel ,
nrf_saadc_channel_config_t const *const p_config
)

Function for initializing an SAADC channel.

This function configures and enables the channel.

Parameters
[in] channel Channel index.
[in] p_config Pointer to the structure with the initial configuration.
Return values
NRFX_SUCCESS Initialization was successful.
NRFX_ERROR_INVALID_STATE The SAADC was not initialized.
NRFX_ERROR_NO_MEM The specified channel was already allocated.
nrfx_err_t nrfx_saadc_channel_uninit ( uint8_t channel )

Function for uninitializing an SAADC channel.

Parameters
[in] channel Channel index.
Return values
NRFX_SUCCESS Uninitialization was successful.
NRFX_ERROR_BUSY The SAADC is busy.
nrfx_err_t nrfx_saadc_init ( nrfx_saadc_config_t const * p_config ,
nrfx_saadc_event_handler_t event_handler
)

Function for initializing the SAADC.

Parameters
[in] p_config Pointer to the structure with initial configuration.
[in] event_handler Event handler provided by the user. Must not be NULL.
Return values
NRFX_SUCCESS Initialization was successful.
NRFX_ERROR_INVALID_STATE The driver is already initialized.
bool nrfx_saadc_is_busy ( void )

Function for retrieving the SAADC state.

Return values
true The SAADC is busy.
false The SAADC is ready.
void nrfx_saadc_limits_set ( uint8_t channel ,
int16_t limit_low ,
int16_t limit_high
)

Function for setting the SAADC channel limits. When limits are enabled and the result exceeds the defined bounds, the limit handler function is called.

Parameters
[in] channel SAADC channel number.
[in] limit_low Lower limit (valid values from NRFX_SAADC_LIMITL_DISABLED to NRFX_SAADC_LIMITH_DISABLED ). Conversion results below this value will trigger the handler function. Set to NRFX_SAADC_LIMITL_DISABLED to disable this limit.
[in] limit_high Upper limit (valid values from NRFX_SAADC_LIMITL_DISABLED to NRFX_SAADC_LIMITH_DISABLED ). Conversion results above this value will trigger the handler function. Set to NRFX_SAADC_LIMITH_DISABLED to disable this limit.
nrfx_err_t nrfx_saadc_sample ( void )

Function for starting the SAADC sampling.

Return values
NRFX_SUCCESS The SAADC sampling was triggered.
NRFX_ERROR_INVALID_STATE The SAADC is in idle state.
nrfx_err_t nrfx_saadc_sample_convert ( uint8_t channel ,
nrf_saadc_value_t * p_value
)

Blocking function for executing a single SAADC conversion.

This function selects the desired input, starts a single conversion, waits for it to finish, and returns the result.

The function fails if the SAADC is busy.

Parameters
[in] channel Channel.
[out] p_value Pointer to the location where the result is to be placed.
Return values
NRFX_SUCCESS The conversion was successful.
NRFX_ERROR_BUSY The SAADC driver is busy.
uint32_t nrfx_saadc_sample_task_get ( void )

Function for getting the address of a SAMPLE SAADC task.

Returns
Task address.
void nrfx_saadc_uninit ( void )

Function for uninitializing the SAADC.

This function stops all ongoing conversions and disables all channels.