STM32L4xx_HAL_Driver  1.14.0
Configuration of ADC hierarchical scope: channels

Functions

__STATIC_INLINE void LL_ADC_SetChannelSamplingTime (ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SamplingTime)
 Set sampling time of the selected ADC channel Unit: ADC clock cycles. More...
 
__STATIC_INLINE uint32_t LL_ADC_GetChannelSamplingTime (ADC_TypeDef *ADCx, uint32_t Channel)
 Get sampling time of the selected ADC channel Unit: ADC clock cycles. More...
 
__STATIC_INLINE void LL_ADC_SetChannelSingleDiff (ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SingleDiff)
 Set mode single-ended or differential input of the selected ADC channel. More...
 
__STATIC_INLINE uint32_t LL_ADC_GetChannelSingleDiff (ADC_TypeDef *ADCx, uint32_t Channel)
 Get mode single-ended or differential input of the selected ADC channel. More...
 

Detailed Description

Function Documentation

◆ LL_ADC_GetChannelSamplingTime()

__STATIC_INLINE uint32_t LL_ADC_GetChannelSamplingTime ( ADC_TypeDef *  ADCx,
uint32_t  Channel 
)

Get sampling time of the selected ADC channel Unit: ADC clock cycles.

Note
On this device, sampling time is on channel scope: independently of channel mapped on ADC group regular or injected.
Conversion time is the addition of sampling time and processing time. On this STM32 serie, ADC processing time is:
  • 12.5 ADC clock cycles at ADC resolution 12 bits
  • 10.5 ADC clock cycles at ADC resolution 10 bits
  • 8.5 ADC clock cycles at ADC resolution 8 bits
  • 6.5 ADC clock cycles at ADC resolution 6 bits SMPR1 SMP0 LL_ADC_GetChannelSamplingTime
    SMPR1 SMP1 LL_ADC_GetChannelSamplingTime
    SMPR1 SMP2 LL_ADC_GetChannelSamplingTime
    SMPR1 SMP3 LL_ADC_GetChannelSamplingTime
    SMPR1 SMP4 LL_ADC_GetChannelSamplingTime
    SMPR1 SMP5 LL_ADC_GetChannelSamplingTime
    SMPR1 SMP6 LL_ADC_GetChannelSamplingTime
    SMPR1 SMP7 LL_ADC_GetChannelSamplingTime
    SMPR1 SMP8 LL_ADC_GetChannelSamplingTime
    SMPR1 SMP9 LL_ADC_GetChannelSamplingTime
    SMPR2 SMP10 LL_ADC_GetChannelSamplingTime
    SMPR2 SMP11 LL_ADC_GetChannelSamplingTime
    SMPR2 SMP12 LL_ADC_GetChannelSamplingTime
    SMPR2 SMP13 LL_ADC_GetChannelSamplingTime
    SMPR2 SMP14 LL_ADC_GetChannelSamplingTime
    SMPR2 SMP15 LL_ADC_GetChannelSamplingTime
    SMPR2 SMP16 LL_ADC_GetChannelSamplingTime
    SMPR2 SMP17 LL_ADC_GetChannelSamplingTime
    SMPR2 SMP18 LL_ADC_GetChannelSamplingTime
Parameters
ADCxADC instance
ChannelThis parameter can be one of the following values:
  • LL_ADC_CHANNEL_0
  • LL_ADC_CHANNEL_1 (7)
  • LL_ADC_CHANNEL_2 (7)
  • LL_ADC_CHANNEL_3 (7)
  • LL_ADC_CHANNEL_4 (7)
  • LL_ADC_CHANNEL_5 (7)
  • LL_ADC_CHANNEL_6
  • LL_ADC_CHANNEL_7
  • LL_ADC_CHANNEL_8
  • LL_ADC_CHANNEL_9
  • LL_ADC_CHANNEL_10
  • LL_ADC_CHANNEL_11
  • LL_ADC_CHANNEL_12
  • LL_ADC_CHANNEL_13
  • LL_ADC_CHANNEL_14
  • LL_ADC_CHANNEL_15
  • LL_ADC_CHANNEL_16
  • LL_ADC_CHANNEL_17
  • LL_ADC_CHANNEL_18
  • LL_ADC_CHANNEL_VREFINT (1)
  • LL_ADC_CHANNEL_TEMPSENSOR (4)
  • LL_ADC_CHANNEL_VBAT (4)
  • LL_ADC_CHANNEL_DAC1CH1 (5)
  • LL_ADC_CHANNEL_DAC1CH2 (5)
  • LL_ADC_CHANNEL_DAC1CH1_ADC2 (2)(6)
  • LL_ADC_CHANNEL_DAC1CH2_ADC2 (2)(6)
  • LL_ADC_CHANNEL_DAC1CH1_ADC3 (3)(6)
  • LL_ADC_CHANNEL_DAC1CH2_ADC3 (3)(6)
