10. Analog-to-digital converter (ADC)

Low-density value line devices are STM32F100xx microcontrollers where the flash memory density ranges between 16 and 32 Kbytes.

Medium-density value line devices are STM32F100xx microcontrollers where the flash memory density ranges between 64 and 128 Kbytes.

High-density value line devices are STM32F100xx microcontrollers where the flash memory density ranges between 256 and 512 Kbytes.

This section applies to the whole STM32F100xx family, unless otherwise specified.

10.1 ADC introduction

The 12-bit ADC is a successive approximation analog-to-digital converter. It has up to 18 multiplexed channels allowing it measure signals from sixteen external and two internal sources. A/D conversion of the various channels can be performed in single, continuous, scan or discontinuous mode. The result of the ADC is stored in a left-aligned or right-aligned 16-bit data register.

The analog watchdog feature allows the application to detect if the input voltage goes outside the user-defined high or low thresholds.

The ADC input clock is generated from the PCLK2 clock divided by a prescaler, refer to Figure 8: STM32F100xx clock tree (low and medium-density devices) and Figure 9: STM32F100xx clock tree (high-density devices) .

10.2 ADC main features

The block diagram of the ADC is shown in Figure 24 .

Note: \( V_{REF-} \) , if available (depending on package), must be tied to \( V_{SSA} \) .

10.3 ADC functional description

Figure 24 shows a single ADC block diagram and Table 57 gives the ADC pin description.

Figure 24. Single ADC block diagram

Single ADC block diagram showing internal components and external connections.

The diagram illustrates the internal architecture of a single ADC block. On the left, external pins are shown: VREF+, VREF-, VDDA, VSSA, ADCx_IN0 through ADCx_IN15, Temp. sensor VREFINT, EXTI_15, and EXTI_11. These pins connect to an internal 'Analog MUX'. The MUX outputs are split into 'Injected channels' (up to 4) and 'Regular channels' (up to 16). Both channel groups feed into the 'Analog to digital converter' block. The converter is clocked by 'ADCCLK' (From ADC prescaler) and has a 'DMA request' output. The converter's output goes to 'Injected data registers (4 × 16 bits)' and a 'Regular data register (16 bits)'. These registers are connected to an 'Address/data bus'. Above the registers, an 'Analog watchdog' block contains 'Compare Result', 'High Threshold (12 bits)', and 'Low Threshold (12 bits)'. This block receives input from the channels and generates an 'Analog watchdog event'. The converter also generates 'End of conversion', 'End of injected conversion', and 'EOC' signals. These signals pass through 'Flags' (EOC, JEOC, AWD) and 'Interrupt enable bits' (EOCIE, JEOCIE, AWDIE) to an AND gate, which produces an 'ADC Interrupt to NVIC'. At the bottom, 'Start trigger' inputs for 'Injected group' and 'Regular group' are shown. These are controlled by 'JEXTRIG' and 'EXTRIG' bits, which are in turn controlled by 'JEXTSEL[2:0] bits' and 'EXTSEL[2:0] bits'. The 'JEXTSEL' bits select from TIM1_TRGO, TIM1_CH4, TIM2_TRGO, TIM2_CH1, TIM3_CH4, TIM4_TRGO, and EXTI_15. The 'EXTSEL' bits select from TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM2_CH2, TIM3_TRGO, TIM4_CH4, and EXTI_11.

Single ADC block diagram showing internal components and external connections.

ai17313

Table 57. ADC pins

NameSignal typeRemarks
V REF+Input, analog reference positiveThe higher/positive reference voltage for the ADC, \( 2.4\text{ V} \leq V_{\text{REF+}} \leq V_{\text{DDA}} \)
V DDA (1)Input, analog supplyAnalog power supply equal to V DD and \( 2.4\text{ V} \leq V_{\text{DDA}} \leq 3.6\text{ V} \)
V REF-Input, analog reference negativeThe lower/negative reference voltage for the ADC, \( V_{\text{REF-}} = V_{\text{SSA}} \)
V SSA (1)Input, analog supply groundGround for analog power supply equal to V SS
ADCx_IN[15:0]Analog signalsUp to 21 analog channels (2)

1. V DDA and V SSA have to be connected to V DD and V SS , respectively.

2. For full details about the ADC I/O pins, refer to the “Pinouts and pin descriptions” section of the corresponding device datasheet.

10.3.1 ADC on-off control

The ADC can be powered-on by setting the ADON bit in the ADC_CR2 register. When the ADON bit is set for the first time, it wakes up the ADC from Power Down mode.

Conversion starts when ADON bit is set for a second time by software after ADC power-up time ( \( t_{\text{STAB}} \) ).

The conversion can be stopped, and the ADC put in power down mode by resetting the ADON bit. In this mode the ADC consumes almost no power (only a few \( \mu\text{A} \) ).

10.3.2 ADC clock

The ADCCLK clock provided by the Clock Controller is synchronous with the PCLK2 (APB2 clock). The RCC controller has a dedicated programmable prescaler for the ADC clock, refer to Section 6: Reset and clock control (RCC) for more details.

10.3.3 Channel selection

There are 16 multiplexed channels. It is possible to organize the conversions in two groups: regular and injected. A group consists of a sequence of conversions which can be done on any channel and in any order. For instance, it is possible to do the conversion in the following order: Ch3, Ch8, Ch2, Ch2, Ch0, Ch2, Ch2, Ch15.

