2024-07-17 06:20 PM - last edited on 2024-07-17 11:09 PM by Peter BENSCH
Hi,
I am just trying to run adc in discontonous mode to measure some voltate from two resistor divider connected on channel 6 (PA1) and channel 7 (PA2) and also Vref from internal channel 12 as per datasheet. see below screenshot from DS14581- Rev2
below is the code
RCC->APBENR2|=RCC_APBENR2_ADCEN; //enable adc clock
ADC1_COMMON->CCR=ADC_CCR_VREFEN; //
ADC1->CFGR2|=(1<<ADC_CFGR2_CKMODE_Pos); clock divide by 2
ADC1->CFGR1|=ADC_CFGR1_DISCEN; // discontinuos mode
ADC1->SMPR=0x05; //sampling time setting
ADC1->CR=ADC_CR_ADCAL|ADC_CR_ADVREGEN; // start adc calibration
while((ADC1->CR)&(ADC_CR_ADCAL)) // wait while adc calibraion is not complete
{};
ADC1->CR=ADC_CR_ADEN; // ADC enable
ADC1->CHSELR=ADC_CHSELR_CHSEL6|ADC_CHSELR_CHSEL7|ADC_CHSELR_CHSEL12;// select channels to be converted
ADC1->CR=0x05; //ADC enable and start conversion.
uint16_t adc_data=ADC1->DR;
I have tested that when I choose below configuration for channels . I get the desired results.
ADC1->CHSELR=ADC_CHSELR_CHSEL5|ADC_CHSELR_CHSEL6|ADC_CHSELR_CHSEL11;
So that clearly means that ADC channel 5 is connected to PA1, ADC channel 6 is connected to PA2 and VREFINT is ADC channel 11 in contrast to what is mentioned in the reference manual RM0503 Rev2. and the datasheet of the product.
Please confirm.