Skip to main content
Ala
Senior
July 30, 2022
Question

stm32f103c8t6 change ADC to GPIO and back

  • July 30, 2022
  • 1 reply
  • 864 views

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?

This topic has been closed for replies.

1 reply

gbm
Lead III
July 31, 2022

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
Ala
AlaAuthor
Senior
July 31, 2022

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?