If the ADC_SQRx or ADC_JSQR registers are modified during a conversion, the current conversion is reset and a new start pulse is sent to the ADC to convert the new chosen group.

Temperature sensor/ \( V_{REFINT} \) internal channels

The temperature sensor is connected to channel ADCx_IN16 and the internal reference voltage \( V_{REFINT} \) is connected to ADCx_IN17. These two internal channels can be selected and converted as injected or regular channels.

Note: The sensor and \( V_{REFINT} \) are only available on the master ADC1 peripheral.

10.3.4 Single conversion mode

In Single conversion mode the ADC does one conversion. This mode is started either by setting the ADON bit in the ADC_CR2 register (for a regular channel only) or by external trigger (for a regular or injected channel), while the CONT bit is 0.

Once the conversion of the selected channel is complete:

The ADC is then stopped.

10.3.5 Continuous conversion mode

In continuous conversion mode ADC starts another conversion as soon as it finishes one. This mode is started either by external trigger or by setting the ADON bit in the ADC_CR2 register, while the CONT bit is 1.

After each conversion:

10.3.6 Timing diagram

As shown in Figure 25 , the ADC needs a stabilization time of \( t_{STAB} \) before it starts converting accurately. After the start of ADC conversion and after 14 clock cycles, the EOC flag is set and the 16-bit ADC Data register contains the result of the conversion.

Figure 25. Timing diagram

Timing diagram showing ADC_CLK, ADON, SWSTART/JSWSTART, ADC, and EOC signals over time. It illustrates the sequence of events for starting a conversion, the conversion time, and clearing the EOC bit.

The timing diagram shows the relationship between several signals during an ADC conversion sequence:

Timing diagram showing ADC_CLK, ADON, SWSTART/JSWSTART, ADC, and EOC signals over time. It illustrates the sequence of events for starting a conversion, the conversion time, and clearing the EOC bit.

ai16047b

10.3.7 Analog watchdog

The AWD analog watchdog status bit is set if the analog voltage converted by the ADC is below a low threshold or above a high threshold. These thresholds are programmed in the 12 least significant bits of the ADC_HTR and ADC_LTR 16-bit registers. An interrupt can be enabled by using the AWDIE bit in the ADC_CR1 register.

The threshold value is independent of the alignment selected by the ALIGN bit in the ADC_CR2 register. The comparison is done before the alignment (see Section 10.5 ).

The analog watchdog can be enabled on one or more channels by configuring the ADC_CR1 register as shown in Table 58 .

Figure 26. Analog watchdog guarded area

Graph showing the guarded area between a higher threshold (HTR) and a lower threshold (LTR) for the analog watchdog.

The graph shows "Analog voltage" on the vertical axis. Two horizontal lines represent the "Higher threshold" (HTR) and "Lower threshold" (LTR). The region between these two thresholds is shaded and labeled "Guarded area".

Graph showing the guarded area between a higher threshold (HTR) and a lower threshold (LTR) for the analog watchdog.

ai16048

Table 58. Analog watchdog channel selection

