cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f103c8t6 change ADC to GPIO and back

Ala
Senior

I have a blue pill which I wish to turn its PA0 pin to ADC mode and then back to GPIO and once again to ADC. I used the code GPIO->MODER which seems doesnt work for F103. any idea how can I do it?

2 REPLIES 2
gbm
Lead III

And what exactly makes you believe that it doesn't work?

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

as in configuration files MODER is not defined in the GPIO structure. also I have tried that out, gave me errors so I coudnt compile the program.

here is my so far approuch

RCC->APB2ENR |=0x0204;//10 0000 0100..Enable Clock for ADC1 and GPIOA
 
RCC->CFGR=0x8000;//PCLK divided by 6
 
GPIOA->CRL=0x00000000;//Configure GPIOA as analog input
 
ADC1->SMPR2=0x0007;//239.5 Cycle
 
ADC1->CR2=0x0003;//enable for first time
 
HAL_Delay(1);
 
ADC1->CR2=0x0003;//enable for second time
 
HAL_Delay(1);

to turn PA0 to ADC. but the thing is it is not yet enabled...

any ideas?