Successive Approximation Analog-to-Digital Converter (SAADC) driver.
More...
Successive Approximation Analog-to-Digital Converter (SAADC) driver.
#define NRF_DRV_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 NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE |
( |
|
PIN_P | ) |
|
#define NRF_DRV_SAADC_DEFAULT_CONFIG |
ADC event handler.
- Parameters
-
[in] | p_event | Pointer to an ADC event. The event structure is allocated on the stack, so it is valid only within the context of the event handler. |
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.
|
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.
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] | buffer | Result buffer. |
[in] | size | Buffer size in words. |
- Return values
-
NRF_SUCCESS | If conversion was successful. |
NRF_ERROR_BUSY | If 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_SUCCESS | If calibration was started successfully. |
NRF_ERROR_BUSY | If the ADC driver is busy. |
Function for initializing an SAADC channel.
This function configures and enables the channel.
- Return values
-
NRF_SUCCESS | If initialization was successful. |
NRF_ERROR_INVALID_STATE | If the ADC was not initialized. |
NRF_ERROR_NO_MEM | If 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_SUCCESS | If uninitialization was successful. |
NRF_ERROR_BUSY | If the ADC is busy. |
Function for initializing the SAADC.
- Parameters
-
[in] | p_config | Pointer to a configuration structure. If NULL, the default one is used. |
[in] | event_handler | Event handler provided by the user. |
- Return values
-
NRF_SUCCESS | If initialization was successful. |
NRF_ERROR_INVALID_STATE | If the driver is already initialized. |
NRF_ERROR_INVALID_PARAM | If event_handler is NULL. |
bool nrf_drv_saadc_is_busy |
( |
void |
| ) |
|
Function for retrieving the SAADC state.
- Return values
-
true | If the ADC is busy. |
false | If 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
-
Function for starting SAADC sampling.
- Return values
-
NRF_SUCCESS | If ADC sampling was triggered. |
NRF_ERROR_INVALID_STATE | If ADC is in idle state. |
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] | channel | Channel. |
[out] | p_value | Pointer to the location where the result should be placed. |
- Return values
-
NRF_SUCCESS | If conversion was successful. |
NRF_ERROR_BUSY | If 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.