- static void ADC_Config(void)8 C( y6 w1 d) P I- `/ b/ E
- {
D& }5 Z9 g) ]5 c - ADC_InitTypeDef ADC_InitStructure;
& {. l# \6 ]# Z ]" z3 x. g- r* m - . V! y' {% j; U: v% ]5 b
! t4 M/ P& R2 z/ u3 h- /* ADCs DeInit */ ! _' B. z+ l" h$ a8 J
- //ADC_DeInit(ADC1);
- S9 S5 M5 Z( Q* E2 D6 O* x$ n
$ q! ^! _2 S& y! Y- /* Initialize ADC structure */7 n0 p$ _+ z: G" I
- ADC_StructInit(&ADC_InitStructure);
* f8 b4 q2 `: s - * L3 y( X# x& k: {' u
- /* Configure the ADC1 in continuous mode with a resolution equal to 12 bits */ f& ?1 C3 K( N$ I" u6 ~
- ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
' W' j; y2 V# p' V - ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
8 s, X6 a! o1 ~ - ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;9 G) q7 F C: A5 g4 l8 a
- ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;. w2 t- R/ b2 n7 w% q' f! v
- ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;
5 B# o- k* c- Z; u# q, Q. h+ d& a - ADC_Init(ADC1, &ADC_InitStructure);
3 @# I% o: e* K* ]+ u; |7 B) O+ x
" E$ l8 s- Z1 A9 m- /* Convert the ADC1 Channel 9 with 239.5 Cycles as sampling time */
" C. `) @! o+ c) O Q. g5 o - ADC_ChannelConfig(ADC1, ADC_Channel_9 , ADC_SampleTime_239_5Cycles);% D1 M1 e8 n% C" S! B. a
- /* ADC Calibration */, i! E/ g% _ m5 `
- ADC_GetCalibrationFactor(ADC1);1 Q) c( r+ R+ I# A2 k" o" K) f
- , g- Y8 l$ h* Q9 o& m
- /* ADC DMA request in circular mode */- z/ m$ g; f2 q1 F( {( H
- //ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_Circular);
) S! v5 H" i5 z" ~ - , I; Y& g9 a4 x1 e1 e7 Z( Y
- /* Enable ADC_DMA */) x7 m, ]# k6 y+ V! [# V, P
- //ADC_DMACmd(ADC1, ENABLE); 9 _) p& W5 o. t; ?2 Y! [/ Z
! E+ N8 K a W- /* Enable the ADC peripheral */! [( ^ U) U$ m0 t
- ADC_Cmd(ADC1, ENABLE); : j5 T" V* R1 S8 Z. o
1 } G& t9 K! V! ~- /* Wait the ADRDY flag */ @& Q1 H: I& h o
- while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY));
/ r0 G: Q7 v$ M) }; N+ {, r - ( h) n" X3 N- B6 X7 v
- /* ADC1 regular Software Start Conv */ * a/ m1 K8 c2 N( f4 z
- ADC_StartOfConversion(ADC1);5 y$ F- H, Y2 x
d' l) n9 X% a5 e- }' r& _; o# w& I' l) h
r3 v/ U$ ]4 M+ L- while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));//等待转换结束
' X# j, d4 E% R2 [! {) E" ^0 q' A! e - _adc=ADC_GetConversionValue(ADC1);
复制代码
, e6 G4 }- ]; D+ {7 b6 n6 H3 r& s/ _
% n& Y, ~" L# s; w" |* e5 x, p$ Q1 Z7 l
|