Skip to main content
ATahi.1
Associate
September 9, 2020
Solved

How to set unused gpio pins to analog input in code?

  • September 9, 2020
  • 3 replies
  • 1600 views

It is recomanded to set unused pins to analog input.

This topic has been closed for replies.
Best answer by waclawek.jan

In STM32L0xx, pins are set to Analog by default after reset, you don't need to do anything else. See GPIOx_MODER description in GPIO chapter of the RM.

JW

3 replies

waclawek.jan
Super User
September 9, 2020

Which STM32?

If those which don't have this by default after reset, maybe the easiest is to set all fields in GPIOx_MODER to Analog for all GPIOx, before any other GPIO setup. Of course, the GPIOx clocks have to be enabled in RCC before that. Make sure the SWD pins are not changed, if debugging ought to remain usable.

JW

ATahi.1
ATahi.1Author
Associate
September 9, 2020

@Community member​  Thanks for the answer. I am using STM32L072RZ.

If I want to set all the 16 pins for port A to analog input is this possible to do in this way:

GPIOA->MODER = GPIO_MODE_ANALOG;

waclawek.jan
waclawek.janBest answer
Super User
September 9, 2020

In STM32L0xx, pins are set to Analog by default after reset, you don't need to do anything else. See GPIOx_MODER description in GPIO chapter of the RM.

JW