#include "stm32f10x.h" #include "../../Drivers/gpiodriver.h" #define ADCPRE 14 #define SQ1 0 #define ADON 0 int main (void) { MyGPIO_Struct_TypeDef led = {GPIOA,5,Out_PullUp}; //led MyGPIO_Struct_TypeDef adc = {GPIOC,0,In_Analog}; char voltageOverflow = 0; MyGPIO_Init(&led); MyGPIO_Init(&adc); RCC->CFGR |= RCC_CFGR_ADCPRE_1;// ADC Prescaler : divided by 6 -> 72MHz to 12MHz RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //We activate the clock first //ADC1->CR1 |= (0x0<<24); //Resolution 12bit -> 00 //ADC1->CR1 |= (0x1<<5); //Interruption //ADC1->CR2 |= (0x1<<30) //Software start conversion ADC1->SMPR1 |= (0x4<<0); // ADC0 cycles : 41 //ADC_SMPR1 0x4<SQR3 |= (10<CR2 |= (0x1<CR2 |= (0x1<DR >= 3102) { MyGPIO_Set(GPIOA,5); voltageOverflow = 1; } else{ if(!voltageOverflow) { MyGPIO_Reset(GPIOA,5); } } }; }