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