LL ADC Macros

Common write and read registers macro

group ADC_LL_EM_WRITE_READ

Defines

LL_ADC_WRITE_REG ( instance , reg , value ) STM32_WRITE_REG((instance)->reg, (value))

Write a value in ADC register.

Parameters :
  • instance – ADC Instance

  • reg – Register to be written

  • value – Value to be written in the register

LL_ADC_READ_REG ( instance , reg ) STM32_READ_REG((instance)->reg)

Read a value in ADC register.

Parameters :
  • instance – ADC Instance

  • reg – Register to be read

Return values :

Register – value

ADC helper macro

group ADC_LL_EM_HELPER_MACRO

Defines

LL_ADC_CHANNEL_TO_DECIMAL_NB ( channel ) ((((channel) & LL_ADC_CHANNEL_ID_BITFIELD_MASK

) == 0UL) \

? ( ((channel) &

LL_ADC_CHANNEL_ID_NB_MASK ) >> LL_ADC_CHANNEL_ID_NB_BITOFFSET_POS

) \

: ( (uint32_t)STM32_POSITION_VAL((channel)) ) \

)


Helper macro to get ADC channel number in decimal format from literals LL_ADC_CHANNEL_x.

Note

Example: LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_CHANNEL_4) will return decimal number “4”.

Note

The input can be a value from functions where a channel number is returned, either defined with number or with bitfield (only one bit must be set).

Parameters :
Return values :

Value – between Min_Data=0 and Max_Data=18

LL_ADC_DECIMAL_NB_TO_CHANNEL ( decimal_nb )

(((decimal_nb) <= 9UL) \

? (((decimal_nb) <<

LL_ADC_CHANNEL_ID_NB_BITOFFSET_POS

) \

| (ADC_AWD2CR_AWD2CH_0 << (decimal_nb)) \

| (

LL_ADC_SMPR1_REGOFFSET

)) \

: (((decimal_nb) <<

LL_ADC_CHANNEL_ID_NB_BITOFFSET_POS

) \

| (ADC_AWD2CR_AWD2CH_0 << (decimal_nb)) \

| (

LL_ADC_SMPR2_REGOFFSET

)) \

)


Helper macro to get ADC channel in literal format LL_ADC_CHANNEL_x from number in decimal format.

Note

Example: LL_ADC_DECIMAL_NB_TO_CHANNEL(4) will return a data equivalent to “LL_ADC_CHANNEL_4”.

Parameters :
  • decimal_nb – Value between Min_Data=0 and Max_Data=18

Return values :

Returned – value can be one of the following values:

(1) On STM32U5, parameter available only on ADC instance: ADC1/ADC2. (2) On STM32U5, parameter available only on ADC instance: ADC4. (3) On STM32U5, fast channel (0.125 us for 14-bit resolution (ADC conversion rate up to 8 Ms/s)). Other channels are slow channels (conversion rate: refer to reference manual). (1, 2) For ADC channel read back from ADC register, comparison with internal channel parameter to be done using helper macro LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL() .

LL_ADC_IS_CHANNEL_INTERNAL ( channel ) (((channel) & LL_ADC_CHANNEL_ID_INTERNAL_CH_MASK ) != 0UL)

Helper macro to determine whether the selected channel corresponds to literal definitions of driver.

Note

The different literal definitions of ADC channels are:

  • ADC internal channel: LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, …

  • ADC external channel (channel connected to a GPIO pin): LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, …

Note

The channel parameter must be a value defined from literal definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, …), ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, …), must not be a value from functions where a channel number is returned from ADC registers, because internal and external channels share the same channel number in ADC registers. The differentiation is made only with parameters definitions of driver.

Parameters :
Return values :

Value – “0” if the channel corresponds to a parameter definition of a ADC external channel (channel connected to a GPIO pin). Value “1” if the channel corresponds to a parameter definition of a ADC internal channel.

LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL ( channel ) ((channel) & ~ LL_ADC_CHANNEL_ID_INTERNAL_CH_MASK )

