All I am trying to do is convert a single channel of ADC. No interrupts, noDMA, this should be really simple.
The results I am getting are not consistent, so I must be doing somethingdaft.
I have an STM32 discovery and have attached VDD/2 to PC0.
RCC->APB2ENR |=RCC_APB2ENR_ADC1EN; // en clocksADC
RCC->CFGR |=RCC_CFGR_ADCPRE; //set ADC prescaler to div 8 (page 55/519)
GPIOC->CRL &=0xFFFFFFF0; //Configure PC0 as analog input. CNF1,CNF0 = 0, Mode = 00
ADC1->SMPR1 =0x07FFFFFF; //293 cycles per sample
ADC1->SMPR2 = 0xCFFFFFFF;
ADC1->CR2 =0x008E0001; //SW start, ADC enabled, Vref and temp enabled
ADC1->SQR1 =0x0000; //set sequence length to one, all input pointers to CH0
ADC1->SQR2 = 0x0000;
ADC1->SQR3 =0x0000; //presumably CH1
ADC1->CR1 =0x0000; //no WD,no int, single mode
main code is run once ever second
val =ADC1->DR; //read the last conversion
ADC1->CR2 |=ADC_CR2_ADON; // start the nextconversion
Not exactly rocket science
It is not obvious how to select the ADC input in single channel mode, so Iam assuming that SQ1[4:0] is the appropriate mechanism since changing it appearsto affect results.
Any thoughts please ?