(1) On STM32L4, parameter available only on ADC instance: ADC1.
(2) On STM32L4, parameter available only on ADC instance: ADC2.
(3) On STM32L4, parameter available only on ADC instance: ADC3.
(4) On STM32L4, parameter available only on ADC instances: ADC1, ADC3.
(5) On STM32L4, parameter available on devices with only 1 ADC instance.
(6) On STM32L4, parameter available on devices with several ADC instances.
(7) On STM32L4, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)). Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
Return values
Returnedvalue can be one of the following values:
  • LL_ADC_SAMPLINGTIME_2CYCLES_5 (1)
  • LL_ADC_SAMPLINGTIME_6CYCLES_5
  • LL_ADC_SAMPLINGTIME_12CYCLES_5
  • LL_ADC_SAMPLINGTIME_24CYCLES_5
  • LL_ADC_SAMPLINGTIME_47CYCLES_5
  • LL_ADC_SAMPLINGTIME_92CYCLES_5
  • LL_ADC_SAMPLINGTIME_247CYCLES_5
  • LL_ADC_SAMPLINGTIME_640CYCLES_5
(1) On some devices, ADC sampling time 2.5 ADC clock cycles can be replaced by 3.5 ADC clock cycles. Refer to function LL_ADC_SetSamplingTimeCommonConfig().

Definition at line 4738 of file stm32l4xx_ll_adc.h.

4739 {
4740  register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->SMPR1, ((Channel & ADC_CHANNEL_SMPRX_REGOFFSET_MASK) >> ADC_SMPRX_REGOFFSET_POS));
4741 
4742  return (uint32_t)(READ_BIT(*preg,
4743  ADC_SMPR1_SMP0 << ((Channel & ADC_CHANNEL_SMPx_BITOFFSET_MASK) >> ADC_CHANNEL_SMPx_BITOFFSET_POS))
4744  >> ((Channel & ADC_CHANNEL_SMPx_BITOFFSET_MASK) >> ADC_CHANNEL_SMPx_BITOFFSET_POS)
4745  );
4746 }

◆ LL_ADC_GetChannelSingleDiff()

__STATIC_INLINE uint32_t LL_ADC_GetChannelSingleDiff ( ADC_TypeDef *  ADCx,
uint32_t  Channel 
)

Get mode single-ended or differential input of the selected ADC channel.

Note
When configuring a channel 'i' in differential mode, the channel 'i+1' is not usable separately. Therefore, to ensure a channel is configured in single-ended mode, the configuration of channel itself and the channel 'i-1' must be read back (to ensure that the selected channel channel has not been configured in differential mode by the previous channel).
Refer to Reference Manual to ensure the selected channel is available in differential mode. For example, internal channels (VrefInt, TempSensor, ...) are not available in differential mode.
When configuring a channel 'i' in differential mode, the channel 'i+1' is not usable separately.
On STM32L4, channels 16, 17, 18 of ADC1, ADC2, ADC3 (if available) are internally fixed to single-ended inputs configuration.
One or several values can be selected. In this case, the value returned is null if all channels are in single ended-mode. Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...) DIFSEL DIFSEL LL_ADC_GetChannelSingleDiff
Parameters
ADCxADC instance
ChannelThis parameter can be a combination of the following values:
  • LL_ADC_CHANNEL_1
  • LL_ADC_CHANNEL_2
  • LL_ADC_CHANNEL_3
  • LL_ADC_CHANNEL_4
  • LL_ADC_CHANNEL_5
  • LL_ADC_CHANNEL_6
  • LL_ADC_CHANNEL_7
  • LL_ADC_CHANNEL_8
  • LL_ADC_CHANNEL_9
  • LL_ADC_CHANNEL_10
  • LL_ADC_CHANNEL_11
  • LL_ADC_CHANNEL_12
  • LL_ADC_CHANNEL_13
  • LL_ADC_CHANNEL_14
  • LL_ADC_CHANNEL_15
Return values
0channel in single-ended mode, else: channel in differential mode

Definition at line 4846 of file stm32l4xx_ll_adc.h.

4847 {
4848  return (uint32_t)(READ_BIT(ADCx->DIFSEL, (Channel & ADC_SINGLEDIFF_CHANNEL_MASK)));
4849 }

◆ LL_ADC_SetChannelSamplingTime()

__STATIC_INLINE void LL_ADC_SetChannelSamplingTime ( ADC_TypeDef *  ADCx,
uint32_t  Channel,
uint32_t  SamplingTime 
)

