From: Bart Massey Date: Tue, 9 Feb 2016 02:55:28 +0000 (-0800) Subject: Clean up stmf0 adc init. X-Git-Tag: 1.6.3~2^2~101 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=e36117ccbf7cbe3704c6b44d3ad429e720a1e16c Clean up stmf0 adc init. This better matches the documented cal sequence. Signed-off-by: Keith Packard --- diff --git a/src/stmf0/ao_adc_fast.c b/src/stmf0/ao_adc_fast.c index 26e6691c..f6740b0e 100644 --- a/src/stmf0/ao_adc_fast.c +++ b/src/stmf0/ao_adc_fast.c @@ -83,7 +83,6 @@ void ao_adc_init(void) { uint32_t chselr; - int i; /* Reset ADC */ stm_rcc.apb2rstr |= (1 << STM_RCC_APB2RSTR_ADCRST); @@ -157,12 +156,13 @@ ao_adc_init(void) /* Shortest sample time */ stm_adc.smpr = STM_ADC_SMPR_SMP_1_5 << STM_ADC_SMPR_SMP; + /* Turn off enable and start */ + stm_adc.cr &= ~((1 << STM_ADC_CR_ADEN) | (1 << STM_ADC_CR_ADSTART)); + /* Calibrate */ stm_adc.cr |= (1 << STM_ADC_CR_ADCAL); - for (i = 0; i < 0xf000; i++) { - if ((stm_adc.cr & (1 << STM_ADC_CR_ADCAL)) == 0) - break; - } + while ((stm_adc.cr & (1 << STM_ADC_CR_ADCAL)) != 0) + ; /* Enable */ stm_adc.cr |= (1 << STM_ADC_CR_ADEN);