RefKEIL/ProjetsKEIL/adc/Source/Principale.c
2023-03-22 16:47:22 +01:00

47 lines
959 B
C

#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 |= (0x2<<ADCPRE); // ADC Prescaler : divided by 6 -> 72MHz to 12MHz
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
//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<<WHATEV (3 bits par bidule)
//RCC_CFGR ADCPRE(bit 14) 10
ADC1->SQR3 |= (10<<SQ1);
ADC1->CR2 |= (0x1<<ADON);
while(1){
ADC1->CR2 |= (0x1<<ADON);
if(ADC1->DR >= 3102)
{
MyGPIO_Set(GPIOA,5);
voltageOverflow = 1;
}
else{
if(!voltageOverflow)
{
MyGPIO_Reset(GPIOA,5);
}
}
};
}