nRF5 SDK v13.0.0
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions

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

Modules

 SAADC peripheral driver configuration
 

Data Structures

struct  nrf_drv_saadc_config_t
 Analog-to-digital converter driver configuration structure. More...
 
struct  nrf_drv_saadc_done_evt_t
 Analog-to-digital converter driver done event data. More...
 
struct  nrf_drv_saadc_limit_evt_t
 Analog-to-digital converter driver limit event data. More...
 
struct  nrf_drv_saadc_evt_t
 Analog-to-digital converter driver event structure. More...
 

Macros

#define NRF_DRV_SAADC_LIMITH_DISABLED   (2047)
 Value that should be set as high limit to disable limit detection.
 
#define NRF_DRV_SAADC_LIMITL_DISABLED   (-2048)
 Value that should be set as low limit to disable limit detection.
 
#define NRF_DRV_SAADC_DEFAULT_CONFIG
 Macro for setting nrf_drv_saadc_config_t to default settings. More...
 
#define NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(PIN_P)
 Macro for setting nrf_saadc_channel_config_t to default settings in single ended mode. More...
 
#define NRF_DRV_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(* nrf_drv_saadc_event_handler_t )(nrf_drv_saadc_evt_t const *p_event)
 ADC event handler. More...
 

Enumerations

enum  nrf_drv_saadc_evt_type_t {
  NRF_DRV_SAADC_EVT_DONE,
  NRF_DRV_SAADC_EVT_LIMIT,
  NRF_DRV_SAADC_EVT_CALIBRATEDONE
}
 Driver event types. More...
 

Functions

ret_code_t nrf_drv_saadc_init (nrf_drv_saadc_config_t const *p_config, nrf_drv_saadc_event_handler_t event_handler)
 Function for initializing the SAADC. More...
 
void nrf_drv_saadc_uninit (void)
 Function for uninitializing the SAADC. More...
 
uint32_t nrf_drv_saadc_sample_task_get (void)
 Function for getting the address of a SAMPLE SAADC task. More...
 
ret_code_t nrf_drv_saadc_channel_init (uint8_t channel, nrf_saadc_channel_config_t const *const p_config)
 Function for initializing an SAADC channel. More...
 
ret_code_t nrf_drv_saadc_channel_uninit (uint8_t channel)
 Function for uninitializing an SAADC channel. More...
 
ret_code_t nrf_drv_saadc_sample (void)
 Function for starting SAADC sampling. More...
 
ret_code_t nrf_drv_saadc_sample_convert (uint8_t channel, nrf_saadc_value_t *p_value)
 Blocking function for executing a single ADC conversion. More...
 
ret_code_t nrf_drv_saadc_buffer_convert (nrf_saadc_value_t *buffer, uint16_t size)
 Function for issuing conversion of data to the buffer. More...
 
ret_code_t nrf_drv_saadc_calibrate_offset (void)
 Function for triggering the ADC offset calibration. More...
 
bool nrf_drv_saadc_is_busy (void)
 Function for retrieving the SAADC state. More...
 
void nrf_drv_saadc_abort (void)
 Function for aborting ongoing and buffered conversions. More...
 
void nrf_drv_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) driver.

Macro Definition Documentation

#define NRF_DRV_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 NRF_DRV_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 NRF_DRV_SAADC_DEFAULT_CONFIG
Value:
{ \
.interrupt_priority = SAADC_CONFIG_IRQ_PRIORITY, \
.low_power_mode = SAADC_CONFIG_LP_MODE \
}

Macro for setting nrf_drv_saadc_config_t to default settings.

Typedef Documentation

typedef void(* nrf_drv_saadc_event_handler_t)(nrf_drv_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
NRF_DRV_SAADC_EVT_DONE 

Event generated when the buffer is filled with samples.

NRF_DRV_SAADC_EVT_LIMIT 

Event generated after one of the limits is reached.

NRF_DRV_SAADC_EVT_CALIBRATEDONE 

Event generated when the calibration is complete.

Function Documentation

void nrf_drv_saadc_abort ( void  )

Function for aborting ongoing and buffered conversions.

Note
NRF_DRV_SAADC_EVT_DONE event will be generated if there is a conversion in progress. Event will contain number of words in the sample buffer.
ret_code_t nrf_drv_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 nrf_drv_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
NRF_SUCCESSIf conversion was successful.
NRF_ERROR_BUSYIf the driver already has two buffers set or calibration is in progress.
ret_code_t nrf_drv_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
NRF_SUCCESSIf calibration was started successfully.
NRF_ERROR_BUSYIf the ADC driver is busy.
ret_code_t nrf_drv_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
NRF_SUCCESSIf initialization was successful.
NRF_ERROR_INVALID_STATEIf the ADC was not initialized.
NRF_ERROR_NO_MEMIf the specified channel was already allocated.
ret_code_t nrf_drv_saadc_channel_uninit ( uint8_t  channel)

Function for uninitializing an SAADC channel.

Return values
NRF_SUCCESSIf uninitialization was successful.
NRF_ERROR_BUSYIf the ADC is busy.
ret_code_t nrf_drv_saadc_init ( nrf_drv_saadc_config_t const *  p_config,
nrf_drv_saadc_event_handler_t  event_handler 
)

Function for initializing the SAADC.

Parameters
[in]p_configPointer to a configuration structure. If NULL, the default one is used.
[in]event_handlerEvent handler provided by the user.
Return values
NRF_SUCCESSIf initialization was successful.
NRF_ERROR_INVALID_STATEIf the driver is already initialized.
NRF_ERROR_INVALID_PARAMIf event_handler is NULL.
bool nrf_drv_saadc_is_busy ( void  )

Function for retrieving the SAADC state.

Return values
trueIf the ADC is busy.
falseIf the ADC is ready.
void nrf_drv_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 NRF_DRV_SAADC_LIMITL_DISABLED to NRF_DRV_SAADC_LIMITH_DISABLED). Conversion results below this value will trigger the handler function. Set to NRF_DRV_SAADC_LIMITL_DISABLED to disable this limit.
[in]limit_highUpper limit (valid values from NRF_DRV_SAADC_LIMITL_DISABLED to NRF_DRV_SAADC_LIMITH_DISABLED). Conversion results above this value will trigger the handler function. Set to NRF_DRV_SAADC_LIMITH_DISABLED to disable this limit.
ret_code_t nrf_drv_saadc_sample ( void  )

Function for starting SAADC sampling.

Return values
NRF_SUCCESSIf ADC sampling was triggered.
NRF_ERROR_INVALID_STATEIf ADC is in idle state.
ret_code_t nrf_drv_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
NRF_SUCCESSIf conversion was successful.
NRF_ERROR_BUSYIf the ADC driver is busy.
uint32_t nrf_drv_saadc_sample_task_get ( void  )

Function for getting the address of a SAMPLE SAADC task.

Returns
Task address.
void nrf_drv_saadc_uninit ( void  )

Function for uninitializing the SAADC.

This function stops all ongoing conversions and disables all channels.


Documentation feedback | Developer Zone | Subscribe | Updated