Helper macro to convert a channel defined from parameter definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, …), to its equivalent parameter definition of a ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, …).

Note

The channel parameter can be, additionally to a value defined from parameter definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, …), a value defined from parameter definition of ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, …) or a value from functions where a channel number is returned from ADC registers.

Parameters :
Return values :

Returned – value can be one of the following values:

LL_ADC_DECIMAL_NB_TO_REG_SEQ_LENGTH ( decimal_nb ) (((decimal_nb) << ADC_SQR1_L_Pos) - 1UL)

Helper macro to get ADC group regular sequencer length in literal format LL_ADC_REG_SEQ_SCAN_x from number in decimal format.

Note

Example: LL_ADC_DECIMAL_NB_TO_REG_SEQ_LENGTH(4) will return a data equivalent to “LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS”.

Parameters :
  • decimal_nb – Value between Min_Data=1 and Max_Data=16 for ADC1 or ADC2, Max_Data=8 for ADC4.

Return values :

Returned – value can be one of the following values:

(1) On STM32U5, parameter available only on ADC instance: ADC1/ADC2.

LL_ADC_REG_SEQ_LENGTH_TO_DECIMAL_NB ( seq_length ) (((seq_length) >> ADC_SQR1_L_Pos) + 1UL)

Helper macro to get ADC group regular sequencer length in decimal format from literal format LL_ADC_REG_SEQ_SCAN_x.

Note

Example: LL_ADC_REG_SEQ_LENGTH_TO_DECIMAL_NB(LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS) will return decimal number “4”.

Parameters :
Return values :

Value – between Min_Data=1 and Max_Data=16 for ADC1 or ADC2, Max_Data=8 for ADC4.

LL_ADC_DECIMAL_NB_TO_INJ_SEQ_LENGTH ( decimal_nb ) (((decimal_nb) << ADC_JSQR_JL_Pos) - 1UL)

Helper macro to get ADC group injected sequencer length in literal format LL_ADC_INJ_SEQ_SCAN_x from number in decimal format.

Note

Example: LL_ADC_DECIMAL_NB_TO_REG_SEQ_LENGTH(4) will return a data equivalent to “LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS”.

Parameters :
  • decimal_nb – Value between Min_Data=1 and Max_Data=4.

Return values :

Returned – value can be one of the following values:

LL_ADC_INJ_SEQ_LENGTH_TO_DECIMAL_NB ( seq_length ) (((seq_length) >> ADC_JSQR_JL_Pos) + 1UL)

Helper macro to get ADC group injected sequencer length in decimal format from literal format LL_ADC_REG_SEQ_SCAN_x.

Note

Example: LL_ADC_REG_SEQ_LENGTH_TO_DECIMAL_NB(LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS) will return decimal number “4”.

Parameters :
Return values :

Value – between Min_Data=1 and Max_Data=4.

LL_ADC_DECIMAL_NB_TO_REG_SEQ_RANK ( decimal_nb ) ((((decimal_nb) / 5UL) << LL_ADC_SQRX_REGOFFSET_POS ) | (((decimal_nb) % 5UL ) * 6UL))

Helper macro to get ADC group regular sequencer rank in literal format LL_ADC_REG_RANK_x from number in decimal format.

Note

Example: LL_ADC_DECIMAL_NB_TO_REG_SEQ_LENGTH(2) will return a data equivalent to “LL_ADC_REG_RANK_2”.

Parameters :
  • decimal_nb – Value between Min_Data=1 and Max_Data=16 for ADC1 or ADC2, Max_Data=8 for ADC4.

Return values :

Returned – value can be one of the following values:

(1) On STM32U5, parameter available only on ADC instance: ADC1/ADC2.

LL_ADC_REG_SEQ_RANK_TO_DECIMAL_NB ( seq_length ) ((((seq_length) >> LL_ADC_SQRX_REGOFFSET_POS ) * 5UL) + (((seq_length) & LL_ADC_REG_RANK_ID_SQRX_MASK ) / 6UL))

