RTE_AD.c 1.63 KB
Newer Older
李俭双's avatar
李俭双 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60


#include "isr.h"
#include "gpio.h"
#include "RTE_AD.h"

void RTC_ADC_Interrupt(void *msg)
{
	INTC_ClearPendingIRQ(ADC_IRQn);     //clear INTAD interrupt flag

}


void RTC_ADC_INIT(uint16_t u16Pin)
{
	uint16_t u16PortIndex;
  uint16_t u16PinIndex;

	GPIO_InitTypeDef      GPIO_InitStructure = {0};
	ADC_InitTypeDef       ADC_InitStructure = {0};
	
	u16PinIndex  = u16Pin & 0x00FFU;
  u16PortIndex = (u16Pin >> 8) & 0x00FFU;
	
	GPIO_InitStructure.GPIO_Pin  = 1U << u16PinIndex;  
	GPIO_InitStructure.GPIO_Ctrl = GPIO_Control_ANA; 
	GPIO_Init(u16PortIndex, &GPIO_InitStructure);

  ADC_InitStructure.ADC_Mode = ADC_Mode_Select; 
	ADC_InitStructure.ADC_ConvSpeed = ADC_ConvSpeed_High; 
	ADC_InitStructure.ADC_Prescaler = ADC_Prescaler_Div32;
	ADC_InitStructure.ADC_RefVoltage = ADC_Ref_Vdd; //????VDD????????
	ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrig_Software; //?��????��?
	ADC_InitStructure.ADC_ContinuousConvMode = ADC_Conv_Continuous;//????????��???
	ADC_InitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_13p5Cycles; 
	ADC_InitStructure.ADC_UpLimit = ADC_UpLimit_Setting; //adc???��??8?? ???����???��??��??????????
	ADC_InitStructure.ADC_LowLimit = ADC_LowLimit_Setting; //adc???��??8?? ???����???��?????????????
	ADC_Init(&ADC_InitStructure);

	ISR_Register(ADC_IRQn, RTC_ADC_Interrupt); //????��????��??��??��
	ISR_DisRegister(ADC_IRQn, RTC_ADC_Interrupt);

}

void RTC_ADC_Converse(ADC_Channel_t ch, uint32_t times, uint16_t *buf)
{
	ADC_Converse(ch, times, buf);
}


void RTC_ADC_Start(ADC_Channel_t ch)
{
  ADC_Start(ch);
}

void RTC_ADC_Stop(void)
{
  ADC_Stop();
}