|
初始化源码
#define ADC_BUFF *(u16*)(0x20000190) #define A01_VALUE *(u16*)(0x20000380) #define A02_VALUE *(u16*)(0x20000382) #define A03_VALUE *(u16*)(0x20000384) #define A04_VALUE *(u16*)(0x20000386) #define ADC1_DR_Address 0x4001244C
DMA_DeInit(DMA_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (u32)(&ADC_BUFF); //AD sample buff DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 4; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA_Channel1, &DMA_InitStructure);
//configure IT //DMA_ITConfig(DMA_Channel1,DMA_IT_TC1, ENABLE); //DMA send end interrupt en
// Enable DMA channel1 DMA_Cmd(DMA_Channel1, ENABLE);
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 4; //4channel ADC_Init(ADC1, &ADC_InitStructure);
// ADC1 regular channel configuration ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 3, ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 4, ADC_SampleTime_55Cycles5);
//ADC_ITConfig //ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
// Enable ADC1 DMA ADC_DMACmd(ADC1, ENABLE);
// Enable ADC1 ADC_Cmd(ADC1, ENABLE);
// Enable ADC1 reset calibration register ADC_ResetCalibration(ADC1); // Check the end of ADC1 reset calibration register while(ADC_GetResetCalibrationStatus(ADC1));
// Start ADC1 calibaration ADC_StartCalibration(ADC1); // Check the end of ADC1 calibration while(ADC_GetCalibrationStatus(ADC1));
// Start ADC1 Software Conversion ADC_SoftwareStartConvCmd(ADC1, ENABLE);
main程式中读取AD的值 u16 *q = &ADC_BUFF; A01_VALUE = *q++; A02_VALUE = *q++; A03_VALUE = *q++; A04_VALUE = *q++; |
|