Helper macro to get ADC group regular sequencer rank in decimal format from literal format LL_ADC_REG_RANK_x.

Note

Example: LL_ADC_REG_SEQ_LENGTH_TO_DECIMAL_NB(LL_ADC_REG_RANK_2) will return decimal number “2”.

Parameters :
Return values :

Value – between Min_Data=1 and Max_Data=16 for ADC1 or ADC2, Max_Data=8 for ADC4.

LL_ADC_DECIMAL_NB_TO_INJ_SEQ_RANK ( decimal_nb ) ((((decimal_nb) - 1UL) << ( LL_ADC_JDRX_REGOFFSET_POS )) | (((decimal_nb) * 6UL) + 3UL))

Helper macro to get ADC group injected sequencer rank in literal format LL_ADC_INJ_RANK_x from number in decimal format.

Note

Example: LL_ADC_DECIMAL_NB_TO_INJ_SEQ_LENGTH(2) will return a data equivalent to “LL_ADC_INJ_RANK_2”.

Parameters :
  • decimal_nb – Value between Min_Data=1 and Max_Data=16 for ADC1 or ADC2, Max_Data=8 for ADC4.

Return values :

Returned – value can be one of the following values:

LL_ADC_INJ_SEQ_RANK_TO_DECIMAL_NB ( seq_length ) ((((seq_length) & LL_ADC_INJ_RANK_ID_JSQR_MASK ) - 3UL) / 6UL)

Helper macro to get ADC group injected sequencer rank in decimal format from literal format LL_ADC_INJ_RANK_x.

Note

Example: LL_ADC_INJ_SEQ_LENGTH_TO_DECIMAL_NB(LL_ADC_INJ_RANK_2) will return decimal number “2”.

Parameters :
Return values :

Value – between Min_Data=1 and Max_Data=16 for ADC1 or ADC2, Max_Data=8 for ADC4.

LL_ADC_OVS_DECIMAL_NB_TO_RATIO ( decimal_nb ) (((STM32_POSITION_VAL(decimal_nb) - 1U) << ADC4_CFGR2_OVSR_Pos) | LL_ADC_ADC4_OVS_RATIO_PARAM )

Helper macro to get ADC oversampling ratio in literal format LL_ADC_OVS_RATIO_x from decimal format.

Note

Example: LL_ADC_OVS_DECIMAL_NB_TO_RATIO(8) will return a data equivalent to “LL_ADC_OVS_RATIO_8”.

Parameters :
  • decimal_nb – Value among list 2, 4, 8, 16, 32, 64, 128, 256

Return values :

Returned – value can be one of the following values:

LL_ADC_OVS_RATIO_TO_DECIMAL_NB ( ovs_ratio ) (1UL << (((ovs_ratio & ADC4_CFGR2_OVSR) >> ADC4_CFGR2_OVSR_Pos) + 1UL))

Helper macro to get ADC oversampling ratio in decimal format from literal format LL_ADC_OVS_RATIO_x.

Note

Example: LL_ADC_OVS_RATIO_TO_DECIMAL_NB(LL_ADC_OVS_RATIO_8) will return decimal number “8”.

Parameters :
Return values :

Value – between Min_Data=1 and Max_Data=256

LL_ADC_OVS_SHIFT_KEEP_RES ( ovs_ratio_decimal ) (STM32_POSITION_VAL(ovs_ratio_decimal))

Helper macro to get ADC oversampling right bit shift value in function of ratio to have oversampling data keeping current resolution (example: to keep data resolution, ratio x8 requires right shift of 3 bits).

Note

Example: LL_ADC_OVS_SHIFT_KEEP_RES(8) will return decimal number “3”.

Parameters :
  • ovs_ratio_decimal – Value power of 2 (1, 2, 4, 8, 16, …) between Min_Data=1 and Max_Data=1024

Return values :

Value – between Min_Data=1 and Max_Data=11

