GPIO analog not working

Post here first, or if you can't find a relevant section!
Post Reply
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

GPIO analog not working

Post by mebab »

Hi,
I am using PB4 in STM32L433 as a GPIO analog to simply read an external battery voltage. I use Arduino IDE with the following commands:

Code: Select all

  analogReadResolution(12);
  Battery = analogRead(PB4);
I have already tested this with STM32L476 successfully. However, it reads zero with STM32L433. I also tested other GPIO analog pins with no success. Does anybody know what might be wrong to read the analog value?

Thanks for your support!
by GonzoG » Sun Jan 02, 2022 11:29 am
First, MCU datasheet is your friend.
There you have all information, and it clearly specifies which pins are ADC input: PA0-PA7, PB0-PB1, PC0-PC5.

Analog, doesn't mean ADC. There are analog comparators, analog outputs (DAC), OPAMPS, and probably more.
Go to full post
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: GPIO analog not working

Post by GonzoG »

So it's working fine.
PB4 is not an ADC input on L433.
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: GPIO analog not working

Post by mebab »

I understand that (PA0 to PA7) and some other pins are connected to ADC. However, what do other GPIO analog pins do in terms of connection to ADC?
If you use Cube MX, you have different options to define some other pins like PB4 as GPIO analog. In the datasheet block diagram (page 16), ADC is connected to all ports (A, B, C, ...). This is why I believe that PB4 can be used as a GPIO analog.

It looks like that I need to link GPIO analog to ADC. Then the question is how to do this in Arduino IDE-based code?
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: GPIO analog not working

Post by GonzoG »

First, MCU datasheet is your friend.
There you have all information, and it clearly specifies which pins are ADC input: PA0-PA7, PB0-PB1, PC0-PC5.

Analog, doesn't mean ADC. There are analog comparators, analog outputs (DAC), OPAMPS, and probably more.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: GPIO analog not working

Post by ag123 »

use pa0 - pa7, they are almost always there, but as always check the data sheets.
just remember, if you have to do without the duino* or cube-MX, you only have the raw bare metal hardware and its registers, that is all that matters.
always go back to the datasheets and ref manual for the chip in context, there is no other way around this.
for the small memory and flash constrainted mcus like those with 4k sram and 8k flash, some resort to assembly language to program them, not even C.
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: GPIO analog not working

Post by mebab »

Thank you very much!
Post Reply

Return to “General discussion”