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

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

[复制链接]
STMCU小助手 发布时间:2022-6-13 08:56
01. USART固件库概述
* _2 A/ D% }0 t8 F0 I+ Ostm32f4xx_usart.h 函数的声明和类型的声明
7 ^( G" u' i+ R) i. e' m8 J1 ]( n- X! d$ H
stm32f4xx_usart.c 函数的实现
" l' Q$ T, M& D$ x2 x, `- @- }* y$ X* B
02. USART相关类型
# n8 U) m! Q9 J' qstm32f4xx_usart.h文件中
, k/ Q. `" p$ d9 W
  ^6 a5 T) c5 T2 GUSART_InitTypeDef类型- y6 P0 `! m" z: @

" _3 C/ C6 w% C: h  M* b

  1. 1 B7 \8 u) j: n6 v3 O3 W  _
  2. /** : l* c' {$ a, _5 t0 A# f8 K, `1 o
  3.   * @brief  USART Init Structure definition  0 n! f  z% l7 k0 E" [0 w) l" \8 ]
  4.   */ - a7 z6 p2 u" W0 B

  5. 3 y& U4 p4 G. B4 l/ x! r* q
  6. typedef struct% t/ ]: ~1 R5 }3 X
  7. {, z, x: l( r, R
  8.   uint32_t USART_BaudRate;            /*!< This member configures the USART communication baud rate.
    ; q$ |4 ~' A5 _( |; d
  9.                                            The baud rate is computed using the following formula:; o# N) S$ ?( o
  10.                                             - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (USART_InitStruct->USART_BaudRate)))9 s6 }* \- h3 b  ?4 G8 b
  11.                                             - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 8 * (OVR8+1)) + 0.5
    2 {" J( r- l4 {- F; d
  12.                                            Where OVR8 is the "oversampling by 8 mode" configuration bit in the CR1 register. */
    0 `/ l, ~' J4 g

  13. 3 S/ s9 U; W" E
  14.   uint16_t USART_WordLength;          /*!< Specifies the number of data bits transmitted or received in a frame.
    * J/ z4 F: G) m, I+ e0 R3 C. F8 p% }
  15.                                            This parameter can be a value of @ref USART_Word_Length */
      f0 P1 w6 f& U9 A9 w0 Z

  16. 3 Z- q- t" d8 h' ^! W
  17.   uint16_t USART_StopBits;            /*!< Specifies the number of stop bits transmitted.. {9 J  l) h' U, G$ `9 y
  18.                                            This parameter can be a value of @ref USART_Stop_Bits */6 f) \# G7 m. {! i6 Z
  19. 1 z! a3 @4 O; M# W
  20.   uint16_t USART_Parity;              /*!< Specifies the parity mode.# `7 o" j8 X! t; F- `
  21.                                            This parameter can be a value of @ref USART_Parity3 ~9 `/ h# A, u4 ~5 {# V* U
  22.                                            @note When parity is enabled, the computed parity is inserted. Z- n, f  b; K% c2 n% i
  23.                                                  at the MSB position of the transmitted data (9th bit when- ~: X, z% o: F' X! m, X
  24.                                                  the word length is set to 9 data bits; 8th bit when the
    6 W+ W6 e, Q+ A4 I
  25.                                                  word length is set to 8 data bits). */) k$ L4 _0 y9 Z; n
  26. 6 e8 J+ F# x9 i+ G' s
  27.   uint16_t USART_Mode;                /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.+ f+ |9 T* ?; a0 ?* \2 P5 m5 F1 a. l
  28.                                            This parameter can be a value of @ref USART_Mode */+ A% H2 S& h. {. `- Q! d

  29. - ^  K" B3 m  t' N& s; Y& {
  30.   uint16_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled' h% q9 L* p4 B8 q* I
  31.                                            or disabled.: U. ^- Q1 [/ b
  32.                                            This parameter can be a value of @ref USART_Hardware_Flow_Control */  R2 A8 ^% U# m# _4 V7 r1 Z" x/ X
  33. } USART_InitTypeDef;
复制代码

0 b& n7 F0 P0 i/ F' ZUSART_ClockInitTypeDef类型) D- T$ g$ }) G) h5 D8 L

9 J( `& L# }% d. f
  1. /**
    + N% `7 x* i% q7 {
  2.   * @brief  USART Clock Init Structure definition  
    ) J6 Q5 A3 S- ~& P! L; d
  3.   */
    , e( ?/ o; s2 j; X- Q  o
  4. 4 ?5 t, J4 i& q4 H3 v0 {5 _
  5. typedef struct" e1 f# @' _) t$ B
  6. {
    $ l* c* P  A, A

  7. / G; X! z& c5 `9 g* o/ ?
  8.   uint16_t USART_Clock;   /*!< Specifies whether the USART clock is enabled or disabled.
    ' T+ e+ X; A! p& m# q! o
  9.                                This parameter can be a value of @ref USART_Clock */" X; j3 M* D8 p" T1 g) i
  10. * V( l6 a: u1 P
  11.   uint16_t USART_CPOL;    /*!< Specifies the steady state of the serial clock.  r. j- z4 H  e/ T8 u/ v$ Z* {7 C
  12.                                This parameter can be a value of @ref USART_Clock_Polarity */6 a  {  _0 z; k/ J' X  j

  13. ( R4 `( @. E3 U% q: r
  14.   uint16_t USART_CPHA;    /*!< Specifies the clock transition on which the bit capture is made.
    7 R6 m, U/ O. u- ~8 j! u" b+ x
  15.                                This parameter can be a value of @ref USART_Clock_Phase */
      W# H  S/ I/ I1 R8 j7 C7 h
  16. 6 d5 V0 O2 y5 `2 s
  17.   uint16_t USART_LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
    3 C) ]. d, Q& f9 N3 W3 z5 }: y* m% k
  18.                                data bit (MSB) has to be output on the SCLK pin in synchronous mode.
    ; B  D2 J9 _& L. O/ a9 ~7 F$ T
  19.                                This parameter can be a value of @ref USART_Last_Bit */8 x+ I( |) g8 P# F5 b. W5 q: o
  20. } USART_ClockInitTypeDef;
复制代码
9 F! V+ K, m! J
USART外设& y. R% _# y0 J3 k
4 s& g. @1 q1 V3 t
  1. /** @defgroup USART_Exported_Constants  S7 d0 t: e7 u0 M  p2 W' ~' A
  2.   * @{! g, Z& i8 i5 L3 ~  m7 m- E
  3.   */ ! L& S& e' y) r$ ~! H

  4. 5 W9 s1 U, L4 y+ _% p
  5. #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \# t% M+ K0 Y; N8 E) k" g
  6.                                      ((PERIPH) == USART2) || \
    ; S5 H3 V1 C, x
  7.                                      ((PERIPH) == USART3) || \7 L- \: g& M/ }: y' t% F
  8.                                      ((PERIPH) == UART4)  || \: H8 W9 L3 k+ R- f! T3 M. n5 I
  9.                                      ((PERIPH) == UART5)  || \
    ! h$ O. A! x; V% A
  10.                                      ((PERIPH) == USART6) || \1 `/ W1 d6 q# Q6 e! t
  11.                                      ((PERIPH) == UART7)  || \) `; i  I, B$ n* W' _3 G
  12.                                      ((PERIPH) == UART8)  || \! y. p7 B. K$ E- C& u
  13.                                      ((PERIPH) == UART9)  || \1 s6 G! L8 u* J
  14.                                      ((PERIPH) == UART10)) 5 Z/ ?5 G/ k! F) |; y

  15. ; \" D& i; S5 L5 w
  16. #define IS_USART_1236_PERIPH(PERIPH) (((PERIPH) == USART1) || \$ X: o* {' I) y3 v% C) e( H  F
  17.                                       ((PERIPH) == USART2) || \: [+ Z$ |  f/ q9 v  E* e* [
  18.                                       ((PERIPH) == USART3) || \
    ; |( }/ o9 D0 K( S  n0 B
  19.                                       ((PERIPH) == USART6))
复制代码

# C% i% M. t' O4 [' m( XUSART_Word_Length
0 G/ d5 C5 c2 _: G( l0 |3 N* d
; d& Z/ ~1 N2 D, a2 Q5 b0 {) L
  1. /** @defgroup USART_Word_Length
    % m  A; I* |9 u  L- \  p, L
  2.   * @{% l' O8 `7 \+ ?$ i5 d
  3.   */
    ! E$ n6 P) |2 b, @
  4. + D; q% b: r# y, n
  5. #define USART_WordLength_8b                  ((uint16_t)0x0000)- [/ D/ R. }/ [+ ]- r* g% U
  6. #define USART_WordLength_9b                  ((uint16_t)0x1000)
    9 _9 L! e" N% g, I" I& _
  7. 7 Y! s4 S! o* K" E5 Q3 ]
  8. #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \" Z* T/ R: R( ]" x" I0 F
  9.                                       ((LENGTH) == USART_WordLength_9b))
复制代码

( ?7 C/ v4 T" [6 s5 H, _; Z& [USART_Stop_Bits
( V/ Y9 R& ]; ]6 [. C4 g" e& M4 N( x- R. A% k* y/ W
  1. /** @defgroup USART_Stop_Bits
    1 `3 n" K# j5 [
  2.   * @{  b: N2 I" e5 g4 u
  3.   */
    5 C2 w3 t. W6 N% S. F" D) e
  4. ) ?$ r! d  z! q
  5. #define USART_StopBits_1                     ((uint16_t)0x0000)# x/ T5 G. Z' x3 Y3 E0 _$ S
  6. #define USART_StopBits_0_5                   ((uint16_t)0x1000)
    8 U% g5 Q# ?. r" n
  7. #define USART_StopBits_2                     ((uint16_t)0x2000)! c; [' l+ M; m) m) A
  8. #define USART_StopBits_1_5                   ((uint16_t)0x3000)
    : L3 {% |. ]/ a% o) I
  9. #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \
    9 K  P0 S3 [# E2 W) N
  10.                                      ((STOPBITS) == USART_StopBits_0_5) || \- X4 J+ D! W+ o- D( X
  11.                                      ((STOPBITS) == USART_StopBits_2) || \( e0 G9 S0 H4 V  {7 R1 s# I
  12.                                      ((STOPBITS) == USART_StopBits_1_5))
复制代码
3 |. X7 T& ^7 ]! ]  I( O
USART_Parity' U$ Y9 g4 Q) O  s1 P! }
  a! z. y2 V( A" K3 h
  1. /** @defgroup USART_Parity
    ' @6 l* Y! J- S- T
  2.   * @{4 f6 v; g7 @# V$ v9 _4 {% h9 r* K
  3.   */
    , L& y9 g& M, D& L
  4. , Z0 r: @1 ^" L  ^$ `" U. {* B
  5. #define USART_Parity_No                      ((uint16_t)0x0000)
    0 _/ Q0 Z" X& `
  6. #define USART_Parity_Even                    ((uint16_t)0x0400)
    ) a7 p  B' n, D1 R( h
  7. #define USART_Parity_Odd                     ((uint16_t)0x0600) ! m# \% J0 p) |) ?) D. T
  8. #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \
    % J( K& P8 v2 P
  9.                                  ((PARITY) == USART_Parity_Even) || \
    ! V* `4 ^/ R6 H% j
  10.                                  ((PARITY) == USART_Parity_Odd))
复制代码

7 Z. Q7 q$ C: j6 `2 P( u7 QUSART_Mode
+ {9 `/ M9 U6 a  X. I4 c) ^# c0 G+ n' l$ A" K
  1. /** @defgroup USART_Mode
      |" S/ a0 z" t5 B
  2.   * @{
    / _/ w/ V- C- T% x+ O  k
  3.   */
    6 @: n3 v/ t3 x, |! |8 y+ X

  4.   P9 B. J* Q$ C; x1 a, |
  5. #define USART_Mode_Rx                        ((uint16_t)0x0004)6 V9 |/ g: x: x, }8 ?
  6. #define USART_Mode_Tx                        ((uint16_t)0x0008)8 w- e- F) G  N3 ]$ d3 }# x0 n
  7. #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00))
复制代码
, m2 ^4 e  s$ `( y+ C
USART_Hardware_Flow_Control$ T6 a& `5 y1 x
/ m' x2 P4 r" B2 B& x3 q, e
  1. /** @defgroup USART_Hardware_Flow_Control
    8 ?) @: @* s! a: I6 p0 q0 Z) S. Q
  2.   * @{
    3 i3 T8 y( ?8 S- b+ |, R: C
  3.   */ " Y. b' p3 G/ p; \% ?  O
  4. #define USART_HardwareFlowControl_None       ((uint16_t)0x0000)
      G5 X, D" A- H' w/ h
  5. #define USART_HardwareFlowControl_RTS        ((uint16_t)0x0100)( W8 r- I" k/ h) o; E
  6. #define USART_HardwareFlowControl_CTS        ((uint16_t)0x0200)
    ! W% V1 S$ Y; G) x" p; `( m
  7. #define USART_HardwareFlowControl_RTS_CTS    ((uint16_t)0x0300)# r$ ~; M" K3 t7 q' o  N
  8. #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\
    # a' x7 A$ H0 P# t
  9.                               (((CONTROL) == USART_HardwareFlowControl_None) || \6 G, K% [& U( W. d
  10.                                ((CONTROL) == USART_HardwareFlowControl_RTS) || \
      n$ W( O. O; _2 \3 s2 H; x
  11.                                ((CONTROL) == USART_HardwareFlowControl_CTS) || \0 t; ]3 u. X. y$ h+ e  D
  12.                                ((CONTROL) == USART_HardwareFlowControl_RTS_CTS))
复制代码
" j" x2 f% P- ^
USART_Clock1 ]0 ^) u3 w2 y$ m# X% ^

4 e* U' d) ]2 d3 U* Z9 _* N
  1. /** @defgroup USART_Clock
    ) T- x( _( X2 y* @4 B  x* z
  2.   * @{
    / `2 G0 ?( V+ O
  3.   */ - k2 r4 U1 b' N" j1 q
  4. #define USART_Clock_Disable                  ((uint16_t)0x0000)
    , [& z0 ?, H$ h! h4 X) j
  5. #define USART_Clock_Enable                   ((uint16_t)0x0800)
    / r/ x% y5 z: r! w
  6. #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \
    . U& y( V; [" l3 S
  7.                                ((CLOCK) == USART_Clock_Enable))
复制代码
0 F. U" {$ R' H4 c9 `9 W& B5 ?" ?
USART_Clock_Polarity
" O! z( q; \9 T( j9 s% [2 |  z/ @+ f9 i
  1. + C- U4 x" [$ e+ M& u- o
  2. /** @defgroup USART_Clock_Polarity ( X3 Q/ \# Y2 a9 D( k
  3.   * @{5 x9 m: H  r2 d! o, M
  4.   */
    # [3 m2 X( J( p1 ]
  5. , U: b8 D7 T( n+ U
  6. #define USART_CPOL_Low                       ((uint16_t)0x0000)
    # S$ N% @! X& U& q& Y% {
  7. #define USART_CPOL_High                      ((uint16_t)0x0400)  h9 A6 H% J9 }; t! |( ^3 h* @
  8. #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High))
复制代码

! y7 v' S/ x* y4 D2 v7 l0 OUSART_Clock_Phase# X* e& b6 P- b. k, l

% E. b, i2 @6 j# [9 k' x
  1. /** @defgroup USART_Clock_Phase
    ( R- f  h6 `3 a% n8 R1 C8 F, A9 I9 D
  2.   * @{$ b( Q( I, ~+ a
  3.   */
    3 N! q8 b0 f$ e' ]9 C- {
  4. 9 L1 |1 c2 O8 h! f
  5. #define USART_CPHA_1Edge                     ((uint16_t)0x0000)
    . B. j" ^9 r2 I; ]- O" n
  6. #define USART_CPHA_2Edge                     ((uint16_t)0x0200)
    1 o/ V% S, @. H' v) c+ c$ I
  7. #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge))
复制代码
* U0 \9 t/ m3 b7 d. @+ k5 A
USART_Last_Bit# r  I7 f4 M8 S  U5 u
; O* g- i- B- y  \, q% L+ B
  1. /** @defgroup USART_Last_Bit3 R$ J7 g# }$ r) \0 p5 _" w  W8 V
  2.   * @{) ^6 k* a) L7 }; ^/ R# q' F
  3.   */
    " T5 }8 T6 s, s: D0 P6 V

  4. 5 R1 L/ _7 [, N  W! }+ f1 V
  5. #define USART_LastBit_Disable                ((uint16_t)0x0000)
    7 J* p$ |, A+ B2 }! s) R
  6. #define USART_LastBit_Enable                 ((uint16_t)0x0100)
    ! Q4 C: m- E3 c& C% d7 e2 i2 G7 |
  7. #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \, r) e1 j9 B% c& y0 A
  8.                                    ((LASTBIT) == USART_LastBit_Enable))
复制代码

6 F1 S2 F1 [/ i# qUSART_Interrupt_definition2 d; c& C7 ~: E

5 u$ _( u; B$ Z! H7 ]
  1. /** @defgroup USART_Interrupt_definition
    6 Q0 s9 R9 p2 S
  2.   * @{/ }5 k3 i) k2 \6 x% C( m
  3.   */
    2 a9 `2 Q9 l5 y. k. Q

  4. 6 X9 v4 c" {( @+ j" X
  5. #define USART_IT_PE                          ((uint16_t)0x0028)
    4 e6 }9 e# i0 ~0 f$ \* o0 u8 f
  6. #define USART_IT_TXE                         ((uint16_t)0x0727). \' Y" [/ ]0 A3 E' ]9 c
  7. #define USART_IT_TC                          ((uint16_t)0x0626)' P8 \  j# G& z6 Q: c0 W
  8. #define USART_IT_RXNE                        ((uint16_t)0x0525)
    , N. L# v/ \: X' c, Z& t
  9. #define USART_IT_ORE_RX                      ((uint16_t)0x0325) /* In case interrupt is generated if the RXNEIE bit is set */9 Q1 U. ]9 K& @  }% V  i
  10. #define USART_IT_IDLE                        ((uint16_t)0x0424)4 L: M6 |: ]1 w$ a; N1 k7 P. l
  11. #define USART_IT_LBD                         ((uint16_t)0x0846)1 q# P" c) |7 _1 J( e3 S
  12. #define USART_IT_CTS                         ((uint16_t)0x096A)
    , k: q  c$ k# y- Q5 x
  13. #define USART_IT_ERR                         ((uint16_t)0x0060)7 }& j0 f3 Q1 \- A
  14. #define USART_IT_ORE_ER                      ((uint16_t)0x0360) /* In case interrupt is generated if the EIE bit is set */" `! b) @9 q# n# A9 Z
  15. #define USART_IT_NE                          ((uint16_t)0x0260)
    $ k* B* f. Z+ Y' O  x# f7 Z, G* u
  16. #define USART_IT_FE                          ((uint16_t)0x0160)
复制代码
  1. #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \% T, x3 ^5 c3 r' i7 z! B
  2.                                 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
    - B9 d  y: b: v3 v4 j' L
  3.                                 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
    4 }8 u2 h* y/ h6 A
  4.                                 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR))  d% f. {1 G/ Z4 X' ~! t
  5. #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
    ( p7 e: I- A- l( W% n
  6.                              ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
    + i4 p, g/ S- V9 K, q! g; I( J7 \. z
  7.                              ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
      j  d; ]7 u) ^. K6 U
  8.                              ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \* m& n+ o5 p+ \/ V  G! |
  9.                              ((IT) == USART_IT_ORE_RX) || ((IT) == USART_IT_ORE_ER) || \
    , t5 V  n/ t. N" h2 C! p6 h
  10.                              ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE)), |" n8 ]: g( K  [( M- g
  11. #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \) v3 O0 j- J0 a' F( Z1 V  s9 Y
  12.                                ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS))
复制代码
% c- d" `- @+ E
USART_DMA_Requests% H$ \: X* Q, O) Y! W# K* y* R; N0 v- @
5 {5 n8 L8 z( |
  1. /** @defgroup USART_DMA_Requests 9 d% |$ V3 |# A$ l  s
  2.   * @{
      |6 x7 M6 u: `4 |" t) i1 p4 m
  3.   */% a; D( f% i# ^9 D, Y5 t

  4. ! {9 x/ x* |; j- N
  5. #define USART_DMAReq_Tx                      ((uint16_t)0x0080)1 R8 x8 w6 Z0 f9 o9 }* q7 Z, c8 g
  6. #define USART_DMAReq_Rx                      ((uint16_t)0x0040)9 L: k- f* N, ]$ K1 X6 T
  7. #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00))
复制代码

9 e, C  n( f* p, ^+ }' t& E% I2 o! l6 X; ?* |1 b) f7 K. X
USART_WakeUp_methods1 u' D, f% S7 E( H' G. j- e
' G7 T. \: Z" f* t9 Q; @
  1. /** @defgroup USART_WakeUp_methods
    1 s. c0 T& W$ [* F
  2.   * @{+ g7 y- j! \7 p" V
  3.   */1 `1 q$ m: W* Y- l7 A
  4. 2 u& F3 m$ [2 i; E  [, G5 D& P: B
  5. #define USART_WakeUp_IdleLine                ((uint16_t)0x0000), m$ k5 t$ ?9 I8 _: {& Q1 k, X
  6. #define USART_WakeUp_AddressMark             ((uint16_t)0x0800)
    6 d: d/ \2 A! V
  7. #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \
    4 \0 p0 @9 d, M6 `0 L7 H0 L- d1 V& n
  8.                                  ((WAKEUP) == USART_WakeUp_AddressMark))
复制代码
9 A, i, N8 j2 P
USART_LIN_Break_Detection_Length
  1. /** @defgroup USART_LIN_Break_Detection_Length 4 @0 h0 @7 h; x
  2.   * @{4 m# r. X* d& v
  3.   */
    " B( t9 B/ }7 Y
  4. , X7 ]7 R) _' z# f5 u% \! I
  5. #define USART_LINBreakDetectLength_10b      ((uint16_t)0x0000)8 t  ~9 [- ^1 n, d0 U3 x# b
  6. #define USART_LINBreakDetectLength_11b      ((uint16_t)0x0020)* X6 C+ ]) h1 z) M' T, l# ^
  7. #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \
    9 @' d* T* c6 T. A: I6 X" p- g* w
  8.                                (((LENGTH) == USART_LINBreakDetectLength_10b) || \  U: t! O! g( }. v7 {; `
  9.                                 ((LENGTH) == USART_LINBreakDetectLength_11b))
复制代码
* s+ Y2 i6 u$ V
USART_IrDA_Low_Power( o* _1 R6 M$ C9 X  U# i) x  o
8 I2 @6 ^! \. R+ }# }! g' u
  1. /** @defgroup USART_IrDA_Low_Power / s2 v$ {6 ?  g" c4 |' N# u& s
  2.   * @{
    2 r0 P7 O( S0 s' I2 w+ e
  3.   */
    - m, x" ^8 j2 T1 y
  4. 6 C* R) @2 Z7 o( S
  5. #define USART_IrDAMode_LowPower              ((uint16_t)0x0004)
    % o) K( d* q  }9 P( [& U( J+ R
  6. #define USART_IrDAMode_Normal                ((uint16_t)0x0000)
    & ^1 p) G! b. {
  7. #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \" M: Y8 F! F/ C6 r  L4 ^. @
  8.                                   ((MODE) == USART_IrDAMode_Normal))
复制代码

( Z  a* x0 @9 Y: sUSART_Flags& L* V' g9 ?( A, r# e( B$ c% ~

; O/ x1 k7 C) B. B. q1 k: ^% R
  1. /** @defgroup USART_Flags & S6 t' g5 ]' W" v
  2.   * @{0 p! p+ o3 D2 X" C+ b) W" _$ W
  3.   */
    - a$ Y+ }9 L5 h

  4. ) w6 c  W9 ^5 m
  5. #define USART_FLAG_CTS                       ((uint16_t)0x0200)# Y3 _9 u( ]+ g# w! F
  6. #define USART_FLAG_LBD                       ((uint16_t)0x0100)% t5 M: X  r4 f- O/ e
  7. #define USART_FLAG_TXE                       ((uint16_t)0x0080)0 R: c! W3 X0 y  A8 p1 C
  8. #define USART_FLAG_TC                        ((uint16_t)0x0040)
    $ m+ G# z  @- b' A! o% c  b1 A
  9. #define USART_FLAG_RXNE                      ((uint16_t)0x0020)
      a9 \2 ^# Q- Q4 T- m! Z8 A0 f4 q
  10. #define USART_FLAG_IDLE                      ((uint16_t)0x0010)" W$ d, x- ^+ k" a7 L7 |& i+ v
  11. #define USART_FLAG_ORE                       ((uint16_t)0x0008)
    7 z' r& C! k% P6 p2 {0 u
  12. #define USART_FLAG_NE                        ((uint16_t)0x0004)" j4 L8 \2 |8 t% C# Y" x0 H0 Y
  13. #define USART_FLAG_FE                        ((uint16_t)0x0002)
    + _' M& u* N# V2 x3 x* b
  14. #define USART_FLAG_PE                        ((uint16_t)0x0001)
    0 _- _% ]# C6 A
  15. #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \
    6 @: V  k/ W; [% [) ?7 T
  16.                              ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \( S! W+ T1 W" D; r
  17.                              ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \' p: C$ K% l! ~* u1 }8 D5 ?! a: b
  18.                              ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \
    ) o- \, Z9 W( G% \: `6 V& @
  19.                              ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE))
    ! j- l* M/ |* _8 S% m$ Q) \
  20. , F' N+ t& p5 D# b
  21. #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00))
    $ d% G/ R7 @4 N( L4 k2 p0 s

  22. ( G2 q6 M# J9 F
  23. #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 7500001))0 O. h) u4 E5 I) K) a. ^
  24. #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)
    $ i/ J' N  K- n  M* H  i$ i* x
  25. #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF)
复制代码

) X- ]2 V* p9 ^- }3 J' F+ G03. USART相关其它宏
& R1 L7 L; G# s/ z5 }1 H& AUSART_TypeDef
, t: C. A' o9 L( @; ]+ Z7 e: G% c# ^8 l: ?1 c
  1. /** " C* D1 O6 B" T2 D; W
  2.   * @brief Universal Synchronous Asynchronous Receiver Transmitter
    , S  g% }9 p. _. e: ~9 M
  3.   */' C& K! k2 v: v0 B
  4. 2 U5 v0 \, y* C/ z) U* M4 @' j9 @* c  l
  5. typedef struct
    ) H: X$ Q7 G8 W4 _
  6. {
    3 P5 ]2 w4 T, T" P( V; X3 X2 h4 |- m
  7.   __IO uint16_t SR;         /*!< USART Status register,                   Address offset: 0x00 */* B5 N2 l8 ]; `9 l7 Q
  8.   uint16_t      RESERVED0;  /*!< Reserved, 0x02                                                */0 D" i. w' `- J' O) f3 F0 w( D
  9.   __IO uint16_t DR;         /*!< USART Data register,                     Address offset: 0x04 */
    1 I1 h4 c$ e0 v3 z  K1 e$ q  `
  10.   uint16_t      RESERVED1;  /*!< Reserved, 0x06                                                */2 f/ o* r# ?* p' ~& }
  11.   __IO uint16_t BRR;        /*!< USART Baud rate register,                Address offset: 0x08 */+ x" q5 i0 U" V' }6 s
  12.   uint16_t      RESERVED2;  /*!< Reserved, 0x0A                                                */- F" A- Y1 o8 X
  13.   __IO uint16_t CR1;        /*!< USART Control register 1,                Address offset: 0x0C */& i* r7 G: ~" ~3 p. _
  14.   uint16_t      RESERVED3;  /*!< Reserved, 0x0E                                                */
    ; ^5 Q" m' }- ?0 q# Q  [9 @
  15.   __IO uint16_t CR2;        /*!< USART Control register 2,                Address offset: 0x10 */) e7 u, ~& W; V8 ?' f) s! d6 n
  16.   uint16_t      RESERVED4;  /*!< Reserved, 0x12                                                */
    ! I4 ?& @) d' _, z
  17.   __IO uint16_t CR3;        /*!< USART Control register 3,                Address offset: 0x14 */
    % U/ y) Y9 j: i- ^% w" k' Q$ H: D
  18.   uint16_t      RESERVED5;  /*!< Reserved, 0x16                                                */
    0 N+ D  D5 Y7 x* B- S
  19.   __IO uint16_t GTPR;       /*!< USART Guard time and prescaler register, Address offset: 0x18 */
    - M% u8 L( s5 t7 d
  20.   uint16_t      RESERVED6;  /*!< Reserved, 0x1A                                                */: S$ \6 J/ L2 E
  21. } USART_TypeDef;
复制代码
  1. /******************************************************************************/
    ! D9 P$ [! Y5 _: l3 d' m
  2. /*                                                                            */
    $ B" o: l6 `6 D" s5 F
  3. /*         Universal Synchronous Asynchronous Receiver Transmitter            */
    1 W, w6 m7 l: E/ J' M% O
  4. /*                                                                            */
    # n7 P0 \4 O  [( c' O7 @
  5. /******************************************************************************/
    ' Z9 m* h3 i$ J; c; b( M  Y7 T
  6. /*******************  Bit definition for USART_SR register  *******************/
    , w7 ?7 V: V; ^, ^" \1 I7 R2 ^
  7. #define  USART_SR_PE                         ((uint16_t)0x0001)            /*!<Parity Error                 */
    , L. {7 X* V3 H7 Z; a! g5 }, B/ y
  8. #define  USART_SR_FE                         ((uint16_t)0x0002)            /*!<Framing Error                */" e2 K* D# ~2 ~5 p% i; F
  9. #define  USART_SR_NE                         ((uint16_t)0x0004)            /*!<Noise Error Flag             */
    2 G$ k* O; Z" Q
  10. #define  USART_SR_ORE                        ((uint16_t)0x0008)            /*!<OverRun Error                */
    ; S- W5 `4 e& X" H
  11. #define  USART_SR_IDLE                       ((uint16_t)0x0010)            /*!<IDLE line detected           */$ w8 I6 z! p8 B3 }* q
  12. #define  USART_SR_RXNE                       ((uint16_t)0x0020)            /*!<Read Data Register Not Empty */
    2 r% |& r% Z3 J) ~2 U% X3 j( H
  13. #define  USART_SR_TC                         ((uint16_t)0x0040)            /*!<Transmission Complete        */
    8 {. G) w* R, [- u5 m/ S. ~
  14. #define  USART_SR_TXE                        ((uint16_t)0x0080)            /*!<Transmit Data Register Empty */
    3 q% s% x( ]9 e- ]
  15. #define  USART_SR_LBD                        ((uint16_t)0x0100)            /*!<LIN Break Detection Flag     */
      ^! U) M2 t; O. b2 g/ Y% Q
  16. #define  USART_SR_CTS                        ((uint16_t)0x0200)            /*!<CTS Flag                     */! j5 g! G6 y+ }7 `5 _9 g# q
  17. $ R8 N: M+ Z8 D9 d) i3 ^/ ^
  18. /*******************  Bit definition for USART_DR register  *******************/
    4 A( B9 K, @7 T" L4 c, V
  19. #define  USART_DR_DR                         ((uint16_t)0x01FF)            /*!<Data value */
    ' b' W! H8 i% o- P' j, e# `

  20. ! W! F: A9 \$ m: ~
  21. /******************  Bit definition for USART_BRR register  *******************/0 \4 Z# B. ]( r9 b3 \0 `# T7 A
  22. #define  USART_BRR_DIV_Fraction              ((uint16_t)0x000F)            /*!<Fraction of USARTDIV */
    & \3 u+ C; N! _( e1 o; v8 G
  23. #define  USART_BRR_DIV_Mantissa              ((uint16_t)0xFFF0)            /*!<Mantissa of USARTDIV */6 ~- X/ E/ _# [& f7 |* Q
  24. ) C9 r8 ~) H8 R) S
  25. /******************  Bit definition for USART_CR1 register  *******************/% t! {( {1 t: W3 [
  26. #define  USART_CR1_SBK                       ((uint16_t)0x0001)            /*!<Send Break                             */
    7 d$ N7 b* l1 G( j
  27. #define  USART_CR1_RWU                       ((uint16_t)0x0002)            /*!<Receiver wakeup                        */
    & ^, F+ {8 q" }0 K/ ^; P7 k6 I
  28. #define  USART_CR1_RE                        ((uint16_t)0x0004)            /*!<Receiver Enable                        */
    5 R( J  K' p4 K0 u* F
  29. #define  USART_CR1_TE                        ((uint16_t)0x0008)            /*!<Transmitter Enable                     */
    9 J; Y9 K) l: A! ~/ ]! r6 d
  30. #define  USART_CR1_IDLEIE                    ((uint16_t)0x0010)            /*!<IDLE Interrupt Enable                  */9 j0 g, _/ \/ N: ?6 t( }9 q
  31. #define  USART_CR1_RXNEIE                    ((uint16_t)0x0020)            /*!<RXNE Interrupt Enable                  */5 n) _! U( k! B& O3 U7 I* }
  32. #define  USART_CR1_TCIE                      ((uint16_t)0x0040)            /*!<Transmission Complete Interrupt Enable *// p2 x, u5 ]5 P- R
  33. #define  USART_CR1_TXEIE                     ((uint16_t)0x0080)            /*!<PE Interrupt Enable                    */
    0 _) n1 T" S/ H% i8 i
  34. #define  USART_CR1_PEIE                      ((uint16_t)0x0100)            /*!<PE Interrupt Enable                    */4 P( F$ w( l( h1 Y$ N  Z- R
  35. #define  USART_CR1_PS                        ((uint16_t)0x0200)            /*!<Parity Selection                       */
    & S$ B1 ^+ F, ]
  36. #define  USART_CR1_PCE                       ((uint16_t)0x0400)            /*!<Parity Control Enable                  */* ?3 R& _# z; |, G/ s, y
  37. #define  USART_CR1_WAKE                      ((uint16_t)0x0800)            /*!<Wakeup method                          */
    0 V$ }, R( I% a
  38. #define  USART_CR1_M                         ((uint16_t)0x1000)            /*!<Word length                            *// D5 A) y7 `' \: r6 u
  39. #define  USART_CR1_UE                        ((uint16_t)0x2000)            /*!<USART Enable                           */
    / B/ U: W1 x- C, @
  40. #define  USART_CR1_OVER8                     ((uint16_t)0x8000)            /*!<USART Oversampling by 8 enable         */: A8 V/ e; g  n% P- b8 A

  41. 1 B% z, W( v- U
  42. /******************  Bit definition for USART_CR2 register  *******************/
    ; M, ]/ ~: p+ V3 g6 i4 f) ]
  43. #define  USART_CR2_ADD                       ((uint16_t)0x000F)            /*!<Address of the USART node            */
    7 l) E% ?( ?) Q7 Q
  44. #define  USART_CR2_LBDL                      ((uint16_t)0x0020)            /*!<LIN Break Detection Length           */' n6 w+ N6 @/ }. A" W& h
  45. #define  USART_CR2_LBDIE                     ((uint16_t)0x0040)            /*!<LIN Break Detection Interrupt Enable */
    / V* v& K! h( {: L! x5 |
  46. #define  USART_CR2_LBCL                      ((uint16_t)0x0100)            /*!<Last Bit Clock pulse                 */
    8 E8 O* \7 i7 `9 V! g
  47. #define  USART_CR2_CPHA                      ((uint16_t)0x0200)            /*!<Clock Phase                          */. K) Q2 N$ a$ }' I
  48. #define  USART_CR2_CPOL                      ((uint16_t)0x0400)            /*!<Clock Polarity                       */9 C/ G$ U3 r) k7 Q
  49. #define  USART_CR2_CLKEN                     ((uint16_t)0x0800)            /*!<Clock Enable                         */
    + G: l3 H; w, c* v4 R4 }' \8 U, O9 j
  50. ! l, w- `" v# N+ A2 s
  51. #define  USART_CR2_STOP                      ((uint16_t)0x3000)            /*!<STOP[1:0] bits (STOP bits) */* P/ d; i! [% l3 @2 G" r2 ~
  52. #define  USART_CR2_STOP_0                    ((uint16_t)0x1000)            /*!<Bit 0 */
    ! J) }$ {( M; a6 Z* x% v
  53. #define  USART_CR2_STOP_1                    ((uint16_t)0x2000)            /*!<Bit 1 */
    : I& z" x0 O, Q. S; @: S

  54. ! n0 E5 N! E7 _7 P/ `9 [4 u$ U& |( Z+ ^
  55. #define  USART_CR2_LINEN                     ((uint16_t)0x4000)            /*!<LIN mode enable */
    8 n7 `; g. i& q" U0 R0 [

  56. / m; r* _" i3 l6 J3 f
  57. /******************  Bit definition for USART_CR3 register  *******************/( k% e: i3 D2 w8 Y  z8 ], n
  58. #define  USART_CR3_EIE                       ((uint16_t)0x0001)            /*!<Error Interrupt Enable      */
    " f" F/ j1 [5 ?3 u: Z" }  l- v+ E
  59. #define  USART_CR3_IREN                      ((uint16_t)0x0002)            /*!<IrDA mode Enable            */
    1 I; E; c: H6 [' s
  60. #define  USART_CR3_IRLP                      ((uint16_t)0x0004)            /*!<IrDA Low-Power              */
    / y; A$ `; Y7 \$ B: Y
  61. #define  USART_CR3_HDSEL                     ((uint16_t)0x0008)            /*!<Half-Duplex Selection       */
    ; ?" K% ~+ Q! c( F
  62. #define  USART_CR3_NACK                      ((uint16_t)0x0010)            /*!<Smartcard NACK enable       */
    9 T/ U8 d7 f# I9 }& }+ k
  63. #define  USART_CR3_SCEN                      ((uint16_t)0x0020)            /*!<Smartcard mode enable       */: J: f7 _5 [" \$ c
  64. #define  USART_CR3_DMAR                      ((uint16_t)0x0040)            /*!<DMA Enable Receiver         */
    + Q! Z6 n6 v! Y, R6 x
  65. #define  USART_CR3_DMAT                      ((uint16_t)0x0080)            /*!<DMA Enable Transmitter      */
    ( n6 l: y( t5 o  M% _$ K- a8 [
  66. #define  USART_CR3_RTSE                      ((uint16_t)0x0100)            /*!<RTS Enable                  */
    ) l% O7 J! r1 g0 w6 o* Y0 {
  67. #define  USART_CR3_CTSE                      ((uint16_t)0x0200)            /*!<CTS Enable                  */, M: l9 v- u+ ]% }" C; U
  68. #define  USART_CR3_CTSIE                     ((uint16_t)0x0400)            /*!<CTS Interrupt Enable        */, r  x0 K- L1 M- R2 O" C. e
  69. #define  USART_CR3_ONEBIT                    ((uint16_t)0x0800)            /*!<USART One bit method enable */
    5 V3 D9 {4 H6 h4 g! \/ a

  70. 3 s- |/ y2 _4 {+ S9 f9 f
  71. /******************  Bit definition for USART_GTPR register  ******************/( Z4 U! c+ Q: p8 S2 q
  72. #define  USART_GTPR_PSC                      ((uint16_t)0x00FF)            /*!<PSC[7:0] bits (Prescaler value) */; Y$ I, b" q+ }  p8 p1 V9 {3 L% l' K
  73. #define  USART_GTPR_PSC_0                    ((uint16_t)0x0001)            /*!<Bit 0 */
    3 _* `3 y) N( _9 V
  74. #define  USART_GTPR_PSC_1                    ((uint16_t)0x0002)            /*!<Bit 1 */
    ' v" O& K- r* |- ~
  75. #define  USART_GTPR_PSC_2                    ((uint16_t)0x0004)            /*!<Bit 2 */4 a# f- H) p. C* f7 W
  76. #define  USART_GTPR_PSC_3                    ((uint16_t)0x0008)            /*!<Bit 3 */# p- @6 T/ [; F4 }3 i% h5 v. {
  77. #define  USART_GTPR_PSC_4                    ((uint16_t)0x0010)            /*!<Bit 4 */) _( _% o! |+ Y& f& `$ ^
  78. #define  USART_GTPR_PSC_5                    ((uint16_t)0x0020)            /*!<Bit 5 *// Y- E; ~9 H' ?. c$ C! V9 r; q
  79. #define  USART_GTPR_PSC_6                    ((uint16_t)0x0040)            /*!<Bit 6 */
    2 f/ e8 l( a% w7 F
  80. #define  USART_GTPR_PSC_7                    ((uint16_t)0x0080)            /*!<Bit 7 */
    4 a3 P/ k) u7 h, @  |
  81. 8 R5 P! Y7 v: K3 c- W# B
  82. #define  USART_GTPR_GT                       ((uint16_t)0xFF00)            /*!<Guard time value */
复制代码

# N5 X% `; l; A2 p$ D) ^7 |04. USART相关函数6 l- z- A7 A$ G% |: }7 ~" Q4 @) W* f
  1. /*  Function used to set the USART configuration to the default reset state ***/
    7 q# c9 v, x" ^% v
  2. void USART_DeInit(USART_TypeDef* USARTx);7 Y! z! s4 |/ ^8 e: l

  3. , w/ w$ P2 \+ j: @7 }. B  v
  4. /* Initialization and Configuration functions *********************************/9 I  v% h; P( O; `
  5. void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);
    0 k. _% J+ e; w2 B# c( T/ A
  6. void USART_StructInit(USART_InitTypeDef* USART_InitStruct);
    - u$ n2 ]6 P: Z, [
  7. void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct);' m' k& {+ o' x' U* Q
  8. void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct);, K$ a, V! h0 Q
  9. void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState);% l6 ~; Z" c: a$ w, K
  10. void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler);
    6 k. [& D1 G9 N" _5 o
  11. void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
    1 U1 V" U0 ^+ y. C8 }6 i6 R1 P
  12. void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState);
    7 j( B% M5 ?" l& O+ X
  13. 2 U- j  F( i5 }9 ^
  14. /* Data transfers functions ***************************************************/
    9 ^; @# x" e+ i2 T5 q+ K
  15. void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);
    . B+ u. e: a$ K+ |" F* h/ {
  16. uint16_t USART_ReceiveData(USART_TypeDef* USARTx);
    ' [. Q1 s" l3 Q9 I: f% C

  17. * P2 |" S4 d/ Q& j. u
  18. /* Multi-Processor Communication functions ************************************/3 q% @/ ~  }. C  m; U: L) f
  19. void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address);1 T4 @" C" F) A# g5 a6 d2 t  O
  20. void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp);
    7 A* U: r/ \3 ~, K' q7 P
  21. void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState);
    $ m: F* Z2 F5 J
  22. - h+ _0 t5 ]& Z8 s3 ?. r- [
  23. /* LIN mode functions *********************************************************/1 k! Z7 m1 |4 ?% l5 n/ G* R! S
  24. void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength);2 L2 l4 p6 P( h( U# T4 @
  25. void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState);
    1 d# H. s: m$ |$ B7 f7 A, P0 e1 [
  26. void USART_SendBreak(USART_TypeDef* USARTx);
    0 L" K3 F7 s$ [1 S, w) p  I) f

  27. ( L5 A( d$ a% Z" Z- t. [
  28. /* Half-duplex mode function **************************************************/; x' B. `" m8 ^/ C0 E
  29. void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState);- z+ e0 @. o6 e% i* b$ {
  30. ( x- t9 b* j) \6 k( J/ J0 V
  31. /* Smartcard mode functions ***************************************************/: H' p4 y3 R, L9 B' a
  32. void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState);+ x+ w, `9 P+ W( P" z
  33. void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState);7 k! F. ?3 W, d* t" j; w3 I1 m7 N3 l
  34. void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime);
    / P( z1 u) y7 R( G, A# `' ^6 o6 p9 m
  35. 8 M- p& i) H$ ^7 k: u
  36. /* IrDA mode functions ********************************************************/
    7 o& n" c( Q+ y. j9 x0 x/ G* s; W% |
  37. void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode);
    ; k! u, G8 w+ \
  38. void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState);- D6 K1 E1 _) F3 j4 q; [) L, [
  39. 6 H; m# r, @# L2 J- y
  40. /* DMA transfers management functions *****************************************/4 i( _+ G* v$ C/ Z. O
  41. void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);0 l7 O8 z% _0 p% `7 S# ]) K/ H& j
  42. ' B) J- ?7 ~; \& w9 X+ g1 `
  43. /* Interrupts and flags management functions **********************************/
    2 I# o1 T4 U% s+ X
  44. void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);
    9 i  O" d2 z% u4 ^$ I
  45. FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);
    , ^& A+ Y% G( R: N9 Z% j! C% h
  46. void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG);
    & z3 L/ z+ _* V0 t9 y+ F: @
  47. ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);
    ( t# d; w) i" N" d. s
  48. void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);
