fix ADC lockup while reading

This commit is contained in:
true 2024-08-02 17:33:20 -07:00
parent 70bf2c481f
commit d42f20773b
1 changed files with 11 additions and 9 deletions

View File

@ -81,17 +81,19 @@ void adc_convert()
void adc_read()
{
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
adc_val[adc_val_idx++] = ADC_GetConversionValue(ADC1);
adc_val_idx &= 0x0f;
if (!adc_val_idx) adc_calc_avg();
if (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)) {
adc_val[adc_val_idx++] = ADC_GetConversionValue(ADC1);
adc_val_idx &= 0x0f;
if (!adc_val_idx) adc_calc_avg();
if (ADC1->CTLR1 & ADC_JAUTO) {
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_JEOC));
lsens_val = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_1);
if (ADC1->CTLR1 & ADC_JAUTO) {
if (ADC_GetFlagStatus(ADC1, ADC_FLAG_JEOC)) {
lsens_val = ADC_GetInjectedConversionValue(ADC1, ADC_InjectedChannel_1);
// reset LSENS
ADC_AutoInjectedConvCmd(ADC1, DISABLE);
// reset LSENS
ADC_AutoInjectedConvCmd(ADC1, DISABLE);
}
}
}
}