The ADC samples the voltage on an input, compares it with the reference voltage and returns a number of 16, 14, 12, 10 or 8 bits. At 16 bits, 0 V gives 0 and VREF+ gives 65535. Every input is a channel (INP0, INP1, … and INN0 for the negative side of a differential pair), and a sequence lists which channels to convert and in what order. Before each conversion the ADC charges a small capacitor from the pin for a set time, the sampling time.
The H7 ADC does not work out of the box, and each trap has its own register bit: the converter has its own kernel clock that is off after reset, it starts in deep power-down, it needs a calibration, and every channel must be preselected. The converter can also be started by a timer trigger and write its results to memory with DMA, which is how you sample at an exact rate without CPU work.
- Reading a potentiometer, a light sensor, a battery divider or any analog sensor on the Arduino A0 to A5 pins
- Sampling at an exact rate: a timer trigger starts each conversion, and DMA stores the results
- Measuring the chip itself: internal temperature sensor, VBAT and the internal reference VREFINT
- Watching a level without the CPU: the analog watchdog raises an interrupt when a value leaves a window
Read in this order
The shortest path through the documents. Each link opens the exact page; the line under it says what to look for.
- RM043325.2 ADC main featuresp.913One page: resolution, channels, triggers, oversampler, watchdogs
- RM043325.4.3 ADC clocksp.917The two clock options (own kernel clock or AHB clock) and the BOOST rule
- RM043325.4.6 ADC deep-power-down mode (DEEPPWD) and ADC voltage regulator (ADVREGEN)p.923DEEPPWD and ADVREGEN: how to wake the ADC up, and the wait that follows
- RM043325.4.8 Calibration (ADCAL, ADCALDIF, ADCALLIN, ADC_CALFACT)p.924ADCAL: the calibration procedure, which must run with the ADC disabled
- RM043325.4.12 Channel preselection register (ADC_PCSEL)p.932Why every converted channel needs its ADC_PCSEL bit first
- RM043325.4.13 Channel-wise programmable sampling time (SMPR1, SMPR2)p.933The eight sampling times, set per channel in ADC_SMPR1 and ADC_SMPR2
- RM043325.4.19 Conversion on external trigger and trigger polarity (EXTSEL, EXTEN, JEXTSEL, JEXTEN)p.938Table of triggers: timer outputs such as tim3_trgo start a conversion by hardware
- RM043325.4.7 Single-ended and differential input channelsp.924INP only, or INP minus INN, and how the result is computed
Registers to learn first
In the order you usually program them. The other 24 registers of the chapter can wait until you need them.
| 1 | RCC_AHB1ENR | ADC12EN: bus clock of ADC1 and ADC2 (ADC3 has its own enable bit in another register) | p.453 |
| 2 | RCC_D3CCIPR | ADCSEL: kernel clock of the ADCs. The reset value is PLL2_P, which is off, so pick another source | p.417 |
| 3 | ADCx_CCR | Shared by ADC1 and ADC2: clock mode (CKMODE) and the divider PRESC | p.1035 |
| 4 | ADC_CR | Power and run control: DEEPPWD, ADVREGEN, ADCAL, ADEN, ADSTART and BOOST | p.1001 |
| 5 | ADC_PCSEL | One bit per input channel; a channel must be set here before it is converted | p.932 |
| 6 | ADC_SQR1 | The conversion sequence: how many channels (L) and the first ones in order | p.1020 |
| 7 | ADC_SMPR2 | Sampling time of channels 10 to 18 (ADC_SMPR1 covers channels 0 to 9) | p.1017 |
| 8 | ADC_CFGR | Resolution (RES), continuous mode, trigger source and polarity, DMA mode | p.1010 |
| 9 | ADC_DR | The conversion result. Reading it clears the end-of-conversion flag | p.1024 |
All 32 registers in Analog-to-digital converters (ADC)
On this board
| Net | Pin | Signal | Note |
|---|---|---|---|
| ARD_A0 | PC0 | analog ADC123_INP10 | Arduino A0 = PC0, ADC123_INP10: on ADC1, ADC2 and ADC3. The pin the ADC guide measures |
| ARD_A1 | PF8 | analog ADC3_INN3, analog ADC3_INP7 | Arduino A1 = PF8, ADC3 only (INP7, INN3) |
| ARD_A2 | PA0_C | analog ADC12_INN1, analog ADC12_INP0 | Arduino A2 = the PA0_C pad, ADC12_INP0. A separate analog pad next to PA0; the SYSCFG_PMCR bit PA0SO controls the switch between the two |
| ARD_A3 | PA1_C | analog ADC12_INP1 | Arduino A3 = the PA1_C pad, ADC12_INP1. Same kind of analog pad (switch bit PA1SO) |
| ARD_A4 | PC2_C | analog ADC3_INN1, analog ADC3_INP0 | Arduino A4 = the PC2_C pad, ADC3_INP0. Analog pad (switch bit PC2SO) |
| ARD_A5 | PC3_C | analog ADC3_INP1 | Arduino A5 = the PC3_C pad, ADC3_INP1. Analog pad (switch bit PC3SO) |
Header pins you can wire to
Arduino and STMod+ header pins whose MCU pin can carry a ADC signal (from the datasheet AF tables).
On this chip
5 instances found in the datasheet’s alternate-function tables, with every pin that can carry each signal.
| Instance | Signals and the pins that can carry them |
|---|---|
| ADC1 | INN2PF12INN16PA1INP2PF11INP6PF12INP16PA0INP17PA1 |
| ADC2 | INN2PF14INP2PF13INP6PF14 |
| ADC3 | INN1PC2_CINN2PF10INN3PF8INN4PF6INN5PF4INN13PH3INN14PH4INN15PH5INP0PC2_CINP1PC3_CINP2PF9INP3PF7INP4PF5INP5PF3INP6PF10INP7PF8INP8PF6INP9PF4INP13PH2INP14PH3INP15PH4INP16PH5 |
| ADC12 | INN1PA0_CINN3PA7INN4PC5INN5PB0INN12PC3INN18PA5INP0PA0_CINP1PA1_CINP3PA6INP4PC4INP5PB1INP7PA7INP8PC5INP9PB0INP13PC3INP14PA2INP15PA3INP18PA4INP19PA5 |
| ADC123 | INN10PC1INN11PC2INP10PC0INP11PC1INP12PC2 |
Map of the chapter
Every reference-manual chapter has the same shape. Sections marked ● are in the reading order above.
Common mistakes
- No clock after reset.
ADCSELinRCC_D3CCIPRresets to PLL2_P, and PLL2 is off. Select another kernel clock or the ADC never starts. - Starting a conversion while the ADC is still in deep power-down. After reset
DEEPPWDis 1 (reset value ofADC_CRis 0x2000 0000). Clear it, setADVREGEN, wait for the regulator, then calibrate withADCALbeforeADEN. - Forgetting
ADC_PCSEL. The channel in the sequence must also have its preselection bit set, or the result is not guaranteed. - A wrong
BOOSTsetting. It must match the ADC clock, and the bit layout differs between silicon revisions V and Y, so check theADC_CRentry for your chip. - Trusting 3.3 V as VREF+. On this board VREF+ is tied to the analog supply VDDA through R66 (0 Ω, schematic sheet 4), so supply noise appears in every reading. Measure it for accurate work.