Page 1 of 1

GPIO analog not working

Posted: Sat Jan 01, 2022 3:14 pm
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!

Re: GPIO analog not working

Posted: Sat Jan 01, 2022 9:59 pm
by GonzoG
So it's working fine.
PB4 is not an ADC input on L433.

Re: GPIO analog not working

Posted: Sun Jan 02, 2022 7:37 am
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?

Re: GPIO analog not working

Posted: Sun Jan 02, 2022 11:29 am
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.

Re: GPIO analog not working

Posted: Sun Jan 02, 2022 11:40 am
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.

Re: GPIO analog not working

Posted: Sun Jan 02, 2022 2:09 pm
by mebab
Thank you very much!