2022-06-03 06:46 AM
I have a project where i use the HAL library to poll the ADC.
Controller STM32G473VC. Cube IDE 1.9.0
.
During the code i call ADC_24V_getADCvalue() at different places but never in interrupt routines .
Even though after a few calls HAL_ADC_ConfigChannel returns always HAL_LOCK.
Any idea ?
static ADC_HandleTypeDef *phandleradc1,*phandleradc2;
static ADC_ChannelConfTypeDef sConfig = { 0 };
void analog_init(ADC_HandleTypeDef *phadc1, ADC_HandleTypeDef *phadc2) {
phandleradc1 = phadc1;
phandleradc2 = phadc2;
sConfig.SamplingTime = ADC_SAMPLETIME_640CYCLES_5;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
}
static uint16_t GetADCValueADC2(){
uint16_t result;
HAL_ADC_Start(phandleradc2);
HAL_ADC_PollForConversion(phandleradc2,2);
result = HAL_ADC_GetValue(phandleradc2);
HAL_ADC_Stop(phandleradc2);
return result;
}
uint16_t ADC_24V_getADCvalue(void) {
HAL_StatusTypeDef result;
sConfig.Channel = ADC_CHANNEL_3;
result = HAL_ADC_ConfigChannel(phandleradc2, &sConfig);
if (result != HAL_OK) {
Error_Handler();
}
return GetADCValueADC2();
}