Module17: added VBat measurement to ADC1 driver

This commit is contained in:
Morgan Diepart 2024-01-28 22:44:14 +01:00 committed by Silvano Seva
parent 4f2c461bf0
commit 220d4d2ef4
2 changed files with 15 additions and 1 deletions

View File

@ -107,10 +107,23 @@ uint16_t adcStm32_sample(const struct Adc *adc, const uint32_t channel)
ADC_TypeDef *pAdc = ((ADC_TypeDef *) adc->priv);
/* Channel 18 is Vbat, enable it if requested */
if(channel == 18)
ADC123_COMMON->CCR |= ADC_CCR_VBATE;
pAdc->SQR3 = channel;
pAdc->CR2 |= ADC_CR2_SWSTART;
while((pAdc->SR & ADC_SR_EOC) == 0) ;
return pAdc->DR;
uint16_t value = pAdc->DR;
/* Disconnect Vbat channel. Vbat has an internal x2 voltage divider */
if(channel == 18)
{
value *= 2;
ADC123_COMMON->CCR &= ~ADC_CCR_VBATE;
}
return value;
}

View File

@ -32,6 +32,7 @@ enum AdcChannel
{
ADC_HWVER_CH = 3,
ADC_HMI_HWVER_CH = 13,
ADC_VBAT_CH = 18
};
extern const struct i2cDevice i2c1;