Skip to main content
OGarc
Visitor II
January 31, 2019
Question

How to set GPIO as analog

  • January 31, 2019
  • 1 reply
  • 812 views

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_?;

This topic has been closed for replies.

1 reply

waclawek.jan
Super User
January 31, 2019

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