2020-06-16 04:59 AM
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
2020-06-16 05:51 AM
If the pin
2020-06-16 05:52 AM
You never set the pin as input. You just set it as output and wait for its value to change. That's not going to happen. Re-read what the link you posted says you should do:
2020-06-16 06:03 AM
Hello,
I am working with the writer of the post in the same team. We have already tried the following code as well:
/*Configure GPIO pin : PB6 */
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
HAL_Delay(5);
/*Configure GPIO pin : PB6 */
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT; // analog Input
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
test = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6); // it gives us 0 or 1 -
Where we get lost is how do we increment the counter while we wait? We have tried various options, nothing works. Would you mind explaining this to us, or even maybe showing us the code?
Thank you,
Bogdan