# How to change Voltage Reference in STM32 NUCLEO-F103RB board Analog Input from 3.3V to 5V?

I have a joystick module for Arduino connected to my PA0 pin (that pin is set as ADC1_IN0). I would like to read the voltage from that pin but there is a problem. The voltage on which the joy-stick module operates is 5V and HAL functions I'm using to read Analog values are referencing it against 3.3V, which renders part of the module (which is essentially a potentiometer) useless and nonfunctional as the value given measured is gonna be simply 4095. Here is the code that I have in the while(1) function in main():

      HAL_ADC_Start(&hadc1);


How can I make it reference this voltage against 5V so I can get the full reading?

• You can't measure 5V analog inputs directly with that part. Datasheet page 67, Table 45 "ADC charactersitics" - Vdda max is 3.6V and Vref cannot be higher than Vdda. If you've already tried to put 5V on any of your analog inputs it's likely that you've damaged the part, since none of them are 5V-tolerant pins (Datasheet, page 26, Table 5, look for pins with 'FT' in the I/O Level column). Commented Apr 20, 2020 at 1:35
• @brhans So is there a way for me to measure the whole spectrum of my joystick? I'm very new to STMs. I read on a few pots about similar things like that, that what I would have to do is to measure it against a different voltage provided through some pin. But This (I guess) would require me to use somehow Vref and as I see now from what you linked it cannot exceed 3.6. So Do I have to just cope with it being the maximum or do you maybe see a different solution?
– John
Commented Apr 20, 2020 at 1:36
• You need to reduce the range of your input to match what the STM's ADC can handle. Use a unity-gain rail-to-rail opamp (with 5V supply) to buffer the input then feed it thru a voltage divider (for example a 3k3 + 6k8 would turn 5V into about 3.3V). Commented Apr 20, 2020 at 1:41
• @brhans okay, I understand. I was really hoping that I could solve this just with code. Thank you very much for the help, I'm new to this and I really appreciate your help :D
– John
Commented Apr 20, 2020 at 1:45