ADC driver
- group nrfx_adc
Analog-to-Digital Converter (ADC) peripheral driver.
Defines
-
NRFX_ADC_DEFAULT_CHANNEL(analog_input)
ADC channel default configuration.
This configuration sets up ADC channel with the following options:
10 bits resolution
full scale input
reference voltage: 1.2 V
external reference input disabled
- Parameters
analog_input – [in] Analog input.
-
NRFX_ADC_DEFAULT_CONFIG
ADC default configuration.
Typedefs
-
typedef struct nrfx_adc_channel_s nrfx_adc_channel_t
Forward declaration of the nrfx_adc_channel_t type.
-
typedef void (*nrfx_adc_event_handler_t)(nrfx_adc_evt_t const *p_event)
User event handler prototype.
This function is called when the requested number of samples has been processed.
- Param p_event
Event.
Enums
Functions
-
nrfx_err_t nrfx_adc_init(nrfx_adc_config_t const *p_config, nrfx_adc_event_handler_t event_handler)
Function for initializing the ADC.
If a valid event handler is provided, the driver is initialized in non-blocking mode. If event_handler is NULL, the driver works in blocking mode.
- Parameters
p_config – [in] Pointer to the structure with the initial configuration.
event_handler – [in] Event handler provided by the user.
- Return values
NRFX_SUCCESS – Initialization was successful.
NRFX_ERROR_INVALID_STATE – The driver is already initialized.
-
void nrfx_adc_uninit(void)
Function for uninitializing the ADC.
This function stops all ongoing conversions and disables all channels.
-
void nrfx_adc_channel_enable(nrfx_adc_channel_t *const p_channel)
Function for enabling an ADC channel.
This function configures and enables the channel. When nrfx_adc_buffer_convert is called, all channels that have been enabled with this function are sampled.
This function can be called only when there is no conversion in progress (the ADC is not busy).
Note
The channel instance variable
p_channel
is used by the driver as an item in a list. Therefore, it cannot be an automatic variable that is located on the stack.- Parameters
p_channel – [in] Pointer to the channel instance.
-
void nrfx_adc_channel_disable(nrfx_adc_channel_t *const p_channel)
Function for disabling an ADC channel.
This function can be called only when there is no conversion in progress (the ADC is not busy).
- Parameters
p_channel – Pointer to the channel instance.
-
void nrfx_adc_all_channels_disable(void)
Function for disabling all ADC channels.
This function can be called only when there is no conversion in progress (the ADC is not busy).
-
void nrfx_adc_sample(void)
Function for starting ADC sampling.
This function triggers single ADC sampling. If more than one channel is enabled, the driver emulates scanning and all channels are sampled in the order they were enabled.
-
nrfx_err_t nrfx_adc_sample_convert(nrfx_adc_channel_t const *p_channel, nrf_adc_value_t *p_value)
Function for executing a single ADC conversion.
This function selects the desired input and starts a single conversion. If a valid pointer is provided for the result, the function blocks until the conversion is completed. Otherwise, the function returns when the conversion is started, and the result is provided in an event (driver must be initialized in non-blocking mode, otherwise an assertion will fail). The function will fail if ADC is busy. The channel does not need to be enabled to perform a single conversion.
- Parameters
p_channel – [in] Channel.
p_value – [out] Pointer to the location where the result is to be placed. Unless NULL is provided, the function is blocking.
- Return values
NRFX_SUCCESS – Conversion was successful.
NRFX_ERROR_BUSY – The ADC driver is busy.
-
nrfx_err_t nrfx_adc_buffer_convert(nrf_adc_value_t *buffer, uint16_t size)
Function for converting data to the buffer.
If the driver is initialized in non-blocking mode, this function returns when the first conversion is set up. When the buffer is filled, the application is notified by the event handler. If the driver is initialized in blocking mode, the function returns when the buffer is filled.
Conversion is done on all enabled channels, but it is not triggered by this function. This function will prepare the ADC for sampling and then wait for the SAMPLE task. Sampling can be triggered manually by the nrfx_adc_sample function or by PPI using the NRF_ADC_TASK_START task.
Note
If more than one channel is enabled, the function emulates scanning, and a single START task will trigger conversion on all enabled channels. For example: If 3 channels are enabled and the user requests 6 samples, the completion event handler will be called after 2 START tasks.
Note
The application must adjust the sampling frequency. The maximum frequency depends on the sampling timer and the maximum latency of the ADC interrupt. If an interrupt is not handled before the next sampling is triggered, the sample will be lost.
- Parameters
buffer – [in] Result buffer.
size – [in] Buffer size in samples.
- Return values
NRFX_SUCCESS – Conversion was successful.
NRFX_ERROR_BUSY – The driver is busy.
-
bool nrfx_adc_is_busy(void)
Function for retrieving the ADC state.
- Return values
true – The ADC is busy.
false – The ADC is ready.
-
NRFX_STATIC_INLINE uint32_t nrfx_adc_start_task_get(void)
Function for getting the address of the ADC START task.
This function is used to get the address of the START task, which can be used to trigger ADC conversion.
- Returns
Start task address.
-
struct nrfx_adc_done_evt_t
- #include <nrfx_adc.h>
ADC driver DONE event structure.
Public Members
-
nrf_adc_value_t *p_buffer
Pointer to the buffer with converted samples.
-
uint16_t size
Number of samples in the buffer.
-
nrf_adc_value_t *p_buffer
-
struct nrfx_adc_sample_evt_t
- #include <nrfx_adc.h>
SAMPLE event structure.
Public Members
-
nrf_adc_value_t sample
Converted sample.
-
nrf_adc_value_t sample
-
struct nrfx_adc_evt_t
- #include <nrfx_adc.h>
ADC driver event.
Public Members
-
nrfx_adc_evt_type_t type
Event type.
-
nrfx_adc_done_evt_t done
Data for DONE event.
-
nrfx_adc_sample_evt_t sample
Data for SAMPLE event.
-
union nrfx_adc_evt_t.[anonymous] data
Union to store event data.
-
nrfx_adc_evt_type_t type
-
struct nrfx_adc_channel_s
- #include <nrfx_adc.h>
ADC channel.
This structure is defined by the user and used by the driver. Therefore, it should not be defined on the stack as a local variable.
Public Members
-
nrfx_adc_channel_t *p_next
Pointer to the next enabled channel (for internal use).
-
nrf_adc_config_t config
ADC configuration for the current channel.
-
nrfx_adc_channel_t *p_next
-
NRFX_ADC_DEFAULT_CHANNEL(analog_input)