1. 使用 CubeMx 创建 ADC 工程
; g; i6 ~) y u5 @7 @9 [打开 CubeMx 软件,选中我们此次使用的单片机型号 STM32G030F6P6 ,点击 StartProject.1 H6 e# \# o. N! e% T
( p0 ^" r5 l, S* ^8 P& R+ ]: @2 A先配置一下串口,用来打印相关信息- M$ Z0 }5 x4 b& U* d
6 M2 J) S' S# r% F( y; R ?" e, e& d) e/ ^7 S( T) d- n# s" A3 D
# F0 d: Y3 R! q8 P再来配置 ADC/ l& P$ \3 P0 h) u% I6 v1 I1 ?' E
& O1 F5 i* n: @ M
4 f3 c' _7 {0 x& y% G/ O2 B x4 Q* Q1 P
( M- Y6 S% b# H9 F0 l( [! V% I" D# U6 |! I3 t
配置DMA0 ]. J" m+ a+ ?) u: t, r) g
; M% x+ z& }6 J2 k
/ H! R1 ^6 |; Z( b) b6 ePS:DMA 需要要配置成循环模式,否则只填满一次缓存数组后就停止工作,需要重调用启动 DMA 的函数.
4 n) X5 q) M* i- [: T
5 U: v. J0 k5 {8 T' |) B配置时钟; p! V* K5 A3 k9 B% W- n) a2 f
S5 @9 A4 u- H- B9 B! ^
" r4 B4 X# E( `8 E2 Q
& v: W( A3 g6 |8 j" @) cps:本实验使用内部高速时钟,未使用外部晶振,主频设置为最大的64MHZ.
5 |1 T8 R8 u5 \/ R2 U
( z( `* Y" i0 L+ }: d3 j配置工程相关选项
- @! D2 d _) L/ }" b6 @9 H$ _9 j [ D4 }% L$ f8 q
2 {/ @; N9 {0 V$ G
" h+ q1 @/ J- ?) {; p配置完成后点击右上角 GENERATE CODE完成工程的创建
: \) l4 {' U, x0 b' g7 j& V! Q% R% M0 y5 K9 u7 p5 P5 V4 A
2. 编程
6 i, L1 ~- G6 o( i' }5 B% h2.1 串口相关的代码5 m [! T, Z$ [# x
因打印相关信息需要使用 printf ,需要包含 stdio.h 的头文件,且需要重新设 fputc 的函数
$ w8 o4 O' L' A9 ]0 q' { v- /* Includes ------------------------------------------------------------------*/
' }+ ?, U$ }1 Y M" j - #include "main.h"
$ ]3 m. f! Y9 j W' `. S, y - ) U5 F& c% U( o% `) X
- /* Private includes ----------------------------------------------------------*/% ^/ `7 v% X3 C1 H |1 v% E
- /* USER CODE BEGIN Includes */
7 d5 `! L V6 G) \8 z& ^) y$ G - #include "stdio.h"3 a- e% i6 d& K" ]' F% f, @% O2 \
- /* USER CODE END Includes *// k9 [ Y5 I; ]" g
- ; x( g5 |8 B1 @( F$ }; ]2 |$ u
- /* Private typedef -----------------------------------------------------------*/
4 k/ b9 x- x2 L: u( L: \6 w7 y - /* USER CODE BEGIN PTD */" L% n5 Q$ o- I3 P2 L
3 @/ D& Z* \$ H# Y- /* USER CODE END PTD */
" d; a8 n6 l; l/ d g - / g! t: W1 J! `
- /* Private define ------------------------------------------------------------*/
6 h$ H$ A9 p$ y9 Y0 r/ V - /* USER CODE BEGIN PD */
/ E' z3 p( ~' F0 k: t8 } - /* USER CODE END PD */4 j X' ?( \! Z! X' J
- ( F8 Y, [$ G' C2 \- }9 [
- /* Private macro -------------------------------------------------------------*/( [* p% X# P( J6 I! Q
- /* USER CODE BEGIN PM *// v8 y( k, P( h5 F- c
l [9 y$ Q3 z% S: g- /* USER CODE END PM */
: }$ y! `3 I2 F! n
7 j8 P/ z8 q: k; p# s7 s/ Y9 `- /* Private variables ---------------------------------------------------------*/3 k# m& q S8 {3 x! X _
- ADC_HandleTypeDef hadc1;
1 L5 O! B* E$ ]( h, y% e! ?7 | - DMA_HandleTypeDef hdma_adc1;0 h) j+ w8 O2 V' B; I
- % _0 @ B& C0 ], {, g; W
- UART_HandleTypeDef huart1;
5 A3 j% k! s9 z: r - ) E6 P7 Y+ `( Z, ?
- /* USER CODE BEGIN PV */6 x; I2 P. q. W7 x0 P( S$ t
) D( U1 ~8 g/ f5 `4 Z$ S' C6 D0 R- /* USER CODE END PV */
6 i& g( d! M) u0 V- `4 [; L - ( l4 I7 ~+ ~" V; r9 U( A
- /* Private function prototypes -----------------------------------------------*/' L8 I: [4 J5 a# _( n& A
- void SystemClock_Config(void);- j+ I) B0 D, B9 o5 P( g5 R
- static void MX_GPIO_Init(void);
1 v4 @& t* W% Z3 _& \ - static void MX_DMA_Init(void);
6 r0 G4 J6 k% {7 A O4 Y2 f& e2 M - static void MX_ADC1_Init(void);! ]! v; F* |# R* P& c; k- i
- static void MX_USART1_UART_Init(void);
/ `9 [( A9 D* P7 r1 m5 o5 B - /* USER CODE BEGIN PFP */
0 w$ i% ?5 j4 s u
G4 o* Q; c- |- /* USER CODE END PFP */% Q* @) {2 x+ e* C+ l! R* I- J M5 ^
- ) Y9 |9 p" X4 C+ a& W |/ _3 V
- /* Private user code ---------------------------------------------------------*/
$ s! o/ I7 q8 B - /* USER CODE BEGIN 0 */8 k+ C+ Y4 G. l6 E9 m# a, g* w! ` q
- __IO uint16_t adcCovValueBuff[30][2] = {0}; //存放ADC的值 2通道 每个通道存放30个值,由DMA循环写入
1 e+ P7 j, c, T' u3 r8 S6 Z - uint16_t adcAverageBuff[2] = {0}; //对每个通道30个ADC值取平均值
- w0 f% o! N* m3 Y+ h A
# ~6 E4 E- ~4 w; V7 p* {6 x
% j, a( ^& ~4 R0 s! w- #ifdef __GNUC_8 a& I, Y/ [) p4 ]$ N, c% `
- #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
6 D" H: y% R+ s0 i - #else
A$ T# |2 D7 a' F9 X! b" D - #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
6 x- o6 D& Q4 _' V% c! P8 ~# W - #endif& H, ~0 ? U- g
- PUTCHAR_PROTOTYPE
) \8 M% \( o9 L% e' K: [ - {
2 H' S/ {8 M! t; O0 ]6 {9 Q - HAL_UART_Transmit(&huart1, (uint8_t*)&ch, 1, 0xFFFF);
. D% B4 n& ?- U3 C. d$ u' ~4 J - - @9 y5 u# R; y4 F6 G+ Q7 `! p9 G
- return ch;
1 A p4 F/ {. @, Q( N7 ] - }- V7 ~9 N# A8 b; r. Y0 T5 j6 O
- 6 M" }7 [+ T& l: [0 j
- /* USER CODE END 0 */
复制代码 4 k- n# F1 _4 L& O
9 M. ?; i- T/ P$ X5 G1 \- w1 E2.2 main 函数
) E& E9 @2 Y5 N5 _8 P- /*** ~: t8 ?. r) @2 W+ p# P# J+ `
- * @brief The application entry point.8 q7 }8 z6 W' v8 g0 [( K( g7 ] I
- * @retval int
2 [+ t: q$ M1 |' X8 ~. P! u - */
# R5 E( \, }( W, @ - int main(void)% [5 p# n9 Z! l9 j. _9 O9 ~: V m
- {
' j# E* j7 P0 O* d - /* USER CODE BEGIN 1 */9 E; b5 M/ F8 ?) j" q, G
- float votage = 0;
r8 ] x6 e* \3 J* s3 U } - uint32_t sum = 0;% |8 ^, ?: z' w
- /* USER CODE END 1 */. X' {4 p; [( s9 J% z! K, ?) q
- * }# a, _+ D: H) H3 ?
- /* MCU Configuration--------------------------------------------------------*/: n# ]- [5 M& t
- : Z4 f( y' a; O' r' \3 M3 W
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */( K6 l5 \5 v/ N, L
- HAL_Init();
m1 b3 c) U. r - # v- f, q4 G/ @
- /* USER CODE BEGIN Init */% i. t# d& t8 W: |- w1 H v
- 7 K0 I2 t. u) |5 V+ R, S( q
- /* USER CODE END Init */
# p% b8 M6 h/ S c5 { - 2 S8 j1 _) {9 D1 f/ s
- /* Configure the system clock */
: r9 x- g0 Q8 B! h+ k+ v5 { - SystemClock_Config();
T: c4 I8 j8 R4 Q* L* U - $ @( E6 N2 o' Y m
- /* USER CODE BEGIN SysInit */% n5 d7 V$ e3 j* I% I1 Z6 k
- 7 ]$ j' X, z& t# [9 E
- /* USER CODE END SysInit */
1 K, _* O* W8 Y o - 4 e! S) S i$ u) F
- /* Initialize all configured peripherals */
: i5 f. Q. _3 F/ r. L - MX_GPIO_Init();
! h+ Q$ L( L% h* b% E" h% g - MX_DMA_Init();
3 w' d. k6 a; ~' z) V8 J - MX_ADC1_Init();
0 p c2 P' j. A0 G - MX_USART1_UART_Init();6 R8 V8 W8 P% l8 l
- /* USER CODE BEGIN 2 */4 Q) @5 q3 g [ S4 ?/ Z( [
- printf("stm32g030f6 adc demo...... \n");5 t0 \& P; k4 U; d! H% A! j+ ~
- HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adcCovValueBuff, 60); M" E: v0 d! q. r5 P6 y. ~" t
- /* USER CODE END 2 */; e4 g+ c- A% Y# @5 i9 w0 N0 I
- 1 }1 t3 O( C" {8 ~* p
- /* Infinite loop */
`- D6 S! O1 H* k& g6 { T - /* USER CODE BEGIN WHILE */
1 z6 A7 R. m3 X6 O9 T- ?0 j+ K - while(1)
1 ^! _- q* ], i: E - {% D7 V( V% ~! H
- for(uint8_t i = 0; i < 2; i++)0 k6 @ ]" S0 E' e( N
- {
( T$ z) G/ u1 y) j - for(uint8_t count = 0; count < 30; count++)& q$ T0 X2 ?/ C: e1 W+ Q
- {& n2 [! E Z/ u8 A& o# Y
- sum += adcCovValueBuff[count];$ m4 p' z8 T3 K5 ~1 t4 d. [
- }
; }8 ^" O( w* _. [ - adcAverageBuff = sum / 30;
1 P" K( g3 R; \; W - sum = 0;
, Y# H% g) q" R5 A( u) {+ u - }
6 k! k; U3 k/ R0 H# |7 n
2 G; C3 B. X r$ l/ l: g- printf("---------------------------------------- \n");
" M5 y6 W4 v" ]; B) L* M7 K9 I - printf("ADC Channel01 Value:0x%04X \n", adcAverageBuff[0]);
) c: X$ Z2 I' E' W3 k2 K4 J4 V - votage = (float) adcAverageBuff[0] / 4096 * (float)3.3;" z9 I) q; F. y; m
- printf("ADC Channel01 Voltage:%f V \n", votage);# a( Q H) u. O9 K
- printf("ADC Channel02 Value:0x%04X \n", adcAverageBuff[1]);3 @+ j- `; Q l; R. K! `/ ^
- votage = (float) adcAverageBuff[1] / 4096 * (float)3.3;) g) X* g9 _( g/ A! Y- A
- printf("ADC Channel02 Voltage:%f V \n", votage);
( Q T2 I, {+ e# X" B* h - printf("---------------------------------------- \n");
* q3 t& @" ~" q) V7 l) l - HAL_Delay(1000);" v$ M( g' A: ?/ V" |# Y# D7 ~
- /* USER CODE END WHILE */
( |3 D9 T3 C" S! d0 z2 E - + Z1 z9 C6 Z h. G0 @
- /* USER CODE BEGIN 3 */
( l3 z, k) y$ ^$ K( H - }0 ?3 t" ~7 X7 s, S2 T/ K
- /* USER CODE END 3 */
: F" a3 j2 B% n7 c8 h - }
复制代码
4 Y( K* P+ F* d- b' K2.3 外设的初始化函数; l; R! E% H3 Z0 I
外设的初始化函数都是由 CubeMx 生成的,因为我们只用 DMA 搬运数据,未使用 DMA 的中断功能,故初始化 DMA 时可将中断配置函数注释。
( T1 y' @4 f; J3 n1 N: o: N4 [
F# E0 s9 _* a/ |* {# K5 k9 u- /**( r, H& J3 i: e" D/ d3 q/ {: p
- * @brief ADC1 Initialization Function& k: E- y3 S1 U: w' R
- * @param None2 R& E* D& h! q! L& Y6 O
- * @retval None3 j& L& i! \6 _1 [+ Z( N% u
- */
$ T9 a8 Y9 o7 \ - static void MX_ADC1_Init(void)' a" f) \% D6 Q1 s' }/ p
- {# q8 J9 n4 V- U$ d" |0 w/ }/ l/ u
- ' _ i' D! V6 Y% i6 W
- /* USER CODE BEGIN ADC1_Init 0 */2 A* a2 E: q: I& g! }. B+ U
- ! ^0 o' ]" K* }9 e, ?
- /* USER CODE END ADC1_Init 0 */0 i6 q+ j. d. S
$ u3 J+ v: y. l: S$ n+ Q- ADC_ChannelConfTypeDef sConfig = {0};
0 S" |# i& p1 \# g8 @+ r, g5 D/ q. w - " w! W1 h# ^) ?3 t) A# S- a# ~
- /* USER CODE BEGIN ADC1_Init 1 */
# O/ G+ B, D( n# t - ) D# i2 l. \4 m2 z: c# ~' o% _* n
- /* USER CODE END ADC1_Init 1 */. ]1 X8 a4 i! H2 n
- /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
, L. H4 R( U/ s& y - */' @# I, J. l) ` ]# x; B
- hadc1.Instance = ADC1;3 N5 D" @ s9 R1 Y/ {
- hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
3 l0 R+ D. q5 [6 \ ~9 ^ - hadc1.Init.Resolution = ADC_RESOLUTION_12B;
% {/ m% }: ~/ i% l* ~, k9 T Z - hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;7 f8 H8 G( M) M' z
- hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;- [6 _$ \6 O+ l! y: F. u5 W6 l! S
- hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
! }0 a ?- w( }8 ^9 E) n* D! \2 } - hadc1.Init.LowPowerAutoWait = DISABLE;. ^& C$ p# ^ x7 j
- hadc1.Init.LowPowerAutoPowerOff = DISABLE; V8 U' {; @3 i
- hadc1.Init.ContinuousConvMode = ENABLE;
|( V1 W. A- J! |- M$ G; T - hadc1.Init.NbrOfConversion = 2;! l' e+ g9 W+ M8 P1 S
- hadc1.Init.DiscontinuousConvMode = DISABLE;2 P4 n& ^% k- {- l
- hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;* ~3 R, f1 ]+ U3 g0 }
- hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
! O+ B, ~; t. h1 G7 } - hadc1.Init.DMAContinuousRequests = ENABLE;
% ]) {4 o5 E, }, I7 I' G3 ] - hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
0 z' O) M$ s7 s - hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_12CYCLES_5;
3 P5 P* _+ X+ r( ` - hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_12CYCLES_5;4 d2 U* q# y( m# [: k) E( |
- hadc1.Init.OversamplingMode = DISABLE;
+ P4 W; Q2 k- e8 K& v9 S. y/ V4 ] - hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
5 k/ c- l, |& Y - if(HAL_ADC_Init(&hadc1) != HAL_OK)( _/ V/ C( j3 K6 L5 ]
- {8 A) I0 S8 P/ W- t; X* M0 u- f. B7 I" h
- Error_Handler();+ d/ I( H" ?, y# {
- }
2 F& q1 X% G' q/ j3 D - /** Configure Regular Channel- _7 k$ N$ E5 R5 z6 U/ z
- */* R/ d W) H( ^0 n+ j7 m
- sConfig.Channel = ADC_CHANNEL_7;
. f) E+ `+ Z) R - sConfig.Rank = ADC_REGULAR_RANK_1;+ l/ }7 c1 z3 n; w \0 [; T
- sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;9 |* {+ C9 [+ E( b3 G2 r( L. q) Y
- if(HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)& A! E+ ?: F1 H/ {! u) ^9 z! v
- {. [2 Y0 x8 D$ U
- Error_Handler();* d4 I* o! A3 o& M8 o
- }- G4 c. N+ m" ]3 @7 G
- /** Configure Regular Channel
9 l) _2 i6 n5 [) ]2 t0 p - */. M4 X" n0 l) w3 Q4 u
- sConfig.Channel = ADC_CHANNEL_8;! A Z0 l* h- @7 |' u: f
- sConfig.Rank = ADC_REGULAR_RANK_2;* u* v' n" h+ h G; ]
- sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_2;: A$ x+ D* S4 y8 N% `) d" ~4 S
- if(HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
& Y: q8 {2 c7 \; b - {7 E2 P1 ]$ f& U& P+ N% v& w4 N
- Error_Handler(); z0 } w5 |3 S" b; ^
- }
8 x8 Z; i. u; t% U( B# n - /* USER CODE BEGIN ADC1_Init 2 */! i' r/ H+ @4 ~% m
3 X# L, g1 l8 Q! I u6 k- /* USER CODE END ADC1_Init 2 */' d! P9 c/ Y$ G0 A
- " D0 i- B: k) F1 _2 g+ g
- }8 w! W0 D7 O( n4 {" |, v
- ' V' f9 Y& a2 g4 I* ~3 l
- /**
6 v# @3 |- z. g; L) k9 Q( s - * @brief USART1 Initialization Function
, Y+ U- }+ Q) A* @2 P& g - * @param None, Q, s/ `* O4 n0 j" V
- * @retval None
/ B5 z; ]4 w. {" Q w - */
/ G t% X$ I7 P - static void MX_USART1_UART_Init(void)$ B) y) {5 ~$ q) [8 m7 N3 A
- {
- {9 G' \2 `! r: v5 i. O3 r - 9 N6 N( r- |& F( R, S
- /* USER CODE BEGIN USART1_Init 0 */6 t+ f# E7 X1 c( s0 k" p
: ^+ ~6 o# c @1 L# Q% ^- /* USER CODE END USART1_Init 0 */$ m7 K% \3 i; P: ]- t
% O9 r( e8 f. N0 P- /* USER CODE BEGIN USART1_Init 1 */
% Y; C+ L; ]+ n& r% \ - 4 @$ Y) D- ^1 X: `5 {; R7 Y
- /* USER CODE END USART1_Init 1 */% U" r# B9 R( W7 ~) U2 Z! f4 F: K
- huart1.Instance = USART1;' B' l5 B; {: U# f) H& p, ~
- huart1.Init.BaudRate = 115200;: P; O1 m4 K5 I1 _9 j; L0 n/ Y' W
- huart1.Init.WordLength = UART_WORDLENGTH_8B;4 U6 V9 _5 ?/ ~- e1 R
- huart1.Init.StopBits = UART_STOPBITS_1;
% S, W( A& m/ k- p: z8 L% B - huart1.Init.Parity = UART_PARITY_NONE;1 q/ I, C+ k# G6 n/ o) r1 w9 D2 q; g
- huart1.Init.Mode = UART_MODE_TX_RX;
% Z* b+ C" Z5 f - huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
* {: e% Z* A2 B! U$ y: f - huart1.Init.OverSampling = UART_OVERSAMPLING_16;2 J7 Z+ G) E1 N/ E
- huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;! o0 O, l: Z, f. c3 {+ `# B
- huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1; H& q3 _$ E# @, U5 Y6 ~: ?
- huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
# s' b5 l7 w4 d4 `" Z- f c$ } - if(HAL_UART_Init(&huart1) != HAL_OK)
C0 L, w* [) x* y& U - {' `! q- O3 L' n2 X9 k& y
- Error_Handler();
4 V/ Y8 h& }" q' u. D$ _+ e9 z. r - }1 u; G* @1 Z7 p* E: n9 N
- if(HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)9 e: M; ~8 U$ g: h3 W* }$ y" C
- { j V/ {9 i) O& n) Z
- Error_Handler();
H, y/ g/ l! M3 Q5 k - }
" W3 D8 |3 U1 s. N - if(HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)0 R8 B; @; h+ J3 b% o# g n4 k
- {2 f' p5 K1 [3 \9 _( Y+ j$ s2 Y
- Error_Handler();
5 ?; ]+ H( n: u - }
5 |; y* ]: E) F+ E - if(HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)* _, U5 s2 K2 G/ I F, P/ k7 J
- {# i; R" p) z; o. ~$ O# E+ W" a
- Error_Handler();
- F" l- x# }' u* q0 e5 @ - }% A# i/ f: C- n6 n% u+ v# l1 Q
- /* USER CODE BEGIN USART1_Init 2 */8 @1 v S" r( [5 I1 r
0 ]) \% i4 E3 r8 s- /* USER CODE END USART1_Init 2 */
( Z, y/ Y. Q$ o1 I
# J* w2 e! u0 p, V- }; V# K! ?1 ~7 P
% v% E# P& e* J& i/ L- /*** d$ o) x5 @$ ~5 @, }/ \
- * Enable DMA controller clock; m( E3 c# D0 V' _# A- U( \
- */
6 E+ j0 P, M" A- t+ |7 i% k - static void MX_DMA_Init(void) B7 e( ?' ?$ f- C `9 h& O
- {
3 T- [1 I& K4 J4 L$ G - ' _+ {# j: [ t9 m
- /* DMA controller clock enable */( `! C9 p2 G# ^' c8 K" {
- __HAL_RCC_DMA1_CLK_ENABLE();5 T# t3 u# V( ]# f
3 x4 {) Z3 v, W. g9 m( D- /* DMA interrupt init */
5 c& y) Z% |( ? - /* DMA1_Channel1_IRQn interrupt configuration */$ }; v4 S$ O" A1 M# {" ~$ W! J
" |$ J) s U8 N" u! u/ m J- C/ L* h- //HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); //未使用中断功能,故注释 - b5 n% N9 P' x6 g+ w8 f* y
- //HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);( B% n" K/ l+ q8 j+ w
o3 s- p. S% p1 Z' M- }+ f+ y: z, H4 E- U' W. W- w0 S8 c
' M- J! z% s& A, u5 {- /**7 z9 e3 `$ [7 J {+ w, v- o
- * @brief GPIO Initialization Function+ C! I; v$ |! [+ O9 @
- * @param None
/ I5 [3 S7 ^& |$ k( a - * @retval None3 y: C& d% S0 w( z% w Y
- */5 a8 j+ S- C' e. Q& Y, A; w3 F
- static void MX_GPIO_Init(void), M' }3 B7 c, l% e3 w
- {
* Z$ c1 Y2 x q& Q, l8 }# c& a
5 N, n+ q! M$ x9 G! C9 y ^3 T- /* GPIO Ports Clock Enable */* |2 t' h" ?5 ]2 w9 j
- __HAL_RCC_GPIOB_CLK_ENABLE();
+ f' m" D1 B* P/ \% n! w - __HAL_RCC_GPIOA_CLK_ENABLE();2 Y. h5 a8 s7 v; w
. H, U @6 G6 }- }
复制代码 h$ V8 ?0 K) D$ A5 d+ ]9 `
# t+ u p3 \4 x( ^( K( W4 _ h3. 实验现象
3 J2 f, Q- S0 v: I: Q( `编译并将程序下载到开发板中,连接串口助手并打开;
7 V% U7 I6 k1 j实验现象:每秒打印一次当前两个通道的 ADC 值及换算后的电压.
" _1 _/ O8 V( e, B* P
" w# ]9 y' K& A: A( q$ s
- v9 |! h/ K" K/ z- D7 b( I( S, b; l3 t; p Y! @ U. h
|