Skip to main content

Subsection 6.2.2 Part 2: Which Pins Can Do Analog?

Before we can measure anything we need to know which pin to connect the potentiometer to. The STM32C031C6 has one ADC, and a multiplexer in front of it that can connect the converter to one of up to 23 channels, some of them external pins and some of them internal signals. Not every pin is wired to a channel, and the only authority on which ones are is the datasheet.
You looked up D4 in the Nucleo pinout when you moved the LED to a new pin, and you used Table 13, Port A alternate function mapping to find which pins USART2 could use. Today’s question is answered one table earlier in the same document.
Figure 6.2.3. How to read Table 12, Pin assignment and description, in the STM32C031C6 datasheet. The header row names the columns: the six on the left give the pin number in each package variant (ours is the 48-pin LQFP, the low-profile quad flat package), then the highlighted Pin name column, and on the far right the highlighted Additional functions column, the one that answers today’s question. Read that column three ways. Where it names ADC_INn, as it does for PA1, PA2 and PA3, the pin can be an analog input on channel \(n\text{.}\) Where it shows a dash, as for PF3 and VREF+, the pin has no additional functions at all. And where it names something that is not an ADC_IN (PC14’s OSCX_IN, or PF2-NRST’s NRST), the pin does have an additional function, just not an analog one. Rows are skipped where marked, and the row you actually need is not among those shown.

Activity 6.2.2. Find Your Channel.

Open the STM32C031C6 datasheet and find Table 12, Pin assignment and description.

(a)

Find the row for PA0. Read across to the Additional functions column. What does it say? Does PA0 support analog input, and if so, on which channel?

(b)

Find the row for PA9. Can PA9 be used as an analog input? How do you know?

(c)

The pin you will use today is labeled A0 on the Nucleo’s header, printed on the board beside the pin. Note all three names for it: the Arduino label, the port pin, and the ADC channel number. Keep these. You will need the same three-way translation for a different pin later.
The three numbers happen to agree for A0: it is PA0, and it is channel 0. That is a coincidence. The header label, the port pin and the ADC channel are three independent naming schemes, and for most pins they do not agree, so we’ll look each one up rather than assuming that one follows from the others.
Which channel the converter actually samples is selected by the channel selection register, ADC_CHSELR. Each bit enables one channel: set bit \(n\) to sample channel \(n\text{.}\) (That plain reading holds because CHSELRMOD is 0, its reset value; the register can also be put into a different sequencing mode, which we do not use.)
Figure 6.2.4. The ADC’s input multiplexer, from RM0490 Figure 33. The green labels mark the six port pins that the Nucleo brings out to the Arduino analog header. Most of the other numbered channels do reach package pins too, and Table 12 is what tells you which. Four channels reach no pin at all: VSENSE, VREFINT, VDDA and VSSA are internal signals (among them the on-chip temperature sensor and the internal reference) that this same ADC can measure with no external wiring whatsoever. Bit \(n\) of ADC_CHSELR selects channel \(n\) (RM0490 §14.12.9).