LL_ADC_ANALOGWD_SET_THRESHOLD_RES ( adc_instance , resolution , awd_threshold )

(((adc_instance) == ADC4) \

? \

(uint32_t)(((uint32_t)awd_threshold) << (((((resolution) -

LL_ADC_RESOLUTION_ADC4_PROCESSING

) & ADC_CFGR1_RES)) \

>> (ADC_CFGR1_RES_Pos - 1U ))) \

: \

(uint32_t)(((uint32_t)awd_threshold) << ((resolution) >> (ADC_CFGR1_RES_Pos - 1U))) \

)


Helper macro to set the value of ADC analog watchdog threshold high or low in function of ADC resolution, when ADC resolution is different of default resolution (14 bit in case of ADC1 or ADC2, 12 bit in case of ADC4).

Note

To be used with function LL_ADC_SetAnalogWDThresholds() . Example, with a ADC resolution of 8 bits, to set the value of analog watchdog threshold high (on 8 bits): LL_ADC_SetAnalogWDThresholds (< ADCx param >, LL_ADC_ANALOGWD_SET_THRESHOLD_RES(LL_ADC_RESOLUTION_8B, <threshold_value_8_bits>) );

Parameters :
  • adc_instance – ADC instance

  • resolution – This parameter can be one of the following values:

  • awd_threshold – Analog watchdog threshold value. Value is signed and can exceed ADC resolution with post-processing computation (offset, oversampling, data shift, …). ADC1, 2: between Min_Data=-16777216 (two’s complement 0xFF000000) and Max_Data=+16777215 (0x00FFFFFF) ADC4: between Min_Data=0x000 and Max_Data=0xFFF

Return values :

Value – is represented as unsigned for intermediate computation but is formatted as signed and can exceed ADC resolution with post-processing computation (offset, oversampling, data shift, …): to be casted to signed 32 bits. ADC1, 2: between Min_Data=-16777216 (two’s complement 0xFF000000) and Max_Data=+16777215 (0x00FFFFFF) ADC4: between Min_Data=0x000 and Max_Data=0xFFF

LL_ADC_ANALOGWD_GET_THRESHOLD_RES ( adc_instance , resolution , awd_threshold )

(((adc_instance) == ADC4) \

? \

(uint32_t)(((uint32_t)awd_threshold) >> (((((resolution) -

LL_ADC_RESOLUTION_ADC4_PROCESSING

) & ADC_CFGR1_RES)) \

>> (ADC_CFGR1_RES_Pos - 1U ))) \

: \

(uint32_t)((((uint32_t)awd_threshold) >> ((resolution) >> (ADC_CFGR1_RES_Pos - 1U))) \

| ((uint32_t)awd_threshold & (~ADC_LTR_LT))) \

)


Helper macro to get the value of ADC analog watchdog threshold high or low in function of ADC resolution, when ADC resolution is different of default resolution (14 bit in case of ADC1 or ADC2, 12 bit in case of ADC4).

Note

To be used with function LL_ADC_GetAnalogWDThresholds() . Example, with a ADC resolution of 8 bits, to get the value of analog watchdog threshold high (on 8 bits): < threshold_value_8_bits > = LL_ADC_ANALOGWD_GET_THRESHOLD_RES (LL_ADC_RESOLUTION_8B, LL_ADC_GetAnalogWDThresholds(<ADCx param>, LL_ADC_AWD_THRESHOLD_HIGH) );

Parameters :
  • adc_instance – ADC instance

  • resolution – This parameter can be one of the following values:

  • awd_threshold – Analog watchdog threshold value. Value is signed and can exceed ADC resolution with post-processing computation (offset, oversampling, data shift, …). ADC1, 2: between Min_Data=-16777216 (two’s complement 0xFF000000) and Max_Data=+16777215 (0x00FFFFFF) ADC4: between Min_Data=0x000 and Max_Data=0xFFF

Return values :

