| nRF5 SDK v12.0.0 |

Choose documentation: | nRF5 SDK | S130 SoftDevice API | S132 SoftDevice API | S212 SoftDevice API | S332 SoftDevice API

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Data Structures | Macros | Enumerations | Functions
ADC HAL
ADC HAL and driver

nRF51 only: Hardware access layer for managing the analog-to-digital converter (ADC). More...

## Data Structures
struct | nrf_adc_config_t
| Analog-to-digital converter configuration. More...

## Macros
#define | NRF_ADC_CONFIG_DEFAULT

## Enumerations
enum | nrf_adc_int_mask_t { NRF_ADC_INT_END_MASK = ADC_INTENSET_END_Msk }
| ADC interrupts. More...
enum | nrf_adc_config_resolution_t { NRF_ADC_CONFIG_RES_8BIT = ADC_CONFIG_RES_8bit, NRF_ADC_CONFIG_RES_9BIT = ADC_CONFIG_RES_9bit, NRF_ADC_CONFIG_RES_10BIT = ADC_CONFIG_RES_10bit }
| Resolution of the analog-to-digital converter. More...
enum | nrf_adc_config_scaling_t { NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE = ADC_CONFIG_INPSEL_AnalogInputNoPrescaling, NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS = ADC_CONFIG_INPSEL_AnalogInputTwoThirdsPrescaling, NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD = ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling, NRF_ADC_CONFIG_SCALING_SUPPLY_TWO_THIRDS = ADC_CONFIG_INPSEL_SupplyTwoThirdsPrescaling, NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD = ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling }
| Scaling factor of the analog-to-digital conversion. More...
enum | nrf_adc_config_reference_t { NRF_ADC_CONFIG_REF_VBG = ADC_CONFIG_REFSEL_VBG, NRF_ADC_CONFIG_REF_SUPPLY_ONE_HALF = ADC_CONFIG_REFSEL_SupplyOneHalfPrescaling, NRF_ADC_CONFIG_REF_SUPPLY_ONE_THIRD = ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling, NRF_ADC_CONFIG_REF_EXT_REF0, NRF_ADC_CONFIG_REF_EXT_REF1 }
| Reference selection of the analog-to-digital converter. More...
enum | nrf_adc_config_input_t { NRF_ADC_CONFIG_INPUT_DISABLED = ADC_CONFIG_PSEL_Disabled, NRF_ADC_CONFIG_INPUT_0 = ADC_CONFIG_PSEL_AnalogInput0, NRF_ADC_CONFIG_INPUT_1 = ADC_CONFIG_PSEL_AnalogInput1, NRF_ADC_CONFIG_INPUT_2 = ADC_CONFIG_PSEL_AnalogInput2, NRF_ADC_CONFIG_INPUT_3 = ADC_CONFIG_PSEL_AnalogInput3, NRF_ADC_CONFIG_INPUT_4 = ADC_CONFIG_PSEL_AnalogInput4, NRF_ADC_CONFIG_INPUT_5 = ADC_CONFIG_PSEL_AnalogInput5, NRF_ADC_CONFIG_INPUT_6 = ADC_CONFIG_PSEL_AnalogInput6, NRF_ADC_CONFIG_INPUT_7 = ADC_CONFIG_PSEL_AnalogInput7 }
| Input selection of the analog-to-digital converter. More...
enum | nrf_adc_task_t { NRF_ADC_TASK_START = offsetof(NRF_ADC_Type, TASKS_START), NRF_ADC_TASK_STOP = offsetof(NRF_ADC_Type, TASKS_STOP) }
| Analog-to-digital converter tasks. More...
enum | nrf_adc_event_t { NRF_ADC_EVENT_END = offsetof(NRF_ADC_Type, EVENTS_END) }
| Analog-to-digital converter events. More...