Set sampling time of the selected ADC channel Unit: ADC clock cycles.

Note
On this device, sampling time is on channel scope: independently of channel mapped on ADC group regular or injected.
In case of internal channel (VrefInt, TempSensor, ...) to be converted: sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting). Refer to device datasheet for timings values (parameters TS_vrefint, TS_temp, ...).
Conversion time is the addition of sampling time and processing time. On this STM32 serie, ADC processing time is:
  • 12.5 ADC clock cycles at ADC resolution 12 bits
  • 10.5 ADC clock cycles at ADC resolution 10 bits
  • 8.5 ADC clock cycles at ADC resolution 8 bits
  • 6.5 ADC clock cycles at ADC resolution 6 bits
In case of ADC conversion of internal channel (VrefInt, temperature sensor, ...), a sampling time minimum value is required. Refer to device datasheet.
On this STM32 serie, setting of this feature is conditioned to ADC state: ADC must be disabled or enabled without conversion on going on either groups regular or injected. SMPR1 SMP0 LL_ADC_SetChannelSamplingTime
SMPR1 SMP1 LL_ADC_SetChannelSamplingTime
SMPR1 SMP2 LL_ADC_SetChannelSamplingTime
SMPR1 SMP3 LL_ADC_SetChannelSamplingTime
SMPR1 SMP4 LL_ADC_SetChannelSamplingTime
SMPR1 SMP5 LL_ADC_SetChannelSamplingTime
SMPR1 SMP6 LL_ADC_SetChannelSamplingTime
SMPR1 SMP7 LL_ADC_SetChannelSamplingTime
SMPR1 SMP8 LL_ADC_SetChannelSamplingTime
SMPR1 SMP9 LL_ADC_SetChannelSamplingTime
SMPR2 SMP10 LL_ADC_SetChannelSamplingTime
SMPR2 SMP11 LL_ADC_SetChannelSamplingTime
SMPR2 SMP12 LL_ADC_SetChannelSamplingTime
SMPR2 SMP13 LL_ADC_SetChannelSamplingTime
SMPR2 SMP14 LL_ADC_SetChannelSamplingTime
SMPR2 SMP15 LL_ADC_SetChannelSamplingTime
SMPR2 SMP16 LL_ADC_SetChannelSamplingTime
SMPR2 SMP17 LL_ADC_SetChannelSamplingTime
SMPR2 SMP18 LL_ADC_SetChannelSamplingTime
Parameters
ADCxADC instance
ChannelThis parameter can be one of the following values:
  • LL_ADC_CHANNEL_0
  • LL_ADC_CHANNEL_1 (7)
  • LL_ADC_CHANNEL_2 (7)
  • LL_ADC_CHANNEL_3 (7)
  • LL_ADC_CHANNEL_4 (7)
  • LL_ADC_CHANNEL_5 (7)
  • LL_ADC_CHANNEL_6
  • LL_ADC_CHANNEL_7
  • LL_ADC_CHANNEL_8
  • LL_ADC_CHANNEL_9
  • LL_ADC_CHANNEL_10
  • LL_ADC_CHANNEL_11
  • LL_ADC_CHANNEL_12
  • LL_ADC_CHANNEL_13
  • LL_ADC_CHANNEL_14
  • LL_ADC_CHANNEL_15
  • LL_ADC_CHANNEL_16
  • LL_ADC_CHANNEL_17
  • LL_ADC_CHANNEL_18
  • LL_ADC_CHANNEL_VREFINT (1)
  • LL_ADC_CHANNEL_TEMPSENSOR (4)
  • LL_ADC_CHANNEL_VBAT (4)
  • LL_ADC_CHANNEL_DAC1CH1 (5)
  • LL_ADC_CHANNEL_DAC1CH2 (5)
  • LL_ADC_CHANNEL_DAC1CH1_ADC2 (2)(6)
  • LL_ADC_CHANNEL_DAC1CH2_ADC2 (2)(6)
  • LL_ADC_CHANNEL_DAC1CH1_ADC3 (3)(6)
  • LL_ADC_CHANNEL_DAC1CH2_ADC3 (3)(6)