Value – is represented as unsigned for intermediate computation but is formatted as signed and can exceed ADC resolution with post-processing computation (offset, oversampling, data shift, …): to be casted to signed 32 bits. ADC1, 2: between Min_Data=-16777216 (two’s complement 0xFF000000) and Max_Data=+16777215 (0x00FFFFFF) ADC4: between Min_Data=0x000 and Max_Data=0xFFF

LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW ( awd_threshold_type , awd_thresholds )

(((awd_thresholds) >> ((awd_threshold_type) * ADC_AWD1TR_HT1_Pos)) \

& ADC_AWD1TR_LT1)


Helper macro to get the ADC analog watchdog threshold high or low from raw value containing both thresholds concatenated.

Note

To be used with function LL_ADC_GetAnalogWDThresholds() . Example, to get analog watchdog threshold high from the register raw value: LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW(LL_ADC_AWD_THRESHOLD_HIGH, <raw_value_with_both_thresholds>) ;

Parameters :
Return values :

Value – between Min_Data=0x000 and Max_Data=0xFFF

LL_ADC_OFFSET_SET_LEVEL_RES ( resolution , offset_level ) ((offset_level) << ((resolution) >> (ADC_CFGR1_RES_Pos - 1U)))

Helper macro to set the value of ADC offset level in function of ADC resolution, when ADC resolution is different of default resolution (14 bit in case of ADC1 or ADC2).

Note

To be used with function LL_ADC_SetOffset() . Example, with a ADC resolution of 8 bits, to set the value of analog watchdog threshold high (on 8 bits): LL_ADC_SetOffset (< ADCx param >, LL_ADC_OFFSET_SET_LEVEL_RES(LL_ADC_RESOLUTION_8B, <offset_level_8_bits>) );

Parameters :
Return values :

Value – between Min_Data=0x00000000 and Max_Data=0x01FFFFFF

LL_ADC_OFFSET_GET_LEVEL_RES ( resolution , offset_level ) ((offset_level) >> ((resolution) >> (ADC_CFGR1_RES_Pos - 1U)))

Helper macro to get the value of ADC offset level in function of ADC resolution, when ADC resolution is different of default resolution (14 bit in case of ADC1 or ADC2).

Note

To be used with function LL_ADC_GetOffsetLevel() . Example, with a ADC resolution of 8 bits, to set the value of analog watchdog threshold high (on 8 bits): LL_ADC_GetOffsetLevel (< ADCx param >, LL_ADC_OFFSET_SET_LEVEL_RES(LL_ADC_RESOLUTION_8B, <offset_level_8_bits>) );

Parameters :
Return values :

Value – between Min_Data=0x00000000 and Max_Data=0x01FFFFFF

LL_ADC_CLOCK_PRESC_TO_DECIMAL_NB ( clock ) (((clock) == LL_ADC_CLOCK_ASYNC_DIV1

) ? 1U : \

(((clock) ==

LL_ADC_CLOCK_ASYNC_DIV2

) ? 2U : \

(((clock) ==

LL_ADC_CLOCK_ASYNC_DIV4

) ? 4U : \

(((clock) ==

LL_ADC_CLOCK_ASYNC_DIV6

) ? 6U : \

(((clock) ==

LL_ADC_CLOCK_ASYNC_DIV8

) ? 8U : \

(((clock) ==

LL_ADC_CLOCK_ASYNC_DIV10

) ? 10U : \

(((clock) ==

LL_ADC_CLOCK_ASYNC_DIV12

) ? 12U : \

(1UL << ((((clock) >> ADC_CCR_PRESC_Pos) - 3U) & 0x0FUL)) \

) \

) \

) \

) \

) \

) \

)


Helper macro to get clock prescaler decimal value from ADC clock setting.

Note

Intended usage: divide a frequency by performing a shift right using value returned ADC kernel clock frequency = (RCC clock source to ADC frequency / LL_ADC_CLOCK_PRESC_TO_DECIMAL_NB(LL_ADC_GetCommonClock(<adc common instance>)) )

Parameters :
Return values :