Channels to be guarded by analog watchdogADC_CR1 register control bits (x = don't care)
AWDSGL bitAWDEN bitJAWDEN bit
Nonex00
All injected channels001
All regular channels010

Table 58. Analog watchdog channel selection (continued)

Channels to be guarded by analog watchdogADC_CR1 register control bits (x = don't care)
AWDSGL bitAWDEN bitJAWDEN bit
All regular and injected channels011
Single (1) injected channel101
Single (1) regular channel110
Single (1) regular or injected channel111

1. Selected by AWDCH[4:0] bits

10.3.8 Scan mode

This mode is used to scan a group of analog channels.

Scan mode can be selected by setting the SCAN bit in the ADC_CR1 register. Once this bit is set, ADC scans all the channels selected in the ADC_SQRx registers (for regular channels) or in the ADC_JSQR (for injected channels). A single conversion is performed for each channel of the group. After each end of conversion the next channel of the group is converted automatically. If the CONT bit is set, conversion does not stop at the last selected group channel but continues again from the first selected group channel.

When using scan mode, DMA bit must be set and the direct memory access controller is used to transfer the converted data of regular group channels to SRAM after each update of the ADC_DR register.

The injected channel converted data is always stored in the ADC_JDRx registers.

10.3.9 Injected channel management

Triggered injection

To use triggered injection, the JAUTO bit must be cleared and SCAN bit must be set in the ADC_CR1 register.

  1. 1. Start conversion of a group of regular channels either by external trigger or by setting the ADON bit in the ADC_CR2 register.
  2. 2. If an external injected trigger occurs during the regular group channel conversion, the current conversion is reset and the injected channel sequence is converted in Scan once mode.
  3. 3. Then, the regular group channel conversion is resumed from the last interrupted regular conversion. If a regular event occurs during an injected conversion, it doesn't interrupt it but the regular sequence is executed at the end of the injected sequence.

Figure 27 shows the timing diagram.

Note: When using triggered injection, the interval between trigger events must be longer than the injection sequence. For instance, if the sequence length is 28 ADC clock cycles (that is two conversions with a 1.5 clock-period sampling time), the minimum interval between triggers must be 29 ADC clock cycles.

Auto-injection

If the JAUTO bit is set, then the injected group channels are automatically converted after the regular group channels. This can be used to convert a sequence of up to 20 conversions programmed in the ADC_SQRx and ADC_JSQR registers.

In this mode, external trigger on injected channels must be disabled.

If the CONT bit is also set in addition to the JAUTO bit, regular channels followed by injected channels are continuously converted.

For ADC clock prescalers ranging from 4 to 8, a delay of 1 ADC clock period is automatically inserted when switching from regular to injected sequence (respectively injected to regular). When the ADC clock prescaler is set to 2, the delay is 2 ADC clock periods.

Note: It is not possible to use both auto-injected and discontinuous modes simultaneously.

Figure 27. Injected conversion latency

Timing diagram showing the relationship between ADCCLK, Injection event, Reset ADC, and SOC signals. The diagram illustrates the maximum latency (1) between the Injection event and the start of conversion (SOC).

The figure is a timing diagram with four horizontal signal lines. From top to bottom, they are:

Vertical dashed lines indicate timing points:

Timing diagram showing the relationship between ADCCLK, Injection event, Reset ADC, and SOC signals. The diagram illustrates the maximum latency (1) between the Injection event and the start of conversion (SOC).
  1. 1. The maximum latency value can be found in the electrical characteristics of the STM32F101xx and STM32F103xx datasheets.

10.3.10 Discontinuous mode

Regular group

This mode is enabled by setting the DISCEN bit in the ADC_CR1 register. It can be used to convert a short sequence of n conversions ( \( n \leq 8 \) ) which is a part of the sequence of conversions selected in the ADC_SQRx registers. The value of n is specified by writing to the DISCNUM[2:0] bits in the ADC_CR1 register.

When an external trigger occurs, it starts the next n conversions selected in the ADC_SQRx registers until all the conversions in the sequence are done. The total sequence length is defined by the L[3:0] bits in the ADC_SQR1 register.

Example:

n = 3, channels to be converted = 0, 1, 2, 3, 6, 7, 9, 10
first trigger: sequence converted 0, 1, 2. An EOC event is generated at each

conversion

second trigger: sequence converted 3, 6, 7. An EOC event is generated at each conversion

third trigger: sequence converted 9, 10. An EOC event is generated at each conversion

fourth trigger: sequence converted 0, 1, 2. An EOC event is generated at each conversion

Note: When a regular group is converted in discontinuous mode, no rollover will occur. When all sub groups are converted, the next trigger starts conversion of the first sub-group. In the example above, the fourth trigger reconverts the first sub-group channels 0, 1 and 2.

Injected group

This mode is enabled by setting the JDISCEN bit in the ADC_CR1 register. It can be used to convert the sequence selected in the ADC_JSQR register, channel by channel, after an external trigger event.

When an external trigger occurs, it starts the next channel conversions selected in the ADC_JSQR registers until all the conversions in the sequence are done. The total sequence length is defined by the JL[1:0] bits in the ADC_JSQR register.

Example:

n = 1, channels to be converted = 1, 2, 3

first trigger: channel 1 converted

second trigger: channel 2 converted

third trigger: channel 3 converted and EOC and JEOC events generated

fourth trigger: channel 1

Note: When all injected channels are converted, the next trigger starts the conversion of the first injected channel. In the example above, the fourth trigger reconverts the first injected channel 1.

It is not possible to use both auto-injected and discontinuous modes simultaneously.

The user must avoid setting discontinuous mode for both regular and injected groups together. Discontinuous mode must be enabled only for one group conversion.

10.4 Calibration

The ADC has an built-in self calibration mode. Calibration significantly reduces accuracy errors due to internal capacitor bank variations. During calibration, an error-correction code (digital word) is calculated for each capacitor, and during all subsequent conversions, the error contribution of each capacitor is removed using this code.

Calibration is started by setting the CAL bit in the ADC_CR2 register. Once calibration is over, the CAL bit is reset by hardware and normal conversion can be performed. It is recommended to calibrate the ADC once at power-on. The calibration codes are stored in the ADC_DR as soon as the calibration phase ends.

Note: It is recommended to perform a calibration after each power-up.

Before starting a calibration, the ADC must have been in power-on state (ADON bit = '1') for at least two ADC clock cycles.

Figure 28. Calibration timing diagram

Timing diagram showing CLK, CAL, and ADC Conversion signals. The CAL signal goes high to start calibration, which lasts for tCAL. After calibration, the CAL signal goes low, and a 'Calibration Reset by Hardware' is indicated. The ADC Conversion signal starts after the calibration period.
Timing diagram showing CLK, CAL, and ADC Conversion signals. The CAL signal goes high to start calibration, which lasts for tCAL. After calibration, the CAL signal goes low, and a 'Calibration Reset by Hardware' is indicated. The ADC Conversion signal starts after the calibration period.

10.5 Data alignment

ALIGN bit in the ADC_CR2 register selects the alignment of data stored after conversion. Data can be left or right aligned as shown in Figure 29. and Figure 30.

The injected group channels converted data value is decreased by the user-defined offset written in the ADC_JOFRx registers so the result can be a negative value. The SEXT bit is the extended sign value.

For regular group channels no offset is subtracted so only twelve bits are significant.

Figure 29. Right alignment of data

Injected group
SEXTSEXTSEXTSEXTD11D10D9D8D7D6D5D4D3D2D1D0
Regular group
0000D11D10D9D8D7D6D5D4D3D2D1D0

ai16050

Figure 30. Left alignment of data

Injected group
SEXTD11D10D9D8D7D6D5D4D3D2D1D0000
Regular group
D11D10D9D8D7D6D5D4D3D2D1D00000

ai16051

10.6 Channel-by-channel programmable sample time

ADC samples the input voltage for a number of ADC_CLK cycles which can be modified using the SMP[2:0] bits in the ADC_SMPR1 and ADC_SMPR2 registers. Each channel can be sampled with a different sample time.

The total conversion time is calculated as follows:

\[ T_{conv} = \text{Sampling time} + 12.5 \text{ cycles} \]

Example:

With an ADCCLK = 12 MHz and a sampling time of 1.5 cycles:

\[ T_{conv} = 1.5 + 12.5 = 14 \text{ cycles} = 1.17 \mu\text{s} \]

10.7 Conversion on external trigger

Conversion can be triggered by an external event (e.g. timer capture, EXTI line). If the EXTTRIG control bit is set then external events are able to trigger a conversion. The EXTSEL[2:0] and JEXTSEL[2:0] control bits allow the application to select decide which out of 8 possible events can trigger conversion for the regular and injected groups.

Note: When an external trigger is selected for ADC regular or injected conversion, only the rising edge of the signal can start the conversion.

Table 59. External trigger for regular channels for ADC1

SourceTypeEXTSEL[2:0]
TIM1_CC1 eventInternal signal from on-chip timers000
TIM1_CC2 event001
TIM1_CC3 event010
TIM2_CC2 event011
TIM3_TRGO event100
TIM4_CC4 event101
EXTI line 11External pin110
SWSTARTSoftware control bit111

Table 60. External trigger for injected channels for ADC1

SourceConnection typeJEXTSEL[2:0]
TIM1_TRGO eventInternal signal from on-chip timers000
TIM1_CC4 event001
TIM2_TRGO event010
TIM2_CC1 event011
TIM3_CC4 event100
TIM4_TRGO event101
EXTI line 15External pin110
JSWSTARTSoftware control bit111

The software source trigger events can be generated by setting a bit in a register (SWSTART and JSWSTART in ADC_CR2).

A regular group conversion can be interrupted by an injected trigger.

10.8 DMA request

Since converted regular channels value are stored in a unique data register, it is necessary to use DMA for conversion of more than one regular channel. This avoids the loss of data already stored in the ADC_DR register.

Only the end of conversion of a regular channel generates a DMA request, which allows the transfer of its converted data from the ADC_DR register to the destination location selected by the user.

10.9 Temperature sensor

The temperature sensor can be used to measure the junction temperature ( \( T_J \) ) of the device.

The temperature sensor is internally connected to the ADCx_IN16 input channel which is used to convert the sensor output voltage into a digital value. The recommended sampling time for the temperature sensor is 17.1 \( \mu\text{s} \) .

The block diagram of the temperature sensor is shown in Figure 31 .

When not in use, this sensor can be put in power down mode.

Note: The TSVREFE bit must be set to enable both internal channels: ADCx_IN16 (temperature sensor) and ADCx_IN17 ( \( V_{REFINT} \) ) conversion.

The temperature sensor output voltage changes linearly with temperature. The offset of this line varies from chip to chip due to process variations (up to 45 °C from one chip to another).

The internal temperature sensor is more suited to applications that detect temperature variations instead of absolute temperatures. If accurate temperature readings are needed, an external temperature sensor part should be used.

Figure 31. Temperature sensor and\( V_{REFINT} \) channel block diagram Block diagram of Temperature sensor and VREFINT channel

The diagram illustrates the internal architecture for the Temperature sensor and \( V_{REFINT} \) channels. On the left, two rectangular blocks are labeled "Temperature sensor" and "Internal power block". Their outputs connect to a 2-to-1 multiplexer. The multiplexer is controlled by a "TSVREFE control bit" input from above. The top output of the multiplexer is labeled \( V_{SENSE} \) and connects to the "ADC1_IN16" input of a large rectangular block labeled "ADC1". The bottom output of the multiplexer is labeled \( V_{REFINT} \) and connects to the "ADC1_IN17" input of the same "ADC1" block. The "ADC1" block has an output labeled "Converted data" which connects to a vertical rectangular block labeled "Address/data bus". In the bottom right corner of the diagram, the text "MS35936V2" is present.

Block diagram of Temperature sensor and VREFINT channel

Reading the temperature

To use the sensor:

  1. 1. Select the ADCx_IN16 input channel.
  2. 2. Select a sample time of 17.1 µs
  3. 3. Set the TSVREFE bit in the ADC control register 2 (ADC_CR2) to wake up the temperature sensor from power down mode.
  4. 4. Start the ADC conversion by setting the ADON bit (or by external trigger).
  5. 5. Read the resulting V SENSE data in the ADC data register
  6. 6. Obtain the temperature using the following formula:

\[ \text{Temperature (in } ^\circ\text{C)} = \{(V_{25} - V_{\text{SENSE}}) / \text{Avg\_Slope}\} + 25. \]

Where,

V 25 = V SENSE value for 25° C and

Avg_Slope = Average Slope for curve between Temperature vs. V SENSE (given in mV/° C or µV/° C).

Refer to the Electrical characteristics section for the actual values of V 25 and Avg_Slope.

Note: The sensor has a startup time after waking from power down mode before it can output V SENSE at the correct level. The ADC also has a startup time after power-on, so to minimize the delay, the ADON and TSVREFE bits should be set at the same time.

10.10 ADC interrupts

An interrupt can be produced on end of conversion for regular and injected groups and when the analog watchdog status bit is set. Separate interrupt enable bits are available for flexibility.

Two other flags are present in the ADC_SR register, but there is no interrupt associated with them:

Table 61. ADC interrupts

Interrupt eventEvent flagEnable Control bit
End of conversion regular groupEOCEOCIE
End of conversion injected groupJEOCJEOCIE
Analog watchdog status bit is setAWDAWDIE

10.11 ADC registers

Refer to Section 1.1 on page 32 for a list of abbreviations used in register descriptions.

The peripheral registers have to be accessed by words (32-bit).

10.11.1 ADC status register (ADC_SR)

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
Reserved
1514131211109876543210
ReservedSTRTJSTRTJEOCEOCAWD
rc_w0rc_w0rc_w0rc_w0rc_w0

Bits 31:5 Reserved, must be kept at reset value.

Bit 4 STRT : Regular channel Start flag

This bit is set by hardware when regular channel conversion starts. It is cleared by software.

0: No regular channel conversion started

1: Regular channel conversion has started

Bit 3 JSTRT : Injected channel Start flag

This bit is set by hardware when injected channel group conversion starts. It is cleared by software.

0: No injected group conversion started

1: Injected group conversion has started

Bit 2 JEOC : Injected channel end of conversion

This bit is set by hardware at the end of all injected group channel conversion. It is cleared by software.

0: Conversion is not complete

1: Conversion complete

Bit 1 EOC : End of conversion

This bit is set by hardware at the end of a group channel conversion (regular or injected). It is cleared by software or by reading the ADC_DR.

0: Conversion is not complete

1: Conversion complete

Bit 0 AWD : Analog watchdog flag

This bit is set by hardware when the converted voltage crosses the values programmed in the ADC_LTR and ADC_HTR registers. It is cleared by software.

0: No Analog watchdog event occurred

1: Analog watchdog event occurred

10.11.2 ADC control register 1 (ADC_CR1)

Address offset: 0x04

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedAWDENJAWDENReserved
rwrw
1514131211109876543210
DISCNUM[2:0]JDISCENDISCENJAUTOAWDSGLSCANJEOCIEAWDIEEOCIEAWDCH[4:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:24 Reserved, must be kept at reset value.

Bit 23 AWDEN : Analog watchdog enable on regular channels

This bit is set/reset by software.

0: Analog watchdog disabled on regular channels

1: Analog watchdog enabled on regular channels

Bit 22 JAWDEN : Analog watchdog enable on injected channels

This bit is set/reset by software.

0: Analog watchdog disabled on injected channels

1: Analog watchdog enabled on injected channels

Bits 21:16 Reserved, must be kept at reset value.

Bits 15:13 DISCNUM[2:0] : Discontinuous mode channel count

These bits are written by software to define the number of regular channels to be converted in discontinuous mode, after receiving an external trigger.

000: 1 channel

001: 2 channels

.....

111: 8 channels

Bit 12 JDISCEN : Discontinuous mode on injected channels

This bit set and cleared by software to enable/disable discontinuous mode on injected group channels

0: Discontinuous mode on injected channels disabled

1: Discontinuous mode on injected channels enabled

Bit 11 DISCEN : Discontinuous mode on regular channels

This bit set and cleared by software to enable/disable Discontinuous mode on regular channels.

0: Discontinuous mode on regular channels disabled

1: Discontinuous mode on regular channels enabled

Bit 10 JAUTO : Automatic Injected Group conversion

This bit set and cleared by software to enable/disable automatic injected group conversion after regular group conversion.

0: Automatic injected group conversion disabled

1: Automatic injected group conversion enabled

Bit 9 AWDSGL : Enable the watchdog on a single channel in scan mode

This bit set and cleared by software to enable/disable the analog watchdog on the channel identified by the AWDCH[4:0] bits.

0: Analog watchdog enabled on all channels

1: Analog watchdog enabled on a single channel

Bit 8 SCAN : Scan mode

This bit is set and cleared by software to enable/disable Scan mode. In Scan mode, the inputs selected through the ADC_SQRx or ADC_JSQRx registers are converted.

0: Scan mode disabled

1: Scan mode enabled

Note: An EOC or JEOC interrupt is generated only on the end of conversion of the last channel if the corresponding EOCIE or JEOCIE bit is set

Bit 7 JEOCIE : Interrupt enable for injected channels

This bit is set and cleared by software to enable/disable the end of conversion interrupt for injected channels.

0: JEOC interrupt disabled

1: JEOC interrupt enabled. An interrupt is generated when the JEOC bit is set.

Bit 6 AWDIE : Analog watchdog interrupt enable

This bit is set and cleared by software to enable/disable the analog watchdog interrupt.

0: Analog watchdog interrupt disabled

1: Analog watchdog interrupt enabled

Bit 5 EOCIE : Interrupt enable for EOC

This bit is set and cleared by software to enable/disable the End of Conversion interrupt.

0: EOC interrupt disabled

1: EOC interrupt enabled. An interrupt is generated when the EOC bit is set.

Bits 4:0 AWDCH[4:0] : Analog watchdog channel select bits

These bits are set and cleared by software. They select the input channel to be guarded by the Analog watchdog.

00000: ADC analog Channel0

00001: ADC analog Channel1

...

01111: ADC analog Channel15

10000: ADC analog Channel16

10001: ADC analog Channel17

Other values: reserved.

ADC1 analog Channel16 and Channel17 are internally connected to the temperature sensor and to V REFINT , respectively.

10.11.3 ADC control register 2 (ADC_CR2)

Address offset: 0x08

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedTSVRE
FE
SWSTA
RT
JSWST
ART
EXTTR
IG
EXTSEL[2:0]Res.
rwrwrwrwrwrwrw
1514131211109876543210
JEXTTRIGJEXTSEL[2:0]ALIGNReservedDMAReserved
rwrwrwrwrwRes.rw

Bits 31:24 Reserved, must be kept at reset value.

Bit 23 TSVREFE : Temperature sensor and \( V_{REFINT} \) enable

This bit is set and cleared by software to enable/disable the temperature sensor and \( V_{REFINT} \) channel.

0: Temperature sensor and \( V_{REFINT} \) channel disabled

1: Temperature sensor and \( V_{REFINT} \) channel enabled

Bit 22 SWSTART : Start conversion of regular channels

This bit is set by software to start conversion and cleared by hardware as soon as conversion starts. It starts a conversion of a group of regular channels if SWSTART is selected as trigger event by the EXTSEL[2:0] bits.

0: Reset state

1: Starts conversion of regular channels

Bit 21 JSWSTART : Start conversion of injected channels

This bit is set by software and cleared by software or by hardware as soon as the conversion starts. It starts a conversion of a group of injected channels (if JSWSTART is selected as trigger event by the JEXTSEL[2:0] bits).

0: Reset state

1: Starts conversion of injected channels

Bit 20 EXTTRIG : External trigger conversion mode for regular channels

This bit is set and cleared by software to enable/disable the external trigger used to start conversion of a regular channel group.

0: Conversion on external event disabled

1: Conversion on external event enabled

Bits 19:17 EXTSEL[2:0] : External event select for regular group

These bits select the external event used to trigger the start of conversion of a regular group:

000: Timer 1 CC1 event

001: Timer 1 CC2 event

010: Timer 1 CC3 event

011: Timer 2 CC2 event

100: Timer 3 TRGO event

101: Timer 4 CC4 event

110: EXTI line 11

111: SWSTART

Bit 16 Reserved, must be kept at reset value.

Bit 15 JEXTTRIG : External trigger conversion mode for injected channels

This bit is set and cleared by software to enable/disable the external trigger used to start conversion of an injected channel group.

0: Conversion on external event disabled

1: Conversion on external event enabled

Bits 14:12 JEXTSEL[2:0] : External event select for injected group

These bits select the external event used to trigger the start of conversion of an injected group:

Bit 11 ALIGN : Data alignment

This bit is set and cleared by software. Refer to Figure 29 and Figure 30 .

Bits 10:9 Reserved, must be kept at reset value.

Bit 8 DMA : Direct memory access mode

This bit is set and cleared by software. Refer to the DMA controller chapter for more details.

Bits 7:4 Reserved, must be kept at reset value.

Bit 3 RSTCAL : Reset calibration

This bit is set by software and cleared by hardware. It is cleared after the calibration registers are initialized.

Note: If RSTCAL is set when conversion is ongoing, additional cycles are required to clear the calibration registers.

Bit 2 CAL : A/D Calibration

This bit is set by software to start the calibration. It is reset by hardware after calibration is complete.

Bit 1 CONT : Continuous conversion

This bit is set and cleared by software. If set conversion takes place continuously till this bit is reset.

Bit 0 ADON : A/D converter ON / OFF

This bit is set and cleared by software. If this bit holds a value of zero and a 1 is written to it then it wakes up the ADC from Power Down state.

Conversion starts when this bit holds a value of 1 and a 1 is written to it. The application should allow a delay of \( t_{STAB} \) between power up and start of conversion. Refer to Figure 25 .

Note: If any other bit in this register apart from ADON is changed at the same time, then conversion is not triggered. This is to prevent triggering an erroneous conversion.

10.11.4 ADC sample time register 1 (ADC_SMPR1)

Address offset: 0x0C

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedSMP17[2:0]SMP16[2:0]SMP15[2:1]
rwrwrwrwrwrwrwrw
1514131211109876543210
SMP15_0SMP14[2:0]SMP13[2:0]SMP12[2:0]SMP11[2:0]SMP10[2:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:24 Reserved, must be kept at reset value.

Bits 23:0 SMPx[2:0] : Channel x Sample time selection

These bits are written by software to select the sample time individually for each channel. During sample cycles channel selection bits must remain unchanged.

ADC1 analog Channel16 and Channel 17 are internally connected to the temperature sensor and to V REFINT , respectively.

10.11.5 ADC sample time register 2 (ADC_SMPR2)

Address offset: 0x10

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedSMP9[2:0]SMP8[2:0]SMP7[2:0]SMP6[2:0]SMP5[2:1]
Res.rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
SMP5_0SMP4[2:0]SMP3[2:0]SMP2[2:0]SMP1[2:0]SMP0[2:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:30 Reserved, must be kept at reset value.

Bits 29:0 SMPx[2:0] : Channel x Sample time selection

These bits are written by software to select the sample time individually for each channel. During sample cycles channel selection bits must remain unchanged.

000: 1.5 cycles

001: 7.5 cycles

010: 13.5 cycles

011: 28.5 cycles

100: 41.5 cycles

101: 55.5 cycles

110: 71.5 cycles

111: 239.5 cycles

10.11.6 ADC injected channel data offset register x (ADC_JOFRx) (x=1..4)

Address offset: 0x14-0x20

Reset value: 0x0000 0000

31302928272625242322212019181716
Reserved
1514131211109876543210
ReservedJOFFSETx[11:0]
rwrwrwrwrwrwrwrwrwrwrw

Bits 31:12 Reserved, must be kept at reset value.

Bits 11:0 JOFFSETx[11:0] : Data offset for injected channel x

These bits are written by software to define the offset to be subtracted from the raw converted data when converting injected channels. The conversion result can be read from in the ADC_JDRx registers.

10.11.7 ADC watchdog high threshold register (ADC_HTR)

Address offset: 0x24

Reset value: 0x0000 0FFF

31302928272625242322212019181716
Reserved
1514131211109876543210
ReservedHT[11:0]
rwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:12 Reserved, must be kept at reset value.

Bits 11:0 HT[11:0] : Analog watchdog high threshold

These bits are written by software to define the high threshold for the analog watchdog.

Note: The software can write to these registers when an ADC conversion is ongoing. The programmed value will be effective when the next conversion is complete. Writing to this register is performed with a write delay that can create uncertainty on the effective time at which the new value is programmed.

10.11.8 ADC watchdog low threshold register (ADC_LTR)

Address offset: 0x28

Reset value: 0x0000 0000

31302928272625242322212019181716
Reserved
1514131211109876543210
ReservedLT[11:0]
rwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:12 Reserved, must be kept at reset value.

Bits 11:0 LT[11:0] : Analog watchdog low threshold

These bits are written by software to define the low threshold for the analog watchdog.

Note: The software can write to these registers when an ADC conversion is ongoing. The programmed value will be effective when the next conversion is complete. Writing to this register is performed with a write delay that can create uncertainty on the effective time at which the new value is programmed.

10.11.9 ADC regular sequence register 1 (ADC_SQR1)

Address offset: 0x2C

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedL[3:0]SQ16[4:1]
rwrwrwrwrwrwrwrw
1514131211109876543210
SQ16_0SQ15[4:0]SQ14[4:0]SQ13[4:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:24 Reserved, must be kept at reset value.

Bits 23:20 L[3:0] : Regular channel sequence length

These bits are written by software to define the total number of conversions in the regular channel conversion sequence.

0000: 1 conversion

0001: 2 conversions

.....

1111: 16 conversions

Bits 19:15 SQ16[4:0] : 16th conversion in regular sequence

These bits are written by software with the channel number (0..17) assigned as the 16th in the conversion sequence.

Bits 14:10 SQ15[4:0] : 15th conversion in regular sequence

Bits 9:5 SQ14[4:0] : 14th conversion in regular sequence

Bits 4:0 SQ13[4:0] : 13th conversion in regular sequence

10.11.10 ADC regular sequence register 2 (ADC_SQR2)

Address offset: 0x30

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedSQ12[4:0]SQ11[4:0]SQ10[4:1]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
SQ10_0SQ9[4:0]SQ8[4:0]SQ7[4:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:30 Reserved, must be kept at reset value.

Bits 29:26 SQ12[4:0] : 12th conversion in regular sequence

These bits are written by software with the channel number (0..17) assigned as the 12th in the sequence to be converted.

Bits 24:20 SQ11[4:0] : 11th conversion in regular sequence

Bits 19:15 SQ10[4:0] : 10th conversion in regular sequence

Bits 14:10 SQ9[4:0] : 9th conversion in regular sequence

Bits 9:5 SQ8[4:0] : 8th conversion in regular sequence

Bits 4:0 SQ7[4:0] : 7th conversion in regular sequence

10.11.11 ADC regular sequence register 3 (ADC_SQR3)

Address offset: 0x34

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedSQ6[4:0]SQ5[4:0]SQ4[4:1]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
SQ4_0SQ3[4:0]SQ2[4:0]SQ1[4:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:30 Reserved, must be kept at reset value.

Bits 29:25 SQ6[4:0] : 6th conversion in regular sequence

These bits are written by software with the channel number (0..17) assigned as the 6th in the sequence to be converted.

Bits 24:20 SQ5[4:0] : 5th conversion in regular sequence

Bits 19:15 SQ4[4:0] : fourth conversion in regular sequence

Bits 14:10 SQ3[4:0] : third conversion in regular sequence

Bits 9:5 SQ2[4:0] : second conversion in regular sequence

Bits 4:0 SQ1[4:0] : first conversion in regular sequence

10.11.12 ADC injected sequence register (ADC_JSQR)

Address offset: 0x38

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedJL[1:0]JSQ4[4:1]
rwrwrwrwrwrw
1514131211109876543210
JSQ4_0JSQ3[4:0]JSQ2[4:0]JSQ1[4:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:22 Reserved, must be kept at reset value.

Bits 21:20 JL[1:0] : Injected sequence length

These bits are written by software to define the total number of conversions in the injected channel conversion sequence.

00: 1 conversion

01: 2 conversions

10: 3 conversions

11: 4 conversions

Bits 19:15 JSQ4[4:0] : fourth conversion in injected sequence (when JL[1:0] = 3) (1)

These bits are written by software with the channel number (0..17) assigned as the fourth in the sequence to be converted.

Note: Unlike a regular conversion sequence, if JL[1:0] length is less than four, the channels are converted in a sequence starting from (4-JL). Example: ADC_JSQR[21:0] = 10 00011 00011 00111 00010 means that a scan conversion will convert the following channel sequence: 7, 3, 3, 3. (not 2, 7, 3)

Bits 14:10 JSQ3[4:0] : third conversion in injected sequence (when JL[1:0] = 3)

Bits 9:5 JSQ2[4:0] : second conversion in injected sequence (when JL[1:0] = 3)

Bits 4:0 JSQ1[4:0] : first conversion in injected sequence (when JL[1:0] = 3)

  1. When JL=3 ( 4 injected conversions in the sequencer), the ADC converts the channels in this order:
    JSQ1[4:0] >> JSQ2[4:0] >> JSQ3[4:0] >> JSQ4[4:0]
    When JL=2 ( 3 injected conversions in the sequencer), the ADC converts the channels in this order:
    JSQ2[4:0] >> JSQ3[4:0] >> JSQ4[4:0]
    When JL=1 ( 2 injected conversions in the sequencer), the ADC converts the channels in this order:
    JSQ3[4:0] >> JSQ4[4:0]
    When JL=0 ( 1 injected conversion in the sequencer), the ADC converts only JSQ4[4:0] channel

10.11.13 ADC injected data register x (ADC_JDRx) (x= 1..4)

Address offset: 0x3C - 0x48

Reset value: 0x0000 0000

31302928272625242322212019181716
Reserved
1514131211109876543210
JDATA[15:0]
rrrrrrrrrrrrrrrr

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:0 JDATA[15:0] : Injected data

These bits are read only. They contain the conversion result from injected channel x. The data is left or right-aligned as shown in Figure 29 and Figure 30 .

10.11.14 ADC regular data register (ADC_DR)

Address offset: 0x4C

Reset value: 0x0000 0000

31302928272625242322212019181716
Reserved
1514131211109876543210
DATA[15:0]
rrrrrrrrrrrrrrrr

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:0 DATA[15:0] : Regular data

These bits are read only. They contain the conversion result from the regular channels. The data is left or right-aligned as shown in Figure 29 and Figure 30 .

10.11.15 ADC register map

The following table summarizes the ADC registers.

Table 62. ADC register map and reset values

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00ADC_SRReservedSTRTJSRTJEOCEOCAWD
Reset value00000
0x04ADC_CR1ReservedAWDENJAWDENReservedDISCNUM [2:0]JDISCENDISCENJAUTOAWDSGLSCANJEOCIENAWDIEEOCIEAWDCH[4:0]
Reset value00000000000
0x08ADC_CR2ReservedTSVREFESWSTARTJSWSTARTEXTTRIGEXTSEL [2:0]ReservedJEXTTRIGJEXTSEL [2:0]ALIGNReservedDMAReservedReservedRSTCALCALCONTADONReserved
Reset value00000000000000
0x0CADC_SMPR1Sample time bits SMPx_x
Reset value0000000000000000000000000000000
0x10ADC_SMPR2Sample time bits SMPx_x
Reset value0000000000000000000000000000000
0x14ADC_JOFR1Reserved
Reset value
0x18ADC_JOFR2Reserved
Reset value
0x1CADC_JOFR3Reserved
Reset value
0x20ADC_JOFR4Reserved
Reset value
0x24ADC_HTRReserved
Reset value
0x28ADC_LTRReserved
Reset value
0x2CADC_SQR1ReservedL[3:0]SQ16[4:0] 16th conversion in regular sequence bitsSQ15[4:0] 15th conversion in regular sequence bitsSQ14[4:0] 14th conversion in regular sequence bitsSQ13[4:0] 13th conversion in regular sequence bitsReserved
Reset value

Table 62. ADC register map and reset values (continued)

OffsetRegister313029282726252423222120191817161514131211109876543210
0000000000000000000000000000000
0x30ADC_SQR2ReservedSQ12[4:0] 12th conversion in regular sequence bitsSQ11[4:0] 11th conversion in regular sequence bitsSQ10[4:0] 10th conversion in regular sequence bitsSQ9[4:0] 9th conversion in regular sequence bitsSQ8[4:0] 8th conversion in regular sequence bitsSQ7[4:0] 7th conversion in regular sequence bits
Reset value00000000000000000000000000000
0x34ADC_SQR3ReservedSQ6[4:0] 6th conversion in regular sequence bitsSQ5[4:0] 5th conversion in regular sequence bitsSQ4[4:0] fourth conversion in regular sequence bitsSQ3[4:0] third conversion in regular sequence bitsSQ2[4:0] second conversion in regular sequence bitsSQ1[4:0] first conversion in regular sequence bits
Reset value00000000000000000000000000000
0x38ADC_JSQRReservedJL[1:0]JSQ4[4:0] fourth conversion in injected sequence bitsJSQ3[4:0] third conversion in injected sequence bitsJSQ2[4:0] second conversion in injected sequence bitsJSQ1[4:0] first conversion in injected sequence bits
Reset value000000000000000000
0x3CADC_JDR1Reserved
Reset value
0x40ADC_JDR2Reserved
Reset value
0x44ADC_JDR3Reserved
Reset value
0x48ADC_JDR4Reserved
Reset value
0x4CADC_DRReserved
Reset value
Refer to Table 1 on page 37 and Table 2 on page 38 for the register boundary addresses.