cancel
Showing results for 
Search instead for 
Did you mean: 

How to set GPIO as analog

OGarc
Associate

I wish to know how Can I set a pin as analog input for ADC.

Bits 31:0MODE[15:0][1:0]: Port x configuration I/O pin y (y = 15 to 0)
These bits are written by software to configure the I/O mode.
00: Input mode 
01: General purpose output mode
10: Alternate function mode
11: Analog mode (reset state)

GPIO_MODER_MODE14_? | GPIO_MODER_MODE15_?;

1 REPLY 1

If, for example, you want to set PB12 as analog, you can write

GPIOB->MODER |= (3 << (2 * 12));

or

GPIOB->MODER |= (3 << GPIO_MODER_MODE12_Pos);

Note, that it's the reset state in many STM32 families, mainly the STM32Lxx (as is given also in the snippet of documetnation you posted above).

JW