## Functions
void | nrf_adc_configure (nrf_adc_config_t *config)
| Function for configuring ADC. More...
int32_t | nrf_adc_convert_single (nrf_adc_config_input_t input)
| Blocking function for executing a single ADC conversion. More...
__STATIC_INLINE void | nrf_adc_input_select (nrf_adc_config_input_t input)
| Function for selecting ADC input. More...
__STATIC_INLINE int32_t | nrf_adc_result_get (void)
| Function for retrieving the ADC conversion result. More...
__STATIC_INLINE bool | nrf_adc_is_busy (void)
| Function for checking whether the ADC is busy. More...
__STATIC_INLINE uint32_t | nrf_adc_int_get (uint32_t mask)
| Function for getting the ADC's enabled interrupts. More...
__STATIC_INLINE void | nrf_adc_start (void)
| Function for starting conversion. More...
__STATIC_INLINE void | nrf_adc_stop (void)
| Function for stopping conversion. More...
__STATIC_INLINE bool | nrf_adc_conversion_finished (void)
| Function for checking if the requested ADC conversion has ended. More...
__STATIC_INLINE void | nrf_adc_conversion_event_clean (void)
| Function for clearing the conversion END event.
__STATIC_INLINE uint32_t | nrf_adc_task_address_get (nrf_adc_task_t adc_task)
| Function for getting the address of an ADC task register. More...
__STATIC_INLINE uint32_t | nrf_adc_event_address_get (nrf_adc_event_t adc_event)
| Function for getting the address of a specific ADC event register. More...
__STATIC_INLINE void | nrf_adc_config_set (uint32_t configuration)
| Function for setting the CONFIG register in ADC. More...
__STATIC_INLINE void | nrf_adc_event_clear (nrf_adc_event_t event)
| Function for clearing an ADC event. More...
__STATIC_INLINE bool | nrf_adc_event_check (nrf_adc_event_t event)
| Function for checking state of an ADC event. More...
__STATIC_INLINE void | nrf_adc_int_enable (uint32_t int_mask)
| Function for enabling specified interrupts. More...
__STATIC_INLINE void | nrf_adc_int_disable (uint32_t int_mask)
| Function for disabling specified interrupts. More...
__STATIC_INLINE bool | nrf_adc_int_enable_check (nrf_adc_int_mask_t int_mask)
| Function for retrieving the state of a given interrupt. More...
__STATIC_INLINE void | nrf_adc_task_trigger (nrf_adc_task_t task)
| Function for activating a specific ADC task. More...
__STATIC_INLINE void | nrf_adc_enable (void)
| Function for enabling ADC.
__STATIC_INLINE void | nrf_adc_disable (void)
| Function for disabling ADC.

## Detailed Description

nRF51 only: Hardware access layer for managing the analog-to-digital converter (ADC).

## Macro Definition Documentation

#define NRF_ADC_CONFIG_DEFAULT

Value:
{ NRF_ADC_CONFIG_RES_10BIT, \
NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD, \
NRF_ADC_CONFIG_REF_VBG }

Default ADC configuration.

## Enumeration Type Documentation

enum nrf_adc_config_input_t

Input selection of the analog-to-digital converter.

Enumerator
NRF_ADC_CONFIG_INPUT_DISABLED | No input selected.
NRF_ADC_CONFIG_INPUT_0 | Input 0.
NRF_ADC_CONFIG_INPUT_1 | Input 1.
NRF_ADC_CONFIG_INPUT_2 | Input 2.
NRF_ADC_CONFIG_INPUT_3 | Input 3.
NRF_ADC_CONFIG_INPUT_4 | Input 4.
NRF_ADC_CONFIG_INPUT_5 | Input 5.
NRF_ADC_CONFIG_INPUT_6 | Input 6.
NRF_ADC_CONFIG_INPUT_7 | Input 7.

enum nrf_adc_config_reference_t

Reference selection of the analog-to-digital converter.

Enumerator
NRF_ADC_CONFIG_REF_VBG | 1.2 V reference.
NRF_ADC_CONFIG_REF_SUPPLY_ONE_HALF | 1/2 of power supply.
NRF_ADC_CONFIG_REF_SUPPLY_ONE_THIRD | 1/3 of power supply.
NRF_ADC_CONFIG_REF_EXT_REF0 | External reference 0.
NRF_ADC_CONFIG_REF_EXT_REF1 | External reference 0.

enum nrf_adc_config_resolution_t

Resolution of the analog-to-digital converter.

Enumerator
NRF_ADC_CONFIG_RES_8BIT | 8 bit resolution.
NRF_ADC_CONFIG_RES_9BIT | 9 bit resolution.
NRF_ADC_CONFIG_RES_10BIT | 10 bit resolution.

enum nrf_adc_config_scaling_t

Scaling factor of the analog-to-digital conversion.

Enumerator
NRF_ADC_CONFIG_SCALING_INPUT_FULL_SCALE | Full scale input.
NRF_ADC_CONFIG_SCALING_INPUT_TWO_THIRDS | 2/3 scale input.
NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD | 1/3 scale input.
NRF_ADC_CONFIG_SCALING_SUPPLY_TWO_THIRDS | 2/3 of supply.
NRF_ADC_CONFIG_SCALING_SUPPLY_ONE_THIRD | 1/3 of supply.

enum nrf_adc_event_t

Analog-to-digital converter events.

Enumerator
NRF_ADC_EVENT_END | End of conversion event.

enum nrf_adc_int_mask_t

ADC interrupts.

