- static void ADC_Config(void)9 J m4 }. s( ] j9 r; k
- {8 V* L' y! f& J/ k0 K) x# `6 S
- ADC_InitTypeDef ADC_InitStructure;
7 f! p" E0 M$ M$ V0 J6 L
' Z( v8 k; [3 j- + F- q3 P$ U" B2 ?1 R, S! u
- /* ADCs DeInit */
7 s5 i0 Q% ^9 w4 p6 h2 j, B - //ADC_DeInit(ADC1);7 m/ X5 E# _- R2 E2 P
- 7 F* |: p. I+ @4 P
- /* Initialize ADC structure */
( Z& N- Y( t1 P" C - ADC_StructInit(&ADC_InitStructure);
/ X( K) A& R: f3 A
/ Q5 w2 ]: Z3 P3 c9 T6 ^- /* Configure the ADC1 in continuous mode with a resolution equal to 12 bits */. N H2 r) O8 e( b* Y7 T' N
- ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
* o$ o! m. D5 Q& W$ l' k N - ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; * n! A8 H: \* z6 Z, s0 }1 z. H
- ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;' p( m- X: t7 `# m" X2 R
- ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
, c! x! l$ J/ h. Z - ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;
8 E/ P) }3 ?1 g$ t! i) M - ADC_Init(ADC1, &ADC_InitStructure); ! J( c! G% e6 m% |9 y
: u2 |1 R* u8 I+ U& a' ]- /* Convert the ADC1 Channel 9 with 239.5 Cycles as sampling time */ , c! H( @4 Y/ ~7 P
- ADC_ChannelConfig(ADC1, ADC_Channel_9 , ADC_SampleTime_239_5Cycles);! \% n3 E- I/ e; S
- /* ADC Calibration */
/ K; s- i! b8 p# d7 ] - ADC_GetCalibrationFactor(ADC1);
: A) g K1 \, w2 m+ s4 ^8 X - 2 r" B* {. b0 M8 Z: h
- /* ADC DMA request in circular mode */4 J0 _! B8 F* Q$ G" Z/ a7 C
- //ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_Circular);2 G9 A- C( ~' }- V
- 3 Q9 d( w( H- X: v7 O' d) F- U7 X
- /* Enable ADC_DMA */
/ j+ e4 ?/ n; q0 ^0 p/ O - //ADC_DMACmd(ADC1, ENABLE); 9 l- T! U$ V; ]8 g3 I H
7 o( k: s+ `: D* E9 l; Q- /* Enable the ADC peripheral */) q2 g/ N. N6 Y2 m1 n _& u
- ADC_Cmd(ADC1, ENABLE);
9 k. a7 }! q( E) o" I6 m$ @3 g
" S. |2 z* B2 I2 j6 B( q; x# w3 W- /* Wait the ADRDY flag */
; d' r# `/ m7 z. d - while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY)); 2 D. E1 X7 P8 ?5 Z! q6 x Q; _3 y
- - Q3 O* _4 q" i
- /* ADC1 regular Software Start Conv */ + s* @0 c- f9 O, M
- ADC_StartOfConversion(ADC1);
. ?' R0 O1 t r, A' L3 [ - . ~7 i; f& R% v4 e% v
- }8 ]3 P* K4 Q" j# d. ~& C' [! N' w
- 2 u) C5 d1 a. |7 y, ~
- while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));//等待转换结束
! X( E3 J z* S8 F" O - _adc=ADC_GetConversionValue(ADC1);
复制代码
" x. B: @5 W1 _& S4 `* }
# x6 L' r. ]9 L5 O5 n( E: R
& I9 }% b; {2 _, E7 p1 k# |4 e+ M* `; W& e4 ?- x- j
|