Skip to main content
MSilv.1
Associate III
June 4, 2020
Question

Analog and Digital in the same pin

  • June 4, 2020
  • 5 replies
  • 1503 views

sorry for my english

I have a LCD TFT 480x320 with touch, and the pins like for the arduino. He is working very fine with STM32F407ZG, its all OK, I converted MCUFRIEND_KBV, with help from developer, to stm32. But i need to use the touch, but theproblem is in this. The touch, share pins with the digital pins. the touch analog read is in the same pin of the CS (sample).

In Arduino, its easy, only change pinmode from digital to analog, read analog, and then turn again to digital.

But in stm32cubeide, where i need to turn on the ADC and INx on the .ioc, I need to know. Can I turn on the ADC, and in the run time, turn off to use the pin as digital, and turn on only when i need to read the touch?

Thanks a lot.

Moacir Jr.

This topic has been closed for replies.

5 replies

S.Ma
Principal
June 4, 2020

yes if you hack cubemx which assumes static config. set cube mx in analog mode, then manually change mode pin to digital input. you also need to check if you need to activate internal pull up/down resistor if needed in analog mode....

MSilv.1
MSilv.1Author
Associate III
June 4, 2020

cool.. i will try do this... idea...

But one question, why have pins, like PE14 and PE15, that have GPIO Analog type, but do not have ADC or IN connected?

berendi
Principal
June 4, 2020

Read about the GPIO MODER register in the reference manual. Use bitwise operators on it to set pin modes at runtime.​

MSilv.1
MSilv.1Author
Associate III
June 4, 2020

Yes, i know MODER from NXP LPC Arm. I am using HAL functions in STM32. But i think this is valid too... thanks

berendi
Principal
June 4, 2020

> I am using HAL functions in STM32.

Of course you can do it with HAL functions too, just the documentation is not too usable.

> why have pins, like PE14 and PE15, that have GPIO Analog type, but do not have ADC or IN connected?

It is recommended to configure unused pins as analog to reduce power consumption. Don't bother with it unless your board runs on battery power.