Enumerator
NRF_ADC_INT_END_MASK | ADC interrupt on END event.

enum nrf_adc_task_t

Analog-to-digital converter tasks.

Enumerator
NRF_ADC_TASK_START | ADC start sampling task.
NRF_ADC_TASK_STOP | ADC stop sampling task.

## Function Documentation

__STATIC_INLINE void nrf_adc_config_set | ( | uint32_t | configuration | ) |

Function for setting the CONFIG register in ADC.

Parameters

  [in] | configuration | Value to be written to the CONFIG register.

void nrf_adc_configure | ( | nrf_adc_config_t * | config | ) |

Function for configuring ADC.

This function powers on the analog-to-digital converter and configures it. After the configuration, the ADC is in DISABLE state and must be enabled before using it.

Parameters

  [in] | config | Configuration parameters.

__STATIC_INLINE bool nrf_adc_conversion_finished | ( | void |  | ) |

Function for checking if the requested ADC conversion has ended.

Return values

  true | If the task has finished.
  false | If the task is still running.

int32_t nrf_adc_convert_single | ( | nrf_adc_config_input_t | input | ) |

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. After the input is selected, the analog-to-digital converter is left in STOP state. The function does not check if the ADC is initialized and powered.

Parameters

  [in] | input | Input to be selected.

Returns
  Conversion result.

__STATIC_INLINE uint32_t nrf_adc_event_address_get | ( | nrf_adc_event_t | adc_event | ) |

Function for getting the address of a specific ADC event register.

Parameters

  [in] | adc_event | ADC event.

Returns
  Address of the specified ADC event.

__STATIC_INLINE bool nrf_adc_event_check | ( | nrf_adc_event_t | event | ) |

Function for checking state of an ADC event.

Parameters

  [in] | event | Event to check.

Return values

  true | If the event is set.
  false | If the event is not set.

__STATIC_INLINE void nrf_adc_event_clear | ( | nrf_adc_event_t | event | ) |

Function for clearing an ADC event.

Parameters

  [in] | event | Event to clear.

__STATIC_INLINE void nrf_adc_input_select | ( | nrf_adc_config_input_t | input | ) |

Function for selecting ADC input.

This function selects the active input of ADC. Ensure that the ADC is powered on and in IDLE state before calling this function.

Parameters

  [in] | input | Input to be selected.

__STATIC_INLINE void nrf_adc_int_disable | ( | uint32_t | int_mask | ) |

Function for disabling specified interrupts.

Parameters

  [in] | int_mask | Interrupts to disable.

__STATIC_INLINE void nrf_adc_int_enable | ( | uint32_t | int_mask | ) |

Function for enabling specified interrupts.

Parameters

  [in] | int_mask | Interrupts to enable.

__STATIC_INLINE bool nrf_adc_int_enable_check | ( | nrf_adc_int_mask_t | int_mask | ) |

Function for retrieving the state of a given interrupt.

Parameters

  [in] | int_mask | Interrupt to check.

Return values

  true | If the interrupt is enabled.
  false | If the interrupt is not enabled.

__STATIC_INLINE uint32_t nrf_adc_int_get | ( | uint32_t | mask | ) |

Function for getting the ADC's enabled interrupts.

Parameters

  [in] | mask | Mask of interrupts to check.

Returns
  State of the interrupts selected by the mask.

See Also
  nrf_adc_int_enable()
  nrf_adc_int_disable()

__STATIC_INLINE bool nrf_adc_is_busy | ( | void |  | ) |

Function for checking whether the ADC is busy.

This function checks whether the analog-to-digital converter is busy with a conversion.

Return values

  true | If the ADC is busy.
  false | If the ADC is not busy.

__STATIC_INLINE int32_t nrf_adc_result_get | ( | void |  | ) |

Function for retrieving the ADC conversion result.

This function retrieves and returns the last analog-to-digital conversion result.

Returns
  Last conversion result.

__STATIC_INLINE void nrf_adc_start | ( | void |  | ) |

Function for starting conversion.

See Also
  nrf_adc_stop()

__STATIC_INLINE void nrf_adc_stop | ( | void |  | ) |

Function for stopping conversion.

If the analog-to-digital converter is in inactive state, power consumption is reduced.

See Also
  nrf_adc_start()

__STATIC_INLINE uint32_t nrf_adc_task_address_get | ( | nrf_adc_task_t | adc_task | ) |

Function for getting the address of an ADC task register.

Parameters

  [in] | adc_task | ADC task.

Returns
  Address of the specified ADC task.

__STATIC_INLINE void nrf_adc_task_trigger | ( | nrf_adc_task_t | task | ) |

Function for activating a specific ADC task.

Parameters

  [in] | task | Task to activate.