nRF5 SDK v15.2.0
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions
SAADC driver

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

Modules

 SAADC peripheral driver configuration
 

Data Structures

struct  nrfx_saadc_config_t
 Analog-to-digital converter driver configuration structure. More...
 
struct  nrfx_saadc_done_evt_t
 Analog-to-digital converter driver done event data. More...
 
struct  nrfx_saadc_limit_evt_t
 Analog-to-digital converter driver limit event data. More...
 
struct  nrfx_saadc_evt_t
 Analog-to-digital converter driver event structure. More...
 

Macros

#define NRFX_SAADC_LIMITH_DISABLED   (2047)
 Value that should be set as high limit to disable limit detection.
 
#define NRFX_SAADC_LIMITL_DISABLED   (-2048)
 Value that should 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)
 ADC event handler. More...
 

Enumerations

enum  nrfx_saadc_evt_type_t {
  NRFX_SAADC_EVT_DONE,
  NRFX_SAADC_EVT_LIMIT,
  NRFX_SAADC_EVT_CALIBRATEDONE
}
 Driver event types. 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 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 ADC 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 ADC offset calibration. More...
 
bool nrfx_saadc_is_busy (void)
 Function for retrieving the SAADC state. More...
 
void nrfx_saadc_abort (void)
 Function for aborting 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...
 
void nrfx_saadc_irq_handler (void)
 

Detailed Description

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

Macro Definition Documentation

#define NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_DIFFERENTIAL (   PIN_P,
  PIN_N 
)
Value:
{ \
.resistor_p = NRF_SAADC_RESISTOR_DISABLED, \
.resistor_n = NRF_SAADC_RESISTOR_DISABLED, \
.gain = NRF_SAADC_GAIN1_6, \
.acq_time = NRF_SAADC_ACQTIME_10US, \
.pin_p = (nrf_saadc_input_t)(PIN_P), \
.pin_n = (nrf_saadc_input_t)(PIN_N) \
}

Macro for setting nrf_saadc_channel_config_t to default settings in differential mode.

Parameters
PIN_PPositive analog input.
PIN_NNegative analog input.
#define NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE (   PIN_P)
Value:
{ \
.resistor_p = NRF_SAADC_RESISTOR_DISABLED, \
.resistor_n = NRF_SAADC_RESISTOR_DISABLED, \
.gain = NRF_SAADC_GAIN1_6, \
.acq_time = NRF_SAADC_ACQTIME_10US, \
.pin_p = (nrf_saadc_input_t)(PIN_P), \
}

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

Parameters
PIN_PAnalog 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)

ADC event handler.

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

Enumeration Type Documentation

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.

Function Documentation

void nrfx_saadc_abort ( void  )

Function for aborting 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.
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 ADC is in idle state, the function will set up Easy DMA for the conversion. The ADC 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]bufferResult buffer.
[in]sizeBuffer size in words.
Return values
NRFX_SUCCESSIf conversion was successful.
NRFX_ERROR_BUSYIf the driver already has two buffers set or calibration is in progress.
nrfx_err_t nrfx_saadc_calibrate_offset ( void  )

Function for triggering the ADC 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 ADC is busy or calibration is already in progress.

Return values
NRFX_SUCCESSIf calibration was started successfully.
NRFX_ERROR_BUSYIf the ADC 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.

Return values
NRFX_SUCCESSIf initialization was successful.
NRFX_ERROR_INVALID_STATEIf the ADC was not initialized.
NRFX_ERROR_NO_MEMIf the specified channel was already allocated.
nrfx_err_t nrfx_saadc_channel_uninit ( uint8_t  channel)

Function for uninitializing an SAADC channel.

Return values
NRFX_SUCCESSIf uninitialization was successful.
NRFX_ERROR_BUSYIf the ADC 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_configPointer to the structure with initial configuration.
[in]event_handlerEvent handler provided by the user. Must not be NULL.
Return values
NRFX_SUCCESSIf initialization was successful.
NRFX_ERROR_INVALID_STATEIf the driver is already initialized.
bool nrfx_saadc_is_busy ( void  )

Function for retrieving the SAADC state.

Return values
trueIf the ADC is busy.
falseIf the ADC 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]channelSAADC channel number.
[in]limit_lowLower 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_highUpper 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 SAADC sampling.

Return values
NRFX_SUCCESSIf ADC sampling was triggered.
NRFX_ERROR_INVALID_STATEIf ADC 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 ADC conversion.

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

The function will fail if ADC is busy.

Parameters
[in]channelChannel.
[out]p_valuePointer to the location where the result should be placed.
Return values
NRFX_SUCCESSIf conversion was successful.
NRFX_ERROR_BUSYIf the ADC 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.


Documentation feedback | Developer Zone | Subscribe | Updated