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

analogstm32stm32f103voltage measurement

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);
      HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
      raw = HAL_ADC_GetValue(&hadc1);

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

Best Answer

The STM32 ADC does not support reading voltages that are larger than the supply voltage. Either change the joystick reference voltage to match the STM32 voltage or divide the joystick voltage down with resistor divider.

Related Topic