(1) On STM32L4, parameter available only on ADC instance: ADC1.
(2) On STM32L4, parameter available only on ADC instance: ADC2.
(3) On STM32L4, parameter available only on ADC instance: ADC3.
(4) On STM32L4, parameter available only on ADC instances: ADC1, ADC3.
(5) On STM32L4, parameter available on devices with only 1 ADC instance.
(6) On STM32L4, parameter available on devices with several ADC instances.
(7) On STM32L4, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)). Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
SamplingTimeThis parameter can be one of the following values:
  • LL_ADC_SAMPLINGTIME_2CYCLES_5 (1)
  • LL_ADC_SAMPLINGTIME_6CYCLES_5
  • LL_ADC_SAMPLINGTIME_12CYCLES_5
  • LL_ADC_SAMPLINGTIME_24CYCLES_5
  • LL_ADC_SAMPLINGTIME_47CYCLES_5
  • LL_ADC_SAMPLINGTIME_92CYCLES_5
  • LL_ADC_SAMPLINGTIME_247CYCLES_5
  • LL_ADC_SAMPLINGTIME_640CYCLES_5
(1) On some devices, ADC sampling time 2.5 ADC clock cycles can be replaced by 3.5 ADC clock cycles. Refer to function LL_ADC_SetSamplingTimeCommonConfig().
Return values
None

Definition at line 4642 of file stm32l4xx_ll_adc.h.

4643 {
4644  /* Set bits with content of parameter "SamplingTime" with bits position */
4645  /* in register and register position depending on parameter "Channel". */
4646  /* Parameter "Channel" is used with masks because containing */
4647  /* other bits reserved for other purpose. */
4648  register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->SMPR1, ((Channel & ADC_CHANNEL_SMPRX_REGOFFSET_MASK) >> ADC_SMPRX_REGOFFSET_POS));
4649 
4650  MODIFY_REG(*preg,
4651  ADC_SMPR1_SMP0 << ((Channel & ADC_CHANNEL_SMPx_BITOFFSET_MASK) >> ADC_CHANNEL_SMPx_BITOFFSET_POS),
4652  SamplingTime << ((Channel & ADC_CHANNEL_SMPx_BITOFFSET_MASK) >> ADC_CHANNEL_SMPx_BITOFFSET_POS));
4653 }
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)

◆ LL_ADC_SetChannelSingleDiff()

__STATIC_INLINE void LL_ADC_SetChannelSingleDiff ( ADC_TypeDef *  ADCx,
uint32_t  Channel,
uint32_t  SingleDiff 
)

Set mode single-ended or differential input of the selected ADC channel.

Note
Channel ending is on channel scope: independently of channel mapped on ADC group regular or injected. In differential mode: Differential measurement is carried out between the selected channel 'i' (positive input) and channel 'i+1' (negative input). Only channel 'i' has to be configured, channel 'i+1' is configured automatically.
Refer to Reference Manual to ensure the selected channel is available in differential mode. For example, internal channels (VrefInt, TempSensor, ...) are not available in differential mode.
When configuring a channel 'i' in differential mode, the channel 'i+1' is not usable separately.
On STM32L4, channels 16, 17, 18 of ADC1, ADC2, ADC3 (if available) are internally fixed to single-ended inputs configuration.
For ADC channels configured in differential mode, both inputs should be biased at (Vref+)/2 +/-200mV. (Vref+ is the analog voltage reference)
On this STM32 serie, setting of this feature is conditioned to ADC state: ADC must be ADC disabled.
One or several values can be selected. Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...) DIFSEL DIFSEL LL_ADC_SetChannelSingleDiff
Parameters
ADCxADC instance
ChannelThis parameter can be one of the following values:
  • LL_ADC_CHANNEL_1
  • LL_ADC_CHANNEL_2
  • LL_ADC_CHANNEL_3
  • LL_ADC_CHANNEL_4
  • LL_ADC_CHANNEL_5
  • LL_ADC_CHANNEL_6
  • LL_ADC_CHANNEL_7
  • LL_ADC_CHANNEL_8
  • LL_ADC_CHANNEL_9
  • LL_ADC_CHANNEL_10
  • LL_ADC_CHANNEL_11
  • LL_ADC_CHANNEL_12
  • LL_ADC_CHANNEL_13
  • LL_ADC_CHANNEL_14
  • LL_ADC_CHANNEL_15
SingleDiffThis parameter can be a combination of the following values:
  • LL_ADC_SINGLE_ENDED
  • LL_ADC_DIFFERENTIAL_ENDED
Return values
None

Definition at line 4796 of file stm32l4xx_ll_adc.h.

4797 {
4798  /* Bits of channels in single or differential mode are set only for */
4799  /* differential mode (for single mode, mask of bits allowed to be set is */
4800  /* shifted out of range of bits of channels in single or differential mode. */
4801  MODIFY_REG(ADCx->DIFSEL,
4802  Channel & ADC_SINGLEDIFF_CHANNEL_MASK,
4803  (Channel & ADC_SINGLEDIFF_CHANNEL_MASK) & (ADC_DIFSEL_DIFSEL >> (SingleDiff & ADC_SINGLEDIFF_CHANNEL_SHIFT_MASK)));
4804 }
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)