2022-01-27 2:37 AM
code:
/* USER CODE BEGIN 2 */
HAL_UART_Transmit(&hlpuart1, (uint8_t *)"Basladi\r\n", 9, 100);
HAL_ADC_Start(&hadc);
#define VREFINT_CAL_ADDR 0x1FF80078
#define VREFINT_CAL ((uint16_t*) VREFINT_CAL_ADDR)
#define MAX_VOLTAGE 3000.0
uint32_t VREFINTADC;
char buffer[23];
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
VREFINTADC=HAL_ADC_GetValue(&hadc);
float VDD = MAX_VOLTAGE * (*VREFINT_CAL / (float) VREFINTADC);
sprintf(buffer, "%f", VDD);
HAL_UART_Transmit(&hlpuart1, (uint8_t *)buffer, 5, 1000);
HAL_UART_Transmit( &hlpuart1, (uint8_t *)"\r\n", 2, 100);
HAL_Delay(2000);
}
2022-01-27 3:23 AM
Have you proved that your code actually works using various known input voltages; eg, supplied from a potentiometer?
You need to show the schematic of how you've connected the ADC input to the battery; it's not "behind" a voltage regulator - is it?
2022-01-27 3:31 AM
You cant start ADC and immediately get value.
/* USER CODE BEGIN 3 */
//here add pool for value ... or wait for complete flag or how yuo config ADC
VREFINTADC=HAL_ADC_GetValue(&hadc);
2022-01-27 3:37 AM
@MM..1 "pool (sic) for value"
* poll
2022-01-27 3:51 AM
And please remember that with the STM32L010C6 a measurement is always relative to VDD because VREF is not accessible due to the pin limitation of the package.
Absolute measurements are thus only possible indirectly by performing them with two measurements:
Afterwards, both have to be put in relation to each other to get an absolute value.
Regards
/Peter
2022-01-27 4:09 AM
Alternatively, if VDD is directly connected to the battery, a measurement of Vrefint (which is constant) relative to VDD (which changes with battery voltage) will give you a measurement of the battery voltage ...
EDIT
If VDD is supplied via a regulator, this might (depending on the system) enable you to detect when the battery has fallen to such a level that the regulator can no longer regulate...
2022-01-27 9:04 AM
2022-01-27 9:06 AM
hello, I didn't quite understand what you mean, but I connected a cable between the + part on the breadboard and the adc pin input. I'm currently running the power from the power supply. The power supply is adjustable, I can increase or decrease it. i will put battery after the code works
2022-01-27 9:08 AM
hello, I didn't quite understand what you mean, but I connected a cable between the + part on the breadboard and the adc pin input. I'm currently running the power from the power supply. The power supply is adjustable, I can increase or decrease it. After the code works, I will put a battery. What does it mean can't access Vref? What does a meter on the ADC input mean?
2022-01-27 9:11 AM
I watched videos about ADC, but I could not understand this subject (voltage measurement with ADC-Vref Internal). I need help. Are there any resources you can recommend?