Value – between Min_Data=1 and Max_Data=11

LL_ADC_CALIB_FACTOR_SINGLE_DIFF ( calib_factor_single_ended , calib_factor_differential ) (((calib_factor_differential) << LL_ADC_SGLDIFF_CALIB_F_BIT_D_POS ) | (calib_factor_single_ended))

Helper macro to set the ADC calibration value with both single ended and differential modes calibration factors concatenated.

Note

To be used with function LL_ADC_SetCalibrationOffsetFactor()

. Example, to set calibration factors single ended to 0x55 and differential ended to 0x2A: LL_ADC_SetCalibrationOffsetFactor(

ADC1,

LL_ADC_CALIB_FACTOR_SINGLE_DIFF(0x55, 0x2A))

Parameters :
  • calib_factor_single_ended – Value between Min_Data=0x00 and Max_Data=0x7F

  • calib_factor_differential – Value between Min_Data=0x00 and Max_Data=0x7F

Return values :

Value – between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF

LL_ADC_MULTI_CONV_DATA_MASTER_SLAVE ( adc_multi_master_slave , adc_multi_conv_data ) (((adc_multi_conv_data) >> ((ADC_CDR_RDATA_SLV_Pos) & ~(adc_multi_master_slave))) & ADC_CDR_RDATA_MST)

Helper macro to get the ADC multimode conversion data of ADC master or ADC slave from raw value with both ADC conversion data concatenated (unpack multimode conversion data).

Note

This macro is intended to be used when multimode transfer by DMA is enabled (refer to function LL_ADC_SetMultiDMATransfer() ) and data retrieved from CDR (not CDR2). In this case the transferred data needs to be processed with this macro to separate the conversion data of ADC master and ADC slave.

Parameters :
Return values :

Value – between Min_Data=0x0000 and Max_Data=0xFFFF

LL_ADC_DIGITAL_SCALE ( resolution ) (0x3FFFUL >> ((resolution) >> (ADC_CFGR1_RES_Pos - 1UL)))

Helper macro to define the ADC conversion data full-scale digital maximum value corresponding to the selected ADC resolution.

Note

ADC conversion data full-scale corresponds to voltage range determined by analog voltage references Vref+ and Vref- (refer to reference manual).

Note

Value returned corresponds to range maximum value without post-processing computation. With post-processing (offset, gain), conversion data maximum value can exceed this range (as well as minimum value in negative range).

Parameters :
Return values :

ADC – conversion data full-scale digital value (unit: digital value of ADC conversion data)

LL_ADC_CONVERT_DATA_RESOLUTION ( data , adc_res_current , adc_res_target )

((((int32_t)(data)) * (int32_t)64L) \

/ (int32_t)((uint32_t)(1UL << (2U * ((3U + ((adc_res_target) >> ADC_CFGR1_RES_Pos)) \

- ((adc_res_current) >> ADC_CFGR1_RES_Pos))))))


Helper macro to convert the ADC conversion data from a resolution to another resolution.

Note

Arguments data type converted to signed (int32_t) to handle all possible input values (conversion data can be negative after post-processing computation: offset feature).

Note

Processing of negative values: Computation with numerical values power of two instead of binary shift for explicit sign management (arithmetic shift instead of logical shift).

Parameters :
Return values :

ADC – conversion data to the requested resolution

LL_ADC_CALC_DATA_TO_VOLTAGE ( vref_analog_voltage , conv_data , resolution )

((int32_t)(conv_data) * (int32_t)(vref_analog_voltage) \

/ (int32_t)(

LL_ADC_DIGITAL_SCALE

(resolution)) \

)


Helper macro to calculate the voltage (unit: mV) corresponding to a ADC conversion data (unit: digital value).

Note

Analog reference voltage (Vref+) must be either known from user board environment or can be calculated using ADC measurement and ADC helper macro LL_ADC_CALC_VREFANALOG_VOLTAGE() .

Note

Arguments data type converted to signed (int32_t) to handle all possible input values (conversion data can be negative after post-processing computation: offset feature)

