你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【经验分享】STM32 DAC相关函数和类型

[复制链接]
STMCU小助手 发布时间:2022-6-16 17:00
01. DAC简介
6 G7 b* \3 N0 `" LSTM32F4的DAC模块(数字/模拟转换模块)是12位数字输入,电压输出型的DAC。DAC可以配置为 8 位或 12 位模式,也可以与 DMA 控制器配合使用。DAC 工作在 12 位模式时,数据可以设置成左对齐或右对齐。DAC 模块有 2 个输出通道,每个通道都有单独的转换器。在双 DAC 模式下,2 个通道可以独立地进行转换,也可以同时进行转换并同步地更新 2 个通道的输出。DAC 可以通过引脚输入参考电压 Vref+(通 ADC 共用)以获得更精确的转换结果。
; B; K0 @" R0 RSTM32F4 的 DAC 模块主要特点有:
& a9 R1 j$ A' j. Y$ b- w① 2 个 DAC 转换器:每个转换器对应 1 个输出通道7 ?' c; l& ]" |, x  J# K% }- I* S
② 8 位或者 12 位单调输出! P2 _+ g' R! u% d; k
③ 12 位模式下数据左对齐或者右对齐7 e( t# ~/ _, I4 d0 K$ p+ u
④ 同步更新功能/ ?, A0 [3 i( ]  G; l1 ^5 \( i
⑤ 噪声波形生成0 \; T& f" `3 E; m" L7 \$ E
⑥ 三角波形生成
5 S5 j3 i8 L4 s+ i  M4 z8 O# K1 T⑦ 双 DAC 通道同时或者分别转换* `/ }( J3 s9 M' _; c2 H) I
⑧ 每个通道都有 DMA 功能" I* X# v8 I+ r% m! D  @; g
/ R  K3 S) c4 I- R# D5 K3 y4 k
02. 相关类型3 x& p- Z: O, w: t( P4 R  w. _
DAC Init structure0 K* a) p5 Y" c& t1 Z8 S) e

