RefKEIL/ProjetsKEIL/Drivers/adcdriver.c

20 lines
886 B
C

#include "adcdriver.h"
void MyADC_Init(MyADC_Struct_TypeDef * ADCStructPtr)
{
RCC->CFGR |= RCC_CFGR_ADCPRE_1; // ADC Prescaler : divided by 6 -> 72MHz to 12MHz
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //We activate the clock first
if(ADCStructPtr->channel < 10)
{
ADCStructPtr->ADC->SMPR2 |= (ADCStructPtr->resolution<<(ADCStructPtr->channel*3)); // Cycle and channel selection
}
else {
ADCStructPtr->ADC->SMPR1 |= (ADCStructPtr->resolution<<((ADCStructPtr->channel-10)*3)); // Cycle and channel selection
}
ADCStructPtr->ADC->SQR3 |= ADCStructPtr->channel; //Sequence Reader, seulement le SQ1 est lu dans notre cas, nous associons un channel à ce dernier.
ADCStructPtr->ADC->CR2 |= ADC_CR2_ADON; //ADON Pour l'instant -> PLUS TARD //ADC1->CR2 |= (0x1<<30) //Software start conversion
if(ADCStructPtr->isIT)
{
ADCStructPtr->ADC->CR1 |= ADC_CR1_EOCIE; //Interruption
}
}