复制代码
' _. L, Q, g: t7 W
05. USART其它
, }' a; j) p$ }0 BUSART基地址* f  L4 f2 e7 r: T! S

+ O  P8 D  o' N# c( ?
  1. #define USART2_BASE           (APB1PERIPH_BASE + 0x4400)
    + J/ _8 k5 g" r, |4 I4 T, H
  2. #define USART3_BASE           (APB1PERIPH_BASE + 0x4800)3 l5 \3 {$ G+ B8 y7 D% I  J
  3. #define UART4_BASE            (APB1PERIPH_BASE + 0x4C00)  p* ~; g$ T' a1 A, H
  4. #define UART5_BASE            (APB1PERIPH_BASE + 0x5000)$ p2 b$ l; _0 I/ \4 l

  5. . [+ z+ e* z9 _, K2 Y; U' Y/ i- j+ W9 F
  6. #define USART1_BASE           (APB2PERIPH_BASE + 0x1000)
    ) }* \; c/ H; j! l
  7. #define USART6_BASE           (APB2PERIPH_BASE + 0x1400)
    & c7 x, X) ~9 f- o/ c/ _
  8. #define UART9_BASE            (APB2PERIPH_BASE + 0x1800U). t; |6 f9 |1 [  L- {
  9. #define UART10_BASE           (APB2PERIPH_BASE + 0x1C00U)
复制代码

2 y( I# ?. f5 G% K3 X4 S/ p* B& U! g0 i' T
赞 收藏 评论0 发布时间:2022-6-13 08:56

举报

0个回答

所属标签

相似技术帖

官网相关资源

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