Parameters :
Return values :

ADC – conversion data equivalent voltage value (unit: mV)

LL_ADC_CALC_VOLTAGE_TO_DATA ( vref_analog_voltage , voltage_mv , resolution ) ((int32_t)(voltage_mv) * (int32_t)( LL_ADC_DIGITAL_SCALE

(resolution)) \

/ (int32_t)(vref_analog_voltage) \

)


Helper macro to calculate the ADC conversion data (unit: digital value) corresponding to a voltage (unit: mV).

Note

Analog reference voltage (Vref+) must be either known from user board environment or can be calculated using ADC measurement and ADC helper macro LL_ADC_CALC_VREFANALOG_VOLTAGE() .

Note

Arguments data type converted to signed (int32_t) to handle all possible input values (conversion data can be negative after post-processing computation: offset feature)

Parameters :
Return values :

ADC – conversion data equivalent value (unit: digital value)

LL_ADC_CALC_DIFF_DATA_TO_VOLTAGE ( vref_analog_voltage , conv_data , resolution )

((((((int32_t)(conv_data)) * (int32_t)2) * (int32_t)(vref_analog_voltage)) \

/ (int32_t)(

LL_ADC_DIGITAL_SCALE ((resolution)))) - (int32_t)(vref_analog_voltage))

Helper macro to calculate the voltage (unit: mV) corresponding to a ADC conversion data (unit: digital value) in differential ended mode.

Note

On STM32U5, this feature is available on ADC instances: ADC1, ADC2.

Note

ADC data from ADC data register is unsigned and centered around mid range. Converted voltage can be positive or negative depending on differential input voltages.

Note

Arguments data type converted to signed (int32_t) to handle all possible input values (conversion data can be negative after post-processing computation: offset feature)

Note

Analog reference voltage (Vref+) must be either known from user board environment or can be calculated using ADC measurement and ADC helper macro LL_ADC_CALC_VREFANALOG_VOLTAGE() .

Parameters :
Return values :

ADC – conversion data equivalent voltage value (unit: mV)

LL_ADC_CALC_VREFANALOG_VOLTAGE ( vrefint_conv_data , resolution ) ((((uint32_t)* LL_ADC_VREFINT_CAL_ADDR ) * (uint32_t) LL_ADC_VREFINT_CAL_VREF

) \

/ (uint32_t)

LL_ADC_CONVERT_DATA_RESOLUTION

((vrefint_conv_data), \

(resolution), \

LL_ADC_RESOLUTION_14B

) \

)


Helper macro to calculate analog reference voltage (Vref+) (unit: mV) from ADC conversion data of internal voltage reference VrefInt.

Note

Computation is using VrefInt calibration value stored in system memory for each device during production.

Note

This voltage depends on user board environment: voltage level connected to pin Vref+. On devices with small package, the pin Vref+ is not present and internally bonded to pin Vdda.

Parameters :
Return values :

Analog – reference voltage Vref+ value (unit: mV)

LL_ADC_CALC_VBAT ( vref_analog_voltage , vbat_conv_data , resolution ) LL_ADC_CALC_DATA_TO_VOLTAGE (vref_analog_voltage, ((int32_t)(vbat_conv_data) * (int32_t)4), resolution)

Helper macro to calculate the battery voltage (unit: mVolt) from ADC conversion data of vbat channel.

Note

Analog reference voltage (Vref+) must be either known from user board environment or can be calculated using ADC measurement and ADC helper macro HAL_ADC_CALC_VREFANALOG_VOLTAGE().

Parameters :
  • vref_analog_voltage – Analog reference voltage Vref+ (unit: mVolt)

  • vbat_conv_data – ADC conversion data of vbat channel (unit: digital value).

  • resolution – ADC resolution at which ADC conversion has been performed. Value among hal_adc_resolution_t

Return values :

Battery – voltage (unit: mVolt)

Functions

int32_t LL_ADC_CALC_TEMPERATURE ( uint32_t vref_analog_voltage , uint32_t tempsensor_conv_data , uint32_t resolution )

Helper macro to calculate the temperature (unit: degree Celsius) from ADC conversion data of internal temperature sensor.

Note

Computation is using temperature sensor calibration values stored in system memory for each device during production.

Note

Calculation formula: Temperature = ((TS_ADC_DATA - TS_CAL1)

  • (TS_CAL2_TEMP - TS_CAL1_TEMP)) / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP with TS_ADC_DATA = temperature sensor raw data measured by ADC Avg_Slope = (TS_CAL2 - TS_CAL1) / (TS_CAL2_TEMP - TS_CAL1_TEMP) TS_CAL1 = equivalent TS_ADC_DATA at temperature TEMP_DEGC_CAL1 (calibrated in factory) TS_CAL2 = equivalent TS_ADC_DATA at temperature TEMP_DEGC_CAL2 (calibrated in factory) Caution: Calculation relevancy under reserve that calibration parameters are correct (address and data). To calculate temperature using temperature sensor datasheet typical values (generic values less, therefore less accurate than calibrated values), use helper macro LL_ADC_CALC_TEMPERATURE_TYP_PARAMS() .

Note

Analog reference voltage (Vref+) must be either known from user board environment or can be calculated using ADC measurement and ADC helper macro LL_ADC_CALC_VREFANALOG_VOLTAGE() .

Parameters :
Return values :

Temperature – (unit: degree Celsius) or error code (value LL_ADC_TEMPERATURE_CALC_ERROR)

int32_t LL_ADC_CALC_TEMPERATURE_TYP_PARAMS ( int32_t tempsensor_typ_avg_slope , uint32_t tempsensor_typ_calx_v , int32_t tempsensor_calx_temp , uint32_t vref_analog_voltage , uint32_t tempsensor_conv_data , uint32_t resolution )

Helper macro to calculate the temperature (unit: degree Celsius) from ADC conversion data of internal temperature sensor.

Note

Computation is using temperature sensor typical values (refer to device datasheet).

Note

Calculation formula: Temperature = (TS_TYP_CALx_VOLT(uV) - TS_ADC_DATA * Conversion_uV) / Avg_Slope + CALx_TEMP with TS_ADC_DATA = temperature sensor raw data measured by ADC (unit: digital value) Avg_Slope = temperature sensor slope (unit: uV/Degree Celsius) TS_TYP_CALx_VOLT = temperature sensor digital value at temperature CALx_TEMP (unit: mV) Caution: Calculation relevancy under reserve the temperature sensor of the current device has characteristics in line with datasheet typical values. If temperature sensor calibration values are available on on this device (presence of macro LL_ADC_CALC_TEMPERATURE() ), temperature calculation will be more accurate using helper macro LL_ADC_CALC_TEMPERATURE() .

Note

Analog reference voltage (Vref+) must be either known from user board environment or can be calculated using ADC measurement and ADC helper macro LL_ADC_CALC_VREFANALOG_VOLTAGE() .

Parameters :
  • tempsensor_typ_avg_slope – Device datasheet data: Temperature sensor slope typical value (unit: uV/DegCelsius). On STM32U5, refer to device datasheet parameter “Avg_Slope”.

  • tempsensor_typ_calx_v – Device datasheet data: Temperature sensor voltage typical value (at temperature and Vref+ defined in parameters below) (unit: mV). On STM32U5, refer to device datasheet parameter “V30” (corresponding to TS_CAL1).

  • tempsensor_calx_temp – Device datasheet data: Temperature at which temperature sensor voltage see parameter above) is corresponding (unit: mV)

  • vref_analog_voltage – Analog reference voltage Vref+ (unit: mV)

  • tempsensor_conv_data – ADC conversion data of internal temperature sensor (unit: digital value).

  • resolution – ADC resolution at which ADC conversion has been performed This parameter can be one of the following values:

Return values :

Temperature – (unit: degree Celsius)