I have a STM32WB55CGU6 where I have all my ADC pins used up and im trying to obtain the battery level using a pin which does not have a ADC (PB6) which is branched as shown in the picture attached.
This follows the principle where it will charge and discharge following this link : link
This is my current program but somehow it doesnt work and im pretty sure im doing something wronf but what I am not too sure.
while(1){
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
HAL_Delay(1);
HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6);
while(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)==1){
time++;
}
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)==0){value = time;}
}
Im programming with STMCubeIDE where I have set the pin to GPIO_Output