diff --git a/Drivers/Sources/Driver_ADC.c b/Drivers/Sources/Driver_ADC.c index f76579e..7ba4737 100644 --- a/Drivers/Sources/Driver_ADC.c +++ b/Drivers/Sources/Driver_ADC.c @@ -1,27 +1,44 @@ #include "Driver_ADC.h" +#include "Driver_GPIO.h" +//----------------------INIT--------------------// void MyADC_Base_Init(MyADC_Struct_TypeDef * ADC){ - RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; //Division par 6 de la clock (72MHz) pour l'ADC (14MHz max) - if(ADC->ADC == ADC1){ - RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //Enable Clock ADC1 - ADC1->CR2 |= ADC_CR2_ADON; //Enable ADC1 - ADC1->SQR1&= ADC_SQR1_L; - ADC1->SQR3|= 8; - - }else if(ADC->ADC == ADC2){ - RCC->APB2ENR |= RCC_APB2ENR_ADC2EN; //Enable Clock ADC1 - ADC1->CR2 |= ADC_CR2_ADON; //Enable ADC1 - ADC1->SQR1&= ADC_SQR1_L; - ADC1->SQR3|= 8; + //Division par 6 de la clock (72MHz) pour l'ADC (14MHz max) + RCC->CFGR |= RCC_CFGR_ADCPRE_DIV6; + + //Selection du channel PC0 pour l'ADC + MyGPIO_Struct_TypeDef * GPIO_ADC; + GPIO_ADC->GPIO = GPIOC; + GPIO_ADC->GPIO_Conf = In_Analog; + GPIO_ADC->GPIO_Pin = 0; + + + //Selection entre ADC1 ou ADC2 + if(ADC->ADC == ADC1){ + RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //Enable Clock ADC1 + }else if(ADC->ADC == ADC2){ + RCC->APB2ENR |= RCC_APB2ENR_ADC2EN; //Enable Clock ADC2 } } + +//---------------------START--------------------// void MyADC_Base_Start(ADC_TypeDef * ADC){ - + if(ADC == ADC1){ + ADC1->CR2 |= ADC_CR2_ADON; //Enable ADC1 + } else if (ADC == ADC2){ + ADC2->CR2 |= ADC_CR2_ADON; //Enable ADC2 + } } + +//---------------------STOP--------------------// void MyADC_Base_Stop(ADC_TypeDef * ADC){ - + if(ADC == ADC1){ + ADC1->CR2 &= ~ADC_CR2_ADON; + }else if(ADC == ADC2){ + ADC2->CR2 &= ~ADC_CR2_ADON; + } }