1. Is it possible to switch the function of a GPIO from being used for Analog Input (Vbat detection) to an input pin connected to a switch (refert the sample circuit below)
2. Are there specific methods required for this, or would simply changing the GPIO configuration before and after the battery measurement suffice?
The maximum voltage range for GPIO I/O is between 3.3V and 3.6V, while the VBAT voltage can reach up to 4.2V, which presents a potential risk. If the VBAT voltage can be maintained below 3.3V, measurements can be made using either an external VBAT connection or by outputting a high level from the GPIO.
It's possible, but the megawatt-level voltage divider circuit is not recommended. It is suggested to replace it with a kilo-hundred level one. The reason is that during the operation of the ADC in the chip, there is a dynamic current, which can be regarded as a dynamic resistor with a megawatt-level resistance value.For resistors and capacitors of the 100k level, it is recommended to use values ranging from 0.1 to 1 uf.
TL_BL 发表于 2025-8-6 16:00
It's possible, but the megawatt-level voltage divider circuit is not recommended. It is suggested to ...
okay. so let me get clear again, first i need to replace the resistor with kilo-hundred value resistor and add capacitor.
so about reading the button state. by default do i need to configure the pin as a gpio where by default is use to detect the button state? then when come to read the baterry level, i switch the gpio func by initialize the adc gpio init everytime and change back to as gpio once done reading the battery value?
ManRam 发表于 2025-8-7 10:15
okay. so let me get clear again, first i need to replace the resistor with kilo-hundred value resis ...
There is a vbat detection mode, which can be considered for use. If you want to use the GPIO mode, just try to restore the IO state as much as possible. In the init API, there are operations to change the IO.
TL_BL 发表于 2025-8-7 18:40
There is a vbat detection mode, which can be considered for use. If you want to use the GPIO mode, ...
But in normal gpio mode, there will be still the present of voltage from the voltage divider at the gpio pin. wont this trigger a false press? how do i overcome this.