; P2 E( _/ i0 U3 j* `8 Q
  1. /**
    6 A* D/ D! }; H* _
  2.   * @brief  DAC Init structure definition4 e7 \, v. k- p7 b: V
  3.   */
    5 H2 m' \8 g7 ~

  4. $ L( `# R: Q- f# g9 t
  5. typedef struct, w) v/ ]2 D5 L) {/ Q
  6. {
    4 F3 @! `& j% ]" M! e
  7.   uint32_t DAC_Trigger;                      /*!< Specifies the external trigger for the selected DAC channel.
    * W; {3 {/ T9 x) R) P
  8.                                                   This parameter can be a value of @ref DAC_trigger_selection */. C0 J, o+ t! \( ?
  9. 8 Z; {& N6 c# x2 h: j: g
  10.   uint32_t DAC_WaveGeneration;               /*!< Specifies whether DAC channel noise waves or triangle waves( b% x, O' k4 r% S" m' e3 r
  11.                                                   are generated, or whether no wave is generated.
    # s3 B6 {! W; A
  12.                                                   This parameter can be a value of @ref DAC_wave_generation */
    : c/ X) C8 l8 W0 ^( R7 z
  13. 7 L5 d1 v7 \# @7 R
  14.   uint32_t DAC_LFSRUnmask_TriangleAmplitude; /*!< Specifies the LFSR mask for noise wave generation or7 J, |0 }5 P2 \1 Q9 L2 P# v9 b
  15.                                                   the maximum amplitude triangle generation for the DAC channel.
    9 H. Z+ X% N* C$ f1 o* I5 h: L! e
  16.                                                   This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */; l2 ?& X6 m6 N0 Y; R

  17. 1 B( h( g; i; Z, @5 U5 I
  18.   uint32_t DAC_OutputBuffer;                 /*!< Specifies whether the DAC channel output buffer is enabled or disabled.. o5 ~5 D1 Y' f: c5 s6 C4 _& w
  19.                                                   This parameter can be a value of @ref DAC_output_buffer */; `- q( r; T- V  J9 X8 m
  20. }DAC_InitTypeDef;
复制代码
. F4 Y9 @" |: e
DAC_trigger_selection
5 `; U: |2 Q2 k. d( y: G$ q3 ?2 W/ `: J* T- \8 i
  1. /** @defgroup DAC_trigger_selection   Z4 w3 [; v& R* M& M! b
  2.   * @{& P- L5 x! \/ c% Q. n" z# `* W
  3.   */9 _* x8 q% Z6 O, x3 b) k& l

  4. # M/ o4 T) e( B
  5. #define DAC_Trigger_None                   ((uint32_t)0x00000000) /*!< Conversion is automatic once the DAC1_DHRxxxx register
    " e4 C) g. I5 T6 O3 S" h
  6.                                                                        has been loaded, and not by external trigger */- C8 V1 M" v; K5 l
  7. #define DAC_Trigger_T2_TRGO                ((uint32_t)0x00000024) /*!< TIM2 TRGO selected as external conversion trigger for DAC channel */
    6 e, a2 G0 b2 e: D/ m6 a
  8. #define DAC_Trigger_T4_TRGO                ((uint32_t)0x0000002C) /*!< TIM4 TRGO selected as external conversion trigger for DAC channel */' J( y: m( H: Y& m$ h5 o$ V# C, k
  9. #define DAC_Trigger_T5_TRGO                ((uint32_t)0x0000001C) /*!< TIM5 TRGO selected as external conversion trigger for DAC channel */* u0 C% y0 W7 F
  10. #define DAC_Trigger_T6_TRGO                ((uint32_t)0x00000004) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */
    3 k7 L. [  C" m1 U- u6 {% [- `/ F1 m5 {
  11. #define DAC_Trigger_T7_TRGO                ((uint32_t)0x00000014) /*!< TIM7 TRGO selected as external conversion trigger for DAC channel */
      \3 u9 n" T! R
  12. #define DAC_Trigger_T8_TRGO                ((uint32_t)0x0000000C) /*!< TIM8 TRGO selected as external conversion trigger for DAC channel */                                                                       9 R! k5 q) G* V
  13. * c4 G8 E* M% U; R, {
  14. #define DAC_Trigger_Ext_IT9                ((uint32_t)0x00000034) /*!< EXTI Line9 event selected as external conversion trigger for DAC channel */, y) a. t! y3 c( ?6 f
  15. #define DAC_Trigger_Software               ((uint32_t)0x0000003C) /*!< Conversion started by software trigger for DAC channel */2 W" o: Q4 F% G2 o

  16. & D$ Y, ^  q3 Q# b8 [- M! n, t
  17. #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_Trigger_None) || \& k# Y2 Q% z" [# _* r
  18.                                  ((TRIGGER) == DAC_Trigger_T6_TRGO) || \
    ' R0 `( J6 D0 b" z
  19.                                  ((TRIGGER) == DAC_Trigger_T8_TRGO) || \
    ' q- v' S$ B* Q0 q7 a
  20.                                  ((TRIGGER) == DAC_Trigger_T7_TRGO) || \: j. }1 A  H$ A- z, [
  21.                                  ((TRIGGER) == DAC_Trigger_T5_TRGO) || \
    2 P: r* G4 o( X+ p2 k
  22.                                  ((TRIGGER) == DAC_Trigger_T2_TRGO) || \, K2 ~* G  F; H0 ]- w. V
  23.                                  ((TRIGGER) == DAC_Trigger_T4_TRGO) || \2 f  {9 b" S9 F) _' Z# v% a
  24.                                  ((TRIGGER) == DAC_Trigger_Ext_IT9) || \
    , o: }  X- A1 C+ y- F* M) ?7 V; o
  25.                                  ((TRIGGER) == DAC_Trigger_Software))
复制代码

2 @" U" z$ c0 k; I3 b' a* x3 WDAC_wave_generation
+ r3 h" H2 j: ]( w% r4 v: A& h, ~& q9 w- F9 d! I
  1. /** @defgroup DAC_wave_generation
    5 T8 J( k1 E' F8 [3 l8 D
  2.   * @{
    , @7 d& x% x& R7 A$ U
  3.   */
    " Y& ?' }) ?7 a

  4. ) S" x" z5 J6 ^1 R- }. Q
  5. #define DAC_WaveGeneration_None            ((uint32_t)0x00000000)
    ' M0 T8 X0 ^" h
  6. #define DAC_WaveGeneration_Noise           ((uint32_t)0x00000040)
    8 [. N% F3 ^6 u' a
  7. #define DAC_WaveGeneration_Triangle        ((uint32_t)0x00000080)
    * ]/ R% N! ?3 w) U
  8. #define IS_DAC_GENERATE_WAVE(WAVE) (((WAVE) == DAC_WaveGeneration_None) || \& P& L3 B! H+ ?( ]
  9.                                     ((WAVE) == DAC_WaveGeneration_Noise) || \
    ) \' k  O3 e) K) n0 c* l6 x1 M! U
  10.                                     ((WAVE) == DAC_WaveGeneration_Triangle))
复制代码
/ E6 E- p6 P" ^; i( a+ |" j! h5 Z
DAC_lfsrunmask_triangleamplitude
  p' M5 u) I! t7 n# n8 D4 o2 }6 L2 T. r3 N

  1. $ C: a/ m, {: O& u8 t8 ?3 v
  2. /** @defgroup DAC_lfsrunmask_triangleamplitude/ F. A9 L% J' N- r1 I' O" n! \
  3.   * @{
    $ D0 m# `. Z) l2 O: u, |7 Q
  4.   */. ]9 D, z+ z, X' S3 f) X5 r
  5. + ~* t- H! q* \2 R
  6. #define DAC_LFSRUnmask_Bit0                ((uint32_t)0x00000000) /*!< Unmask DAC channel LFSR bit0 for noise wave generation */
    ! D; [. q& I" [1 z$ H' k- ~
  7. #define DAC_LFSRUnmask_Bits1_0             ((uint32_t)0x00000100) /*!< Unmask DAC channel LFSR bit[1:0] for noise wave generation */
    : O2 {" u3 }% }2 h  Z% q
  8. #define DAC_LFSRUnmask_Bits2_0             ((uint32_t)0x00000200) /*!< Unmask DAC channel LFSR bit[2:0] for noise wave generation */
    9 d' }) u9 l" z5 i% @' v
  9. #define DAC_LFSRUnmask_Bits3_0             ((uint32_t)0x00000300) /*!< Unmask DAC channel LFSR bit[3:0] for noise wave generation */
    7 G7 V6 f, U' n& I0 l- H( Z7 f
  10. #define DAC_LFSRUnmask_Bits4_0             ((uint32_t)0x00000400) /*!< Unmask DAC channel LFSR bit[4:0] for noise wave generation */, l" N" S# ~* Z2 `! A* Y* x6 d
  11. #define DAC_LFSRUnmask_Bits5_0             ((uint32_t)0x00000500) /*!< Unmask DAC channel LFSR bit[5:0] for noise wave generation */
    & X. q$ [& Q6 X7 C$ B/ b
  12. #define DAC_LFSRUnmask_Bits6_0             ((uint32_t)0x00000600) /*!< Unmask DAC channel LFSR bit[6:0] for noise wave generation */
    2 m- H% c! l0 E7 i: m
  13. #define DAC_LFSRUnmask_Bits7_0             ((uint32_t)0x00000700) /*!< Unmask DAC channel LFSR bit[7:0] for noise wave generation */. W3 r. a" d/ c7 l
  14. #define DAC_LFSRUnmask_Bits8_0             ((uint32_t)0x00000800) /*!< Unmask DAC channel LFSR bit[8:0] for noise wave generation */7 K; y( I) g$ r# ~! c* B
  15. #define DAC_LFSRUnmask_Bits9_0             ((uint32_t)0x00000900) /*!< Unmask DAC channel LFSR bit[9:0] for noise wave generation */8 J. o- O- E% p# A7 Y5 N
  16. #define DAC_LFSRUnmask_Bits10_0            ((uint32_t)0x00000A00) /*!< Unmask DAC channel LFSR bit[10:0] for noise wave generation */
    ; |9 u( G6 X' a1 ^( t+ v1 M3 S
  17. #define DAC_LFSRUnmask_Bits11_0            ((uint32_t)0x00000B00) /*!< Unmask DAC channel LFSR bit[11:0] for noise wave generation */
    2 v7 T% u5 S* q2 g% |% F: C
  18. #define DAC_TriangleAmplitude_1            ((uint32_t)0x00000000) /*!< Select max triangle amplitude of 1 */  D. a5 y% x! y
  19. #define DAC_TriangleAmplitude_3            ((uint32_t)0x00000100) /*!< Select max triangle amplitude of 3 */
    - E+ @) z) l" v, z$ G
  20. #define DAC_TriangleAmplitude_7            ((uint32_t)0x00000200) /*!< Select max triangle amplitude of 7 */
    * x" R8 t* {2 F# i$ @
  21. #define DAC_TriangleAmplitude_15           ((uint32_t)0x00000300) /*!< Select max triangle amplitude of 15 */8 {' j# ~: H" M% E' \. [: Y
  22. #define DAC_TriangleAmplitude_31           ((uint32_t)0x00000400) /*!< Select max triangle amplitude of 31 */
    ) R/ k1 ~/ m- d: I
  23. #define DAC_TriangleAmplitude_63           ((uint32_t)0x00000500) /*!< Select max triangle amplitude of 63 */# U6 G( m# p8 ?% V9 P/ J. f/ {
  24. #define DAC_TriangleAmplitude_127          ((uint32_t)0x00000600) /*!< Select max triangle amplitude of 127 */: T: d! x' u! J* U) N
  25. #define DAC_TriangleAmplitude_255          ((uint32_t)0x00000700) /*!< Select max triangle amplitude of 255 *// ]* T) W3 }: y) G0 _% R5 ]1 ^
  26. #define DAC_TriangleAmplitude_511          ((uint32_t)0x00000800) /*!< Select max triangle amplitude of 511 */
    - g9 u2 `4 d: F6 m: r9 D# o
  27. #define DAC_TriangleAmplitude_1023         ((uint32_t)0x00000900) /*!< Select max triangle amplitude of 1023 */3 r# t; _* t& }- b+ v
  28. #define DAC_TriangleAmplitude_2047         ((uint32_t)0x00000A00) /*!< Select max triangle amplitude of 2047 */
    * l5 L# G/ J/ q
  29. #define DAC_TriangleAmplitude_4095         ((uint32_t)0x00000B00) /*!< Select max triangle amplitude of 4095 */
    - ^" o5 }3 X+ ?$ `1 X
  30. ) H7 s9 ~1 R! ^0 \) j! V$ Z/ q
  31. #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) (((VALUE) == DAC_LFSRUnmask_Bit0) || \
    + h  h  s0 c) s  ]9 ^
  32.                                                       ((VALUE) == DAC_LFSRUnmask_Bits1_0) || \. q2 h4 ^- Q( T5 F3 ~- K/ t: v
  33.                                                       ((VALUE) == DAC_LFSRUnmask_Bits2_0) || \
    6 z, ~3 S- T+ V; e- G
  34.                                                       ((VALUE) == DAC_LFSRUnmask_Bits3_0) || \7 G1 q" Y& z6 C
  35.                                                       ((VALUE) == DAC_LFSRUnmask_Bits4_0) || \
    4 A: e) p% [3 ^
  36.                                                       ((VALUE) == DAC_LFSRUnmask_Bits5_0) || \
    6 }, X/ R; Z: G3 ]* ]5 P
  37.                                                       ((VALUE) == DAC_LFSRUnmask_Bits6_0) || \' d! E" x4 j  Q
  38.                                                       ((VALUE) == DAC_LFSRUnmask_Bits7_0) || \
    ( Q# W8 W! P5 y4 D8 U
  39.                                                       ((VALUE) == DAC_LFSRUnmask_Bits8_0) || \; Z' \  Q. s* K- R7 \$ H) X
  40.                                                       ((VALUE) == DAC_LFSRUnmask_Bits9_0) || \
    % ]8 J/ E) |* W
  41.                                                       ((VALUE) == DAC_LFSRUnmask_Bits10_0) || \
    + I! [' g1 O  Z6 _) g! T% ?6 @& T
  42.                                                       ((VALUE) == DAC_LFSRUnmask_Bits11_0) || \' D5 O. ]3 {1 a4 e
  43.                                                       ((VALUE) == DAC_TriangleAmplitude_1) || \- P7 r( S& q- E4 G' u) ~$ A' t# X
  44.                                                       ((VALUE) == DAC_TriangleAmplitude_3) || \% F. X) J8 k. S9 ~) o
  45.                                                       ((VALUE) == DAC_TriangleAmplitude_7) || \
    4 i3 Q0 s1 z4 V* ^7 d6 t
  46.                                                       ((VALUE) == DAC_TriangleAmplitude_15) || \
    ( t2 e' ?& k. Z# m
  47.                                                       ((VALUE) == DAC_TriangleAmplitude_31) || \
    , h. O- i+ f* V! ]
  48.                                                       ((VALUE) == DAC_TriangleAmplitude_63) || \. d5 [3 s, V" @! p* ?
  49.                                                       ((VALUE) == DAC_TriangleAmplitude_127) || \
    3 p- \1 v6 ?  J* L7 q3 P
  50.                                                       ((VALUE) == DAC_TriangleAmplitude_255) || \
    : H9 V1 t& b% E- ~* c8 G/ t5 T
  51.                                                       ((VALUE) == DAC_TriangleAmplitude_511) || \: K4 U( t9 c; `& o: k
  52.                                                       ((VALUE) == DAC_TriangleAmplitude_1023) || \
    . Q( ^4 Z: l( }
  53.                                                       ((VALUE) == DAC_TriangleAmplitude_2047) || \7 l" u, {# w& P
  54.                                                       ((VALUE) == DAC_TriangleAmplitude_4095))
复制代码
7 l9 j1 _$ R( X. }6 e
DAC_output_buffer
, x: B! |- Z) O1 d! `/ o. u; T2 V5 Q3 h& {& O0 q
  1. /** @defgroup DAC_output_buffer & D4 V5 o8 ^  @2 u+ T/ b, }
  2.   * @{5 i: P% P, U& w# k+ K
  3.   */
    * H* l) C  q& a* o
  4. " L3 t- a1 P, U# [. l+ q- N
  5. #define DAC_OutputBuffer_Enable            ((uint32_t)0x00000000)
    6 t$ K) j3 A4 [- g+ S' ]: G
  6. #define DAC_OutputBuffer_Disable           ((uint32_t)0x00000002)
    ' T, L. y! b- W5 T6 Q8 ^
  7. #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OutputBuffer_Enable) || \
    : Y0 k: o% _1 [
  8.                                            ((STATE) == DAC_OutputBuffer_Disable))
复制代码
9 a- x( M7 q, _% d
DAC_Channel_selection
- o5 A( J6 f+ c7 T8 P
% J6 Q. ^) z* A9 O
  1. /** @defgroup DAC_Channel_selection $ S4 |  U: t' l; w4 h8 O* ?8 w0 U
  2.   * @{7 }& i# F. [8 ?( [5 W
  3.   */. L: f. S. ]. ?% j* o# {( l

  4. % j. o/ }) y9 x0 A( e' ^, N0 A7 m
  5. #define DAC_Channel_1                      ((uint32_t)0x00000000)
      [! N4 }1 |( y* q0 j( J
  6. #define DAC_Channel_2                      ((uint32_t)0x00000010)4 V: X$ H2 c$ J
  7. #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_Channel_1) || \
    - q$ }9 \3 T. s
  8.                                  ((CHANNEL) == DAC_Channel_2))
复制代码
+ X. t. z8 z& @5 s
DAC_data_alignement
' y9 P( H+ ^$ d5 _% P2 ~1 P; U7 ]
' t+ h) |2 F6 M+ l+ `8 U* X7 [5 a
  1. /** @defgroup DAC_data_alignement 9 W' ]% A; S# n$ y! ^0 z+ L
  2.   * @{9 i8 `: q/ n8 V
  3.   */
    ' K" r* c3 i, y' g6 H5 a1 T) O# Z

  4. % |! \6 q3 U" N  ?8 R
  5. #define DAC_Align_12b_R                    ((uint32_t)0x00000000)! k- Y% X& G* o: {8 t2 H- E
  6. #define DAC_Align_12b_L                    ((uint32_t)0x00000004)
    * G" ~; k3 y! D
  7. #define DAC_Align_8b_R                     ((uint32_t)0x00000008)! U, \7 [: E( @( Q" B
  8. #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_Align_12b_R) || \" M1 k' R2 P5 q) N4 y; A6 T
  9.                              ((ALIGN) == DAC_Align_12b_L) || \
    ! `) N& G- ?  K7 s. ^, C9 q4 W
  10.                              ((ALIGN) == DAC_Align_8b_R))
复制代码
( c. _/ O6 M- d+ ]2 k5 e6 Q" w1 @
DAC_wave_generation: @2 c5 ?8 k1 p' g( ~2 E

, ^, N- T1 m' n
  1. /** @defgroup DAC_wave_generation   N/ }3 l# z5 ]  ]# U
  2.   * @{
      Q% w' ^, @1 _( j
  3.   */
    . Y. V4 l- d5 g2 ^4 V
  4. 8 }1 E. R8 P' Q
  5. #define DAC_Wave_Noise                     ((uint32_t)0x00000040)$ v# s" K3 S, Z, @" e7 T  B# o
  6. #define DAC_Wave_Triangle                  ((uint32_t)0x00000080)
    0 j8 q- e. L6 H8 J
  7. #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_Wave_Noise) || \
    " M  y2 w  _# w  j, z
  8.                            ((WAVE) == DAC_Wave_Triangle))
复制代码
' P/ |2 k) ], l
其它
% `' V  U4 h' ?% A7 W
" h7 M$ ?0 P' a, g8 [% Z7 w. ~) U, B
  1. /** @defgroup DAC_data
    2 X: l4 c# `) h* h
  2.   * @{
    ) Y- q, n" d- j+ g4 }2 M8 M
  3.   */
    ' M$ ]' D% [/ Y$ g( @8 u2 M% s5 @
  4. * _9 }% R6 _$ E( w
  5. #define IS_DAC_DATA(DATA) ((DATA) <= 0xFFF0) / j' e! s% g  i$ Q
  6. /**
    0 F( A" @- ^4 K2 z( C
  7.   * @}6 Y7 w' }. c* I2 c
  8.   */7 t* \, s. I' T, e
  9. & \# H7 _. `& k# e0 n( t
  10. /** @defgroup DAC_interrupts_definition
    ! [' _* u1 J- B2 M$ c. T1 \7 ]
  11.   * @{% c. `2 q' O$ o5 y0 l5 ]: G
  12.   */   % M0 J) {" s' [
  13. #define DAC_IT_DMAUDR                      ((uint32_t)0x00002000)  
    2 J/ o8 E. b* ^+ k( t6 g& n
  14. #define IS_DAC_IT(IT) (((IT) == DAC_IT_DMAUDR)) 2 h& ~7 U+ F* P5 S' y' ^9 y

  15. ( ^* q( U  Y) |9 G
  16. /**; Q/ ]/ U2 G+ `! b* R( r; w8 V
  17.   * @}' Z7 |; D: p" |$ T4 e& ~9 Q$ V9 S5 k
  18.   */ 7 F4 x7 \: h' l5 t- i

  19. 1 `5 H4 o% J- c2 ^
  20. /** @defgroup DAC_flags_definition
    * |: }( |9 E& Z% p9 r
  21.   * @{1 j' Z/ e' ~( }2 Z: A
  22.   */
    6 k% d6 }# \$ B

  23. 6 F. N; d7 `% x' C
  24. #define DAC_FLAG_DMAUDR                    ((uint32_t)0x00002000)  ) Z( M4 g: o+ S9 o' T7 L# t
  25. #define IS_DAC_FLAG(FLAG) (((FLAG) == DAC_FLAG_DMAUDR))  
复制代码

+ z0 y& F0 [) E! w2 G03. 相关函数
* {9 m% J9 x( h& @7 W
  1. /*  Function used to set the DAC configuration to the default reset state *****/  " [1 |* W0 M; ]: {; y, O
  2. void DAC_DeInit(void);2 F! t& ^/ {, m' n

  3. ! W6 ]; m4 d+ C3 _: @5 m* [4 r
  4. /*  DAC channels configuration: trigger, output buffer, data format functions */3 q  q, b/ K- u  |* ]6 Y& i+ z: r7 u
  5. void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);
    + s$ q+ N' b& c: b) V. h
  6. void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct);- N" D0 K6 S0 B3 I5 x3 ?
  7. void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState);5 ]" r( f" [2 l
  8. void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState);
    . \  A& U3 f: Z! A
  9. void DAC_DualSoftwareTriggerCmd(FunctionalState NewState);4 D( J0 B6 U# k
  10. void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState);
    3 [4 Z- e4 a0 V! T6 }9 M  @
  11. void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data);) Y9 x3 N7 `6 [1 k+ R# b# z
  12. void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data);
    " a/ l$ U4 Q- z4 }% g
  13. void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);
    ) F8 B. y$ u4 p1 x
  14. uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel);! W. y$ I" s3 t2 M9 I/ B! j

  15. " }" A( J) u/ x5 z* h( s
  16. /* DMA management functions ***************************************************/
    + w+ o7 M$ z7 r
  17. void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState);
    4 h2 C7 w) `4 |0 O
  18. ! o% d& Q* E4 H
  19. /* Interrupts and flags management functions **********************************/
    : \) ]3 P7 K  C
  20. void DAC_ITConfig(uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState);; R( C. p" N: G! Z5 \( m
  21. FlagStatus DAC_GetFlagStatus(uint32_t DAC_Channel, uint32_t DAC_FLAG);
    - B, O& W0 d5 a0 [; O6 Y; T" E
  22. void DAC_ClearFlag(uint32_t DAC_Channel, uint32_t DAC_FLAG);
    6 `) {: a* v; T7 l8 E, V; k
  23. ITStatus DAC_GetITStatus(uint32_t DAC_Channel, uint32_t DAC_IT);
    ( ~( D  _2 s# v* I# t# C5 T! E
  24. void DAC_ClearITPendingBit(uint32_t DAC_Channel, uint32_t DAC_IT);
复制代码

; z7 H( C! w# X. L04. 结构体封装
/ L" H, N0 V  n5 Q3 A
  1. /**
    & h3 e  M& Y1 ~
  2.   * @brief Digital to Analog Converter
    ) ]1 m. ?: j3 d2 _* P
  3.   */
    " N6 a% y0 v" ^+ p1 r( w: {

  4. , `/ a9 P2 D( D6 S! ^
  5. typedef struct1 }; @0 k* S; f9 I' v+ l2 F4 e& S9 W
  6. {3 o% J0 W+ ]0 |; F9 h- c) j+ I
  7.   __IO uint32_t CR;       /*!< DAC control register,                                    Address offset: 0x00 */
    # }9 |6 x7 l% o& q
  8.   __IO uint32_t SWTRIGR;  /*!< DAC software trigger register,                           Address offset: 0x04 */
    9 ?+ l4 g7 s$ Z
  9.   __IO uint32_t DHR12R1;  /*!< DAC channel1 12-bit right-aligned data holding register, Address offset: 0x08 */
    1 i: |% S; _5 l
  10.   __IO uint32_t DHR12L1;  /*!< DAC channel1 12-bit left aligned data holding register,  Address offset: 0x0C */3 N. s$ t1 E9 M! s* [: f
  11.   __IO uint32_t DHR8R1;   /*!< DAC channel1 8-bit right aligned data holding register,  Address offset: 0x10 */) G7 h  S3 d; I. ]
  12.   __IO uint32_t DHR12R2;  /*!< DAC channel2 12-bit right aligned data holding register, Address offset: 0x14 */
    : F" w1 x0 `! g
  13.   __IO uint32_t DHR12L2;  /*!< DAC channel2 12-bit left aligned data holding register,  Address offset: 0x18 */
    7 u# s' |1 T( A+ H
  14.   __IO uint32_t DHR8R2;   /*!< DAC channel2 8-bit right-aligned data holding register,  Address offset: 0x1C */6 |! Z6 s3 ], e; a! K9 w
  15.   __IO uint32_t DHR12RD;  /*!< Dual DAC 12-bit right-aligned data holding register,     Address offset: 0x20 */7 v& q0 p, p; |- D/ B* O
  16.   __IO uint32_t DHR12LD;  /*!< DUAL DAC 12-bit left aligned data holding register,      Address offset: 0x24 */) g' U1 U0 |) Q# N9 S+ U
  17.   __IO uint32_t DHR8RD;   /*!< DUAL DAC 8-bit right aligned data holding register,      Address offset: 0x28 */
    4 N3 H3 Z8 _9 m+ R2 P
  18.   __IO uint32_t DOR1;     /*!< DAC channel1 data output register,                       Address offset: 0x2C */- a% @$ l4 H  u7 D& @4 Y; e
  19.   __IO uint32_t DOR2;     /*!< DAC channel2 data output register,                       Address offset: 0x30 */
    ; t0 ^0 i5 \6 b- z' u
  20.   __IO uint32_t SR;       /*!< DAC status register,                                     Address offset: 0x34 */
    ) }" d% x0 c/ P, q
  21. } DAC_TypeDef;
复制代码

; b( t" R  t! {1 ~  G0 u
9 B# K# h$ I$ [  P) [& S0 ]9 F5 u3 e% F9 x
赞 收藏 评论0 发布时间:2022-6-16 17:00

举报

0个回答

所属标签

相似技术帖

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版