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

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

[复制链接]
STMCU小助手 发布时间:2022-6-13 08:56
01. USART固件库概述
3 \: L4 D3 }; J; R/ T7 q+ _stm32f4xx_usart.h 函数的声明和类型的声明4 o( Y1 _: d9 C4 T
- G$ C) k5 N7 T$ E% K
stm32f4xx_usart.c 函数的实现
, E5 y( G5 U! ~! U1 m' l- G3 L; m/ b  W/ u8 s9 V: W* Y4 U
02. USART相关类型1 U! i0 g: \5 ?0 t
stm32f4xx_usart.h文件中
: j! v' L3 B' @5 j/ D% j" F' `4 R- a$ U& G7 @
USART_InitTypeDef类型) ^( l9 X& C, K) P- a: `

) `$ `/ V# \* m. X0 m7 k5 c' N
  1. 7 p4 R1 G; s2 h; |9 J7 Y
  2. /**
    8 ^& f4 e- J$ u- [9 @, F7 x
  3.   * @brief  USART Init Structure definition  6 S: R0 y* g2 u5 q5 n! E* `  z
  4.   */
    $ ?& Q% H  n4 k7 E
  5.   r! _( b8 i% |5 M$ H/ S
  6. typedef struct/ L: i6 B) `1 C5 C
  7. {
    - j3 W  ?3 |7 j- e# [
  8.   uint32_t USART_BaudRate;            /*!< This member configures the USART communication baud rate.
    # ~: ]/ X9 D3 C  S* P5 G
  9.                                            The baud rate is computed using the following formula:. \7 `8 m- q) \! M$ K, U/ p
  10.                                             - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (USART_InitStruct->USART_BaudRate)))" u( V6 A7 T1 k+ o4 Y8 y; C
  11.                                             - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 8 * (OVR8+1)) + 0.5
    ' z3 n; i8 `9 q( n7 _5 g% W; A6 B
  12.                                            Where OVR8 is the "oversampling by 8 mode" configuration bit in the CR1 register. */
      ?8 \- j" K  [8 T
  13. 2 x/ @$ l' B  C5 [" A
  14.   uint16_t USART_WordLength;          /*!< Specifies the number of data bits transmitted or received in a frame.6 U. O, l, H6 a9 }/ p1 x
  15.                                            This parameter can be a value of @ref USART_Word_Length */8 n2 f1 V8 `% U" z2 j# H
  16. # m* w0 e( z) S& D1 G
  17.   uint16_t USART_StopBits;            /*!< Specifies the number of stop bits transmitted.
    0 V* u! i. r7 E, V- e. C
  18.                                            This parameter can be a value of @ref USART_Stop_Bits */
    1 i) I, a/ ~" \8 H, L- _9 t& Z

  19. ( A1 a, @. a  Y
  20.   uint16_t USART_Parity;              /*!< Specifies the parity mode.# n. \( s; C  t( t! a2 a: N
  21.                                            This parameter can be a value of @ref USART_Parity$ L) O3 Q- p& ^* E- D
  22.                                            @note When parity is enabled, the computed parity is inserted" V2 `& J" ^9 t  T
  23.                                                  at the MSB position of the transmitted data (9th bit when, u$ F4 k- J. j3 c$ C" G0 C, T
  24.                                                  the word length is set to 9 data bits; 8th bit when the
    % q( Z0 F; u+ u. `5 {
  25.                                                  word length is set to 8 data bits). */
    * L: ~; o2 f6 W; y# R* Y

  26. - {5 ~0 ?* y7 t" y
  27.   uint16_t USART_Mode;                /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.2 [# G7 e4 {8 A! e' h
  28.                                            This parameter can be a value of @ref USART_Mode */+ ]: U, [  r) z4 g% B

  29. ; T) T6 K' }) _, Q( s" j6 ^# N
  30.   uint16_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled
    $ ]. o" `; s* ]" \; S
  31.                                            or disabled.
    0 |: Z1 Z) T+ X4 C' ]  H
  32.                                            This parameter can be a value of @ref USART_Hardware_Flow_Control */! s; a+ @, ?  v, J; s. n" H
  33. } USART_InitTypeDef;
复制代码
4 [' Q2 N# m# }/ v
USART_ClockInitTypeDef类型
5 C8 f) S7 @# i$ u( W( P1 q; o
$ J7 N, n# I: c5 s0 @4 I
  1. /**
    ' }. y/ B; P" q
  2.   * @brief  USART Clock Init Structure definition  
    ( r3 j- B. Q6 m8 Z, B
  3.   */
    ! {( c+ ^: r, W: Y& ]
  4.   @$ E) r. {# R: z. F4 D% I
  5. typedef struct
    8 m* x& p% S. u( L
  6. {) `  X& F8 _& l! g
  7. $ L+ ^; _* J* s6 l3 |- _2 b! L
  8.   uint16_t USART_Clock;   /*!< Specifies whether the USART clock is enabled or disabled.2 k; A& G7 e6 Q  ~
  9.                                This parameter can be a value of @ref USART_Clock */
    5 T1 Y- _. w1 t: a1 c

  10. % h7 H3 e6 V8 H, t) X7 l( ^, g4 r, A
  11.   uint16_t USART_CPOL;    /*!< Specifies the steady state of the serial clock.8 n3 @3 }* A3 P& ^) B# `; L
  12.                                This parameter can be a value of @ref USART_Clock_Polarity */! l: d5 ^$ H2 h5 H% |
  13. 7 b& ?6 f7 J" ~' j2 N2 L
  14.   uint16_t USART_CPHA;    /*!< Specifies the clock transition on which the bit capture is made.
    7 m( V! Y# ^8 T3 ^" p
  15.                                This parameter can be a value of @ref USART_Clock_Phase */7 d; R$ C0 ]% f

  16. % X6 B7 ~2 V, a# A
  17.   uint16_t USART_LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
    ; H$ U6 c8 u9 u% R( G* x( F
  18.                                data bit (MSB) has to be output on the SCLK pin in synchronous mode.1 j$ j8 H4 f6 O( \# b/ c
  19.                                This parameter can be a value of @ref USART_Last_Bit */+ {5 n5 n; k( O
  20. } USART_ClockInitTypeDef;
复制代码
3 c& @1 V6 a6 T" s
USART外设0 O( h" m, I& M. _
5 c4 L8 ^( i9 T3 R+ M- b
  1. /** @defgroup USART_Exported_Constants
    5 d2 Z) Y! s4 @9 X. A
  2.   * @{1 \7 b6 r3 [) y+ Q. N. ^) j
  3.   */
    ' q# B5 G1 j- p- I: m: N. b3 a1 S
  4. 8 Y3 ?2 q& `3 d4 F
  5. #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \
    8 S! u9 c$ R$ m2 s/ Z( y, n5 a' g
  6.                                      ((PERIPH) == USART2) || \/ d9 q2 d1 J" K
  7.                                      ((PERIPH) == USART3) || \/ w5 K% M# T3 X0 e
  8.                                      ((PERIPH) == UART4)  || \6 ]7 s0 \/ e1 w/ N) Y
  9.                                      ((PERIPH) == UART5)  || \- y7 {: h* C9 s4 Z( c2 [+ T
  10.                                      ((PERIPH) == USART6) || \
      N+ G+ ?( A  B$ R3 Q, ?1 M
  11.                                      ((PERIPH) == UART7)  || \
    8 t) \& R* o! P, i# D! ?  C2 B4 J
  12.                                      ((PERIPH) == UART8)  || \* U  E" q% `& ^* C$ z. G& j9 K
  13.                                      ((PERIPH) == UART9)  || \! F) h6 i+ V% F% o2 s6 Z/ {4 n
  14.                                      ((PERIPH) == UART10)) 1 i: _; G  Q1 V2 N
  15. / t8 F1 B8 e) I) ?3 p- P
  16. #define IS_USART_1236_PERIPH(PERIPH) (((PERIPH) == USART1) || \
    ) K# O! y( L" I+ B- s
  17.                                       ((PERIPH) == USART2) || \3 s0 y6 c2 }, m) u- D$ K
  18.                                       ((PERIPH) == USART3) || \
    ! {! N. {( k9 I) {! Q/ s
  19.                                       ((PERIPH) == USART6))
复制代码
3 ]' x1 U3 }/ {0 S
USART_Word_Length, t: q; |# s1 f6 D! c
1 w6 Z: Q8 g# d
  1. /** @defgroup USART_Word_Length 2 D2 n' j) d( _  ?2 y* N# e* L
  2.   * @{' {7 V6 t) A7 v" L- f6 `+ g# w
  3.   */ % f) D- s5 f% W, Z* b  M* X

  4. & F5 A% }, n+ j, n
  5. #define USART_WordLength_8b                  ((uint16_t)0x0000)
    / U6 o% j1 i# J  y' F" k+ b/ l; U
  6. #define USART_WordLength_9b                  ((uint16_t)0x1000)2 |: \: R& X$ P* K

  7. / s6 I4 S9 v4 L) b9 w+ Q
  8. #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \/ e+ r. r8 Q# [, i* p# \
  9.                                       ((LENGTH) == USART_WordLength_9b))
复制代码

9 b7 A  L- Z/ r% BUSART_Stop_Bits
# q, n4 k' P. `* g" U$ u+ U8 L" F* L0 f$ ^8 B) b/ Y
  1. /** @defgroup USART_Stop_Bits
    , ]; R1 h: M6 b1 ]! A
  2.   * @{
    ) M9 b! _3 R$ W/ i, {" ^: e" v( Q
  3.   */ - v; G5 F% ^4 p
  4. , T9 c7 o1 X2 v$ v6 S
  5. #define USART_StopBits_1                     ((uint16_t)0x0000)
    / h! \8 y% g4 w, v7 z) D' z
  6. #define USART_StopBits_0_5                   ((uint16_t)0x1000)
      B# j: C7 ~# H( S  }$ o0 q  E! O/ D
  7. #define USART_StopBits_2                     ((uint16_t)0x2000)+ @, Y8 J# ^7 @0 T
  8. #define USART_StopBits_1_5                   ((uint16_t)0x3000)/ H- F9 f7 e; d! h. y' L
  9. #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \
    2 e# g: G" d/ ^/ D9 E8 g
  10.                                      ((STOPBITS) == USART_StopBits_0_5) || \/ r# L) V3 Z1 Q  P* r
  11.                                      ((STOPBITS) == USART_StopBits_2) || \% H: R; F) g* S1 P% p: O# l
  12.                                      ((STOPBITS) == USART_StopBits_1_5))
复制代码
$ f$ @3 n+ K$ x& h  o
USART_Parity
+ p# ]  ^7 p) n; w8 `0 g
7 i: n# o, K4 @( M5 s5 w8 ^! e
  1. /** @defgroup USART_Parity 0 v* {3 N9 {; f1 h; C
  2.   * @{5 S1 n, N+ p" y4 d
  3.   */
    . I; H& Y' o5 S, _$ E5 D

  4. ! r# X  w6 J/ T6 d# ~" b8 \7 W
  5. #define USART_Parity_No                      ((uint16_t)0x0000)
    ! ~6 f3 C0 i2 s; x9 U
  6. #define USART_Parity_Even                    ((uint16_t)0x0400)
    $ _3 h1 z! C) J
  7. #define USART_Parity_Odd                     ((uint16_t)0x0600) ' e4 \  m9 i$ m3 ~+ w5 Q! z
  8. #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \
    & o+ B8 k3 Y3 @
  9.                                  ((PARITY) == USART_Parity_Even) || \
    # P  {, k0 M5 L
  10.                                  ((PARITY) == USART_Parity_Odd))
复制代码

1 P: a  P# k! n2 m, [. zUSART_Mode- B9 d* ^/ O$ H! v: h$ u

" s- h' Q9 j* a; e
  1. /** @defgroup USART_Mode
      ]+ J5 d  E/ t, H' H- t7 D' H- [% M6 d
  2.   * @{
    / ]5 W  l0 O+ e. h1 ~
  3.   */
    & U" ]* |3 |& e6 A! l
  4. 7 f# x4 b+ B1 S$ R
  5. #define USART_Mode_Rx                        ((uint16_t)0x0004)
    " P. `8 K9 `) g
  6. #define USART_Mode_Tx                        ((uint16_t)0x0008). |$ A& F% U, Z, l6 E
  7. #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00))
复制代码

7 R/ P1 ]( l9 f% s9 T3 wUSART_Hardware_Flow_Control
9 W# ?; ^9 T1 ]7 t% @' M( u
8 w; g9 N5 Y, C$ I9 [) P- Z
  1. /** @defgroup USART_Hardware_Flow_Control
      C  J# O! f( n/ d6 W3 |% F
  2.   * @{' M! Y& b# Z- F# W1 \8 e5 U
  3.   */ 6 W6 N6 R. H* R2 s' P" O" I
  4. #define USART_HardwareFlowControl_None       ((uint16_t)0x0000)
    9 @: H* d! {! W2 ~) A( x" a
  5. #define USART_HardwareFlowControl_RTS        ((uint16_t)0x0100)
    + f) ?# M' ]% D+ j
  6. #define USART_HardwareFlowControl_CTS        ((uint16_t)0x0200)# w" r( {+ P  s
  7. #define USART_HardwareFlowControl_RTS_CTS    ((uint16_t)0x0300)
    3 v( E$ {5 B& b  M2 |
  8. #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\" X, n+ E  m. ^# g8 v+ m: a, b
  9.                               (((CONTROL) == USART_HardwareFlowControl_None) || \: O+ W$ z2 E0 C5 L0 ^& M
  10.                                ((CONTROL) == USART_HardwareFlowControl_RTS) || \1 |. S. e$ a( W" p9 A: j* p
  11.                                ((CONTROL) == USART_HardwareFlowControl_CTS) || \
    ' o# Z) i" b3 T! r" l2 z
  12.                                ((CONTROL) == USART_HardwareFlowControl_RTS_CTS))
复制代码

0 c: @& H1 U7 z, \( J/ ?, e! @USART_Clock
! w4 `+ ]3 k) N: Z* x, _- u' g9 Q: a- c% A; a& g
  1. /** @defgroup USART_Clock % ]( q8 ?2 N8 _5 J0 x5 Z& x9 Z4 m
  2.   * @{6 Y; E4 v4 S3 e4 n( f, [
  3.   */ ! Z0 Q( t0 M" p6 y; ^" `
  4. #define USART_Clock_Disable                  ((uint16_t)0x0000)
    # F* t1 [8 ^. x2 V% Y) a
  5. #define USART_Clock_Enable                   ((uint16_t)0x0800)/ J0 ^3 j$ Q. Z! n, T: S5 n0 E+ \
  6. #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \- }5 P/ L, f" s) \2 H5 A3 M
  7.                                ((CLOCK) == USART_Clock_Enable))
复制代码
- V& J* B- }# a' j; E/ D
USART_Clock_Polarity8 Q) A- Y$ L" w" [' g4 o2 D9 k4 ?

  B5 T! S, p  y2 p% w: Z
  1. * ~8 d/ y, _( C2 f
  2. /** @defgroup USART_Clock_Polarity
    % O; X# y9 c2 ?0 F1 s0 I
  3.   * @{
    / a/ B2 v) k2 N
  4.   */5 [  a5 R& n+ A; |4 J
  5. $ k* v, q; i* g( K7 z4 L1 K
  6. #define USART_CPOL_Low                       ((uint16_t)0x0000)
    - t. k2 A' N; D! E( T# ]. Y
  7. #define USART_CPOL_High                      ((uint16_t)0x0400)
    / C! N+ p+ Q* K; k! W! I/ c& m
  8. #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High))
复制代码
- Q/ h: m3 f- D9 l( V# f
USART_Clock_Phase( l) T+ \; ?8 H# i8 A- k

, U3 a$ f' c; s- i% c4 r
  1. /** @defgroup USART_Clock_Phase1 Y3 `5 ^$ ]/ k0 e2 W
  2.   * @{, G# g( J9 w# D0 c7 q) H3 W" r
  3.   */
      a! V. C' p. }  P

  4. ' w! s& X2 ]! k$ [; t! l0 ^0 [
  5. #define USART_CPHA_1Edge                     ((uint16_t)0x0000)" z2 g4 X1 `4 P1 w0 s% _
  6. #define USART_CPHA_2Edge                     ((uint16_t)0x0200)7 y$ W% k+ ~% r* K
  7. #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge))
复制代码

, [5 w* r- @3 ~  cUSART_Last_Bit
" G4 f9 ]- W& J% \* e+ w* j  _" C$ j; L5 S' S6 y# n
  1. /** @defgroup USART_Last_Bit7 z' }# c# b* R$ }5 x0 T) P
  2.   * @{
    6 X3 D" i: F. ^7 a4 J7 U, T! ^: z
  3.   */0 x0 r3 T& W5 |4 \% M

  4. , U5 p- c8 H7 ^( [3 s/ w
  5. #define USART_LastBit_Disable                ((uint16_t)0x0000)
    0 C2 x; o: w% j, F
  6. #define USART_LastBit_Enable                 ((uint16_t)0x0100)
      C) @) b% b& o$ u- M! Y$ W
  7. #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \5 G4 m' m* ]  B
  8.                                    ((LASTBIT) == USART_LastBit_Enable))
复制代码

& e& W/ h5 m" s7 VUSART_Interrupt_definition
8 g/ N  B2 F2 {: a, f$ f" x5 k: g" A2 e
  1. /** @defgroup USART_Interrupt_definition
    " ^5 E5 \' \) U" m/ q9 Q& a$ f/ \4 s
  2.   * @{
    & d' l) R5 P4 a! E3 I
  3.   */' d' I# b" W1 Q8 \! O7 P+ S5 q
  4. ) R8 U5 b1 S% H7 l& I  G
  5. #define USART_IT_PE                          ((uint16_t)0x0028)
    " b! a* X/ M, N2 ^+ v4 y0 V) n
  6. #define USART_IT_TXE                         ((uint16_t)0x0727)# b4 l, \+ p! l, Y3 n1 v
  7. #define USART_IT_TC                          ((uint16_t)0x0626)
    1 J. N, M+ O4 q" N
  8. #define USART_IT_RXNE                        ((uint16_t)0x0525)' Z: U6 y# x( W4 }/ A
  9. #define USART_IT_ORE_RX                      ((uint16_t)0x0325) /* In case interrupt is generated if the RXNEIE bit is set */* M) ?2 y' r  _0 Q
  10. #define USART_IT_IDLE                        ((uint16_t)0x0424)5 Q- Z1 e4 z9 v4 T; N  S4 M; K
  11. #define USART_IT_LBD                         ((uint16_t)0x0846)9 f( H5 f* n) p
  12. #define USART_IT_CTS                         ((uint16_t)0x096A)
    % g6 \- J3 h! I* s! Q* \5 K
  13. #define USART_IT_ERR                         ((uint16_t)0x0060)0 I6 \! ~4 x) a
  14. #define USART_IT_ORE_ER                      ((uint16_t)0x0360) /* In case interrupt is generated if the EIE bit is set */
    / j8 {  ?& O$ `( l, X' T
  15. #define USART_IT_NE                          ((uint16_t)0x0260)
    1 b4 V+ J& g1 G: V. a; t3 [6 C
  16. #define USART_IT_FE                          ((uint16_t)0x0160)
复制代码
  1. #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
    8 C5 A9 [" b2 ]% V4 d# E
  2.                                 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \% I/ z+ \7 p$ t& @
  3.                                 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
    $ p  i1 ?- U( H, c8 a4 x
  4.                                 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR))
      Q* T1 X  Y0 z2 l4 ^6 t/ m( N2 ^
  5. #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
    $ p% Q! _7 f- f/ {( R
  6.                              ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \+ J; r, F: {, K  u
  7.                              ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
    5 ]/ q5 M. ~7 n; I" C! n" d
  8.                              ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \
    : C5 g% P. e& Q* w
  9.                              ((IT) == USART_IT_ORE_RX) || ((IT) == USART_IT_ORE_ER) || \
    , d& {; h4 n, _/ `3 v5 U, I
  10.                              ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE))
    # \5 a5 v" o1 y; m' g
  11. #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \0 T! L! R  S, _( H+ v! d
  12.                                ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS))
复制代码

/ R0 y0 x$ i) W. cUSART_DMA_Requests$ r; z, B+ |% b, G) ~; x5 B; h

$ ]$ o0 p3 W3 g" E
  1. /** @defgroup USART_DMA_Requests
    # O8 e2 g8 ?3 P" g9 t# O7 `
  2.   * @{
    4 v4 ^$ D+ E0 L1 X
  3.   */
    # `9 R4 d: E% }+ z) J5 ?
  4.   y- o+ b! Y; s0 ~
  5. #define USART_DMAReq_Tx                      ((uint16_t)0x0080)* L5 I& v7 j3 u/ E, b4 g; l
  6. #define USART_DMAReq_Rx                      ((uint16_t)0x0040)
    3 R* s1 R/ O4 ^
  7. #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00))
复制代码
6 \: _7 f1 b* ?: E  p

+ A- V/ @2 a# o# @2 y' s$ u. rUSART_WakeUp_methods
' I$ ?& {9 {% r! }1 r+ H! q9 y6 f8 m! U/ d/ I5 L
  1. /** @defgroup USART_WakeUp_methods
    6 y8 J# U# q$ ~+ V
  2.   * @{9 o0 U* @1 B) q
  3.   */
      L/ D: n. M6 ~% r- s
  4. 8 L2 G9 z# Z! z) j
  5. #define USART_WakeUp_IdleLine                ((uint16_t)0x0000)6 h5 X+ A( F0 V+ B( }- t& z4 w0 _* @8 l
  6. #define USART_WakeUp_AddressMark             ((uint16_t)0x0800)( r3 J7 Q# R% |( z# z
  7. #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \- O! C- A( A% u- {- a/ r# L
  8.                                  ((WAKEUP) == USART_WakeUp_AddressMark))
复制代码

/ F) C8 N0 C. w: p5 T0 \/ N$ FUSART_LIN_Break_Detection_Length
  1. /** @defgroup USART_LIN_Break_Detection_Length + [/ E5 J% E% E5 U: A0 M) H( h
  2.   * @{
    8 q; v0 m  r0 M6 Z3 X
  3.   */+ D1 \% l& S/ i0 Z

  4. / H' ?" W2 ?4 S. o; k3 C9 E
  5. #define USART_LINBreakDetectLength_10b      ((uint16_t)0x0000)( a; @! t3 _' Z/ d. a) B. @0 r
  6. #define USART_LINBreakDetectLength_11b      ((uint16_t)0x0020)) ?! M* B4 ?2 k( E3 ^
  7. #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \
    . D2 R" p3 c- \$ [+ A1 A
  8.                                (((LENGTH) == USART_LINBreakDetectLength_10b) || \6 \4 d/ ]  Y1 ?+ @5 ]5 v
  9.                                 ((LENGTH) == USART_LINBreakDetectLength_11b))
复制代码

, m6 {4 A5 {, @  g" [9 _& Y; sUSART_IrDA_Low_Power
2 e/ z6 s, ]/ q: U1 P
5 g" f& ]. e9 L
  1. /** @defgroup USART_IrDA_Low_Power
    2 g8 e' u* u$ ~: y& ?5 J; j8 F
  2.   * @{
    & C& M$ c; w& v+ S
  3.   */
    + ?% Z8 s8 k, d! E( c' j
  4. 1 o  |2 u- B# B* L, p- z
  5. #define USART_IrDAMode_LowPower              ((uint16_t)0x0004)
    4 o, ]- l) X* S3 x. Y7 ^
  6. #define USART_IrDAMode_Normal                ((uint16_t)0x0000)! `  }, A4 ^: }- O
  7. #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \; \7 k; v7 N( f2 w5 }) T4 {3 x( d
  8.                                   ((MODE) == USART_IrDAMode_Normal))
复制代码

: B, `% u( C- x! M# L  p; T. V# D0 KUSART_Flags" |& _3 A. y5 _

- W& Z( n. j$ [+ L- ^* ]3 X! i! U& P
  1. /** @defgroup USART_Flags
    ' `* a6 j6 q( k  A* B6 x7 d
  2.   * @{, e! X' c( m- ^. d
  3.   */
    ! `6 ~$ m  g8 w6 D. c

  4. ) n6 U+ h. ^3 _. K8 v: [$ l
  5. #define USART_FLAG_CTS                       ((uint16_t)0x0200)
    $ e0 L7 H  J% ]: p& Z
  6. #define USART_FLAG_LBD                       ((uint16_t)0x0100)
    " O& J8 Z: l, ^! P0 n
  7. #define USART_FLAG_TXE                       ((uint16_t)0x0080), l9 \( r5 ?+ G& D
  8. #define USART_FLAG_TC                        ((uint16_t)0x0040), b/ A7 V3 t* @" F9 e/ M
  9. #define USART_FLAG_RXNE                      ((uint16_t)0x0020)3 l1 i3 u- l* b0 F
  10. #define USART_FLAG_IDLE                      ((uint16_t)0x0010)! m+ y& ~6 X& y1 m
  11. #define USART_FLAG_ORE                       ((uint16_t)0x0008)
    - P- [* p9 C+ V+ H* V' f* X- Q
  12. #define USART_FLAG_NE                        ((uint16_t)0x0004)
    ' P( U* o2 N) N; {1 n
  13. #define USART_FLAG_FE                        ((uint16_t)0x0002)3 c+ `; [' T, B4 ^6 [& S
  14. #define USART_FLAG_PE                        ((uint16_t)0x0001)/ s3 j  ^" q: m+ |- K' s
  15. #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \* N$ F& q+ l5 b  r9 _0 C7 H
  16.                              ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \
    " e  B% H9 z6 F4 b. p
  17.                              ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \1 z2 n% @+ m. ]5 \( m
  18.                              ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \+ a. J4 B& ?9 e$ E$ E$ Q* F8 A
  19.                              ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE))
    7 L. [6 E& [- J9 U

  20. + h% A; A, ~3 q% y8 S
  21. #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00))5 X( W$ Q- i2 @" L
  22. : c9 x! i  Y& n% y: c7 A
  23. #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 7500001))% n9 n6 y. k5 B6 a+ D% e
  24. #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)( i1 z& m* x' |
  25. #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF)
复制代码
6 M& G/ k+ M# p; E1 I  t# @1 C$ }
03. USART相关其它宏7 C, `+ M: C' n0 K1 u7 m$ t
USART_TypeDef, z9 d! ~3 P5 L1 c8 K/ }

' y  k: l) E' N8 Y& f. @) u
  1. /**
    , J( C; R8 f1 c
  2.   * @brief Universal Synchronous Asynchronous Receiver Transmitter
      k, t7 H" z! E0 c0 _9 _  l
  3.   */- v# C( w9 g' z

  4. 5 H) S- w" z; r: ?: p
  5. typedef struct
    1 f8 a1 ?1 O& b* C' U
  6. {/ g/ _3 v/ _  k) e. c% Z4 u
  7.   __IO uint16_t SR;         /*!< USART Status register,                   Address offset: 0x00 */6 T9 b8 c8 V( I  x9 ]) l6 G7 c
  8.   uint16_t      RESERVED0;  /*!< Reserved, 0x02                                                */
    6 D' @% S: G( y4 _
  9.   __IO uint16_t DR;         /*!< USART Data register,                     Address offset: 0x04 */5 Y$ x! h0 E& P4 W4 g
  10.   uint16_t      RESERVED1;  /*!< Reserved, 0x06                                                */' M; I- Z& L5 _* V$ U6 _2 F
  11.   __IO uint16_t BRR;        /*!< USART Baud rate register,                Address offset: 0x08 */
    # {4 ^6 I! n; I" x% O8 B+ v
  12.   uint16_t      RESERVED2;  /*!< Reserved, 0x0A                                                */$ T1 Z+ _* W: ~3 g9 S. i
  13.   __IO uint16_t CR1;        /*!< USART Control register 1,                Address offset: 0x0C */
    6 s/ h2 C2 ^6 T  a" m# y' T, J% a
  14.   uint16_t      RESERVED3;  /*!< Reserved, 0x0E                                                */
    ' Z$ u1 j$ a( ~5 f- Y
  15.   __IO uint16_t CR2;        /*!< USART Control register 2,                Address offset: 0x10 */
    $ N: `) s! W' P, t& j
  16.   uint16_t      RESERVED4;  /*!< Reserved, 0x12                                                */1 Q! U5 T/ \% q7 Z( {
  17.   __IO uint16_t CR3;        /*!< USART Control register 3,                Address offset: 0x14 */4 b3 O  z  m1 b$ E! u
  18.   uint16_t      RESERVED5;  /*!< Reserved, 0x16                                                */
    ' Q, D6 q8 }- q* Y9 D2 W6 e. t9 L; r/ C
  19.   __IO uint16_t GTPR;       /*!< USART Guard time and prescaler register, Address offset: 0x18 */
    4 c) X2 B+ k. o, d6 e
  20.   uint16_t      RESERVED6;  /*!< Reserved, 0x1A                                                */
    $ c- z: X( h0 |7 B4 K
  21. } USART_TypeDef;
复制代码
  1. /******************************************************************************/
      I; i; @& o+ F0 y* E$ V% }
  2. /*                                                                            */8 L. _# f4 J; I5 f4 j' Y: |8 ~
  3. /*         Universal Synchronous Asynchronous Receiver Transmitter            */8 I& @' E6 d, E- ]4 `
  4. /*                                                                            */6 F: `! ]3 y3 I9 y# U; l. f7 R
  5. /******************************************************************************/
    ; N: n  i& B/ F2 t2 L, Q0 _) ?
  6. /*******************  Bit definition for USART_SR register  *******************/6 r5 O6 g3 u$ R# k9 Q4 }
  7. #define  USART_SR_PE                         ((uint16_t)0x0001)            /*!<Parity Error                 */! v1 y( V7 g0 W5 D
  8. #define  USART_SR_FE                         ((uint16_t)0x0002)            /*!<Framing Error                */, B" @# E/ ?7 G( S* J" w
  9. #define  USART_SR_NE                         ((uint16_t)0x0004)            /*!<Noise Error Flag             */1 a) v5 p1 U/ R% L# \$ t
  10. #define  USART_SR_ORE                        ((uint16_t)0x0008)            /*!<OverRun Error                */
    1 {" L* O. m- N8 f# S1 l2 ^
  11. #define  USART_SR_IDLE                       ((uint16_t)0x0010)            /*!<IDLE line detected           */; q0 O) m: }. X4 v. J. z7 h$ T; a
  12. #define  USART_SR_RXNE                       ((uint16_t)0x0020)            /*!<Read Data Register Not Empty */5 F% ?2 X  p" B, m* r# Y. d
  13. #define  USART_SR_TC                         ((uint16_t)0x0040)            /*!<Transmission Complete        */% ]( _. t% m. R8 @
  14. #define  USART_SR_TXE                        ((uint16_t)0x0080)            /*!<Transmit Data Register Empty */$ b& l# s5 z+ X+ n; p: i
  15. #define  USART_SR_LBD                        ((uint16_t)0x0100)            /*!<LIN Break Detection Flag     */
    : M8 ]; D( }/ Q# T( F- ]+ q" r
  16. #define  USART_SR_CTS                        ((uint16_t)0x0200)            /*!<CTS Flag                     */
    : ^0 w  i0 i1 g) T% ?

  17. ! c/ C, W. _" H( [+ v: Z9 i
  18. /*******************  Bit definition for USART_DR register  *******************/5 e( _. _) `. g
  19. #define  USART_DR_DR                         ((uint16_t)0x01FF)            /*!<Data value */
    0 W7 J. K# e) Z( B4 R2 ^
  20. 9 i4 T7 K# b( U# X0 g2 i7 X; P
  21. /******************  Bit definition for USART_BRR register  *******************/$ r  j9 M. Z: D( P$ Y
  22. #define  USART_BRR_DIV_Fraction              ((uint16_t)0x000F)            /*!<Fraction of USARTDIV */9 q. h' S% Y8 V* s- ~! K+ L
  23. #define  USART_BRR_DIV_Mantissa              ((uint16_t)0xFFF0)            /*!<Mantissa of USARTDIV */
    3 S, [8 Z" c* N* ~. p& v
  24. / S  H. {& F+ W( i' @
  25. /******************  Bit definition for USART_CR1 register  *******************/: S% }6 l0 _# M
  26. #define  USART_CR1_SBK                       ((uint16_t)0x0001)            /*!<Send Break                             */
    ; F! `7 _# l# k5 ^" Z. d# D6 R  m
  27. #define  USART_CR1_RWU                       ((uint16_t)0x0002)            /*!<Receiver wakeup                        */
    # \8 Y7 {1 h& V$ N5 n- _
  28. #define  USART_CR1_RE                        ((uint16_t)0x0004)            /*!<Receiver Enable                        */
    % d3 ^1 u. H8 d& Y8 y$ y9 m
  29. #define  USART_CR1_TE                        ((uint16_t)0x0008)            /*!<Transmitter Enable                     */6 c( S- v" q+ f7 W. \. Z" O
  30. #define  USART_CR1_IDLEIE                    ((uint16_t)0x0010)            /*!<IDLE Interrupt Enable                  */4 J/ B' S7 s/ _1 k4 u/ ~
  31. #define  USART_CR1_RXNEIE                    ((uint16_t)0x0020)            /*!<RXNE Interrupt Enable                  */
    6 D1 m3 `# Y/ m
  32. #define  USART_CR1_TCIE                      ((uint16_t)0x0040)            /*!<Transmission Complete Interrupt Enable */, \+ g8 ~, J* G% L' w
  33. #define  USART_CR1_TXEIE                     ((uint16_t)0x0080)            /*!<PE Interrupt Enable                    */5 q* E; `1 v/ z
  34. #define  USART_CR1_PEIE                      ((uint16_t)0x0100)            /*!<PE Interrupt Enable                    */
    * P7 h: `5 }7 q2 X
  35. #define  USART_CR1_PS                        ((uint16_t)0x0200)            /*!<Parity Selection                       */' h7 M2 x3 H: H3 |" P1 U
  36. #define  USART_CR1_PCE                       ((uint16_t)0x0400)            /*!<Parity Control Enable                  */8 N0 `+ I- l* N4 e
  37. #define  USART_CR1_WAKE                      ((uint16_t)0x0800)            /*!<Wakeup method                          */
    ' H# G9 w/ x" K( b
  38. #define  USART_CR1_M                         ((uint16_t)0x1000)            /*!<Word length                            */- F, H1 R# |6 v7 F2 F
  39. #define  USART_CR1_UE                        ((uint16_t)0x2000)            /*!<USART Enable                           */
    4 W. N, \. ?2 k! B) w
  40. #define  USART_CR1_OVER8                     ((uint16_t)0x8000)            /*!<USART Oversampling by 8 enable         */
    ; h2 V, |: e; D6 }. u  K
  41.   T7 Z4 X. f1 D' c4 K
  42. /******************  Bit definition for USART_CR2 register  *******************/
    6 z) @7 q( K+ S
  43. #define  USART_CR2_ADD                       ((uint16_t)0x000F)            /*!<Address of the USART node            */+ f' [* u9 Z$ H& @) X8 R- O
  44. #define  USART_CR2_LBDL                      ((uint16_t)0x0020)            /*!<LIN Break Detection Length           */3 I$ C" C+ U; S5 m" f2 K4 P) H. `
  45. #define  USART_CR2_LBDIE                     ((uint16_t)0x0040)            /*!<LIN Break Detection Interrupt Enable */7 h. h) l7 E8 r; O5 @6 N2 Z+ }
  46. #define  USART_CR2_LBCL                      ((uint16_t)0x0100)            /*!<Last Bit Clock pulse                 */& F2 y  R, w2 E" o+ a
  47. #define  USART_CR2_CPHA                      ((uint16_t)0x0200)            /*!<Clock Phase                          */5 u, y: c, ?1 B9 A8 j6 \
  48. #define  USART_CR2_CPOL                      ((uint16_t)0x0400)            /*!<Clock Polarity                       */! T* z- r* D! v& f9 \- a0 P7 f
  49. #define  USART_CR2_CLKEN                     ((uint16_t)0x0800)            /*!<Clock Enable                         */. T" _5 k: S- r8 A5 T3 Y

  50. 9 g' n8 J' \& s6 E5 ~, W  K0 v
  51. #define  USART_CR2_STOP                      ((uint16_t)0x3000)            /*!<STOP[1:0] bits (STOP bits) */+ A( G" s' g$ D& b
  52. #define  USART_CR2_STOP_0                    ((uint16_t)0x1000)            /*!<Bit 0 */
    2 N2 N- d3 _1 X9 r8 p+ Z" ^) E% N
  53. #define  USART_CR2_STOP_1                    ((uint16_t)0x2000)            /*!<Bit 1 */
    % |0 D7 l- @0 B* f0 L1 \: {8 e+ p

  54. 4 N4 a% ]7 R" ^7 z0 V% V% U4 @+ ^
  55. #define  USART_CR2_LINEN                     ((uint16_t)0x4000)            /*!<LIN mode enable */: c* R  d" k5 b- |  `0 |3 Q

  56.   t8 S$ \5 M6 Z* |* g( T7 B/ q
  57. /******************  Bit definition for USART_CR3 register  *******************/
    7 K' o& f; t' p% s% C
  58. #define  USART_CR3_EIE                       ((uint16_t)0x0001)            /*!<Error Interrupt Enable      */' ^# Y! ^5 x4 a
  59. #define  USART_CR3_IREN                      ((uint16_t)0x0002)            /*!<IrDA mode Enable            */
    , v% q: i9 B- R
  60. #define  USART_CR3_IRLP                      ((uint16_t)0x0004)            /*!<IrDA Low-Power              */
    7 ]! F- W' T* F
  61. #define  USART_CR3_HDSEL                     ((uint16_t)0x0008)            /*!<Half-Duplex Selection       */
    0 I# l/ z- f4 \( G) Q( r/ K4 c5 W) k. B
  62. #define  USART_CR3_NACK                      ((uint16_t)0x0010)            /*!<Smartcard NACK enable       */- T& q( j0 y: F" N: _" Q
  63. #define  USART_CR3_SCEN                      ((uint16_t)0x0020)            /*!<Smartcard mode enable       */4 E# k& w! s$ C! P8 _$ \1 ^
  64. #define  USART_CR3_DMAR                      ((uint16_t)0x0040)            /*!<DMA Enable Receiver         */! V0 w, L% [- c2 c
  65. #define  USART_CR3_DMAT                      ((uint16_t)0x0080)            /*!<DMA Enable Transmitter      */  ?5 U2 h9 L& G  _
  66. #define  USART_CR3_RTSE                      ((uint16_t)0x0100)            /*!<RTS Enable                  */! }4 G, [- p9 G: K6 ?
  67. #define  USART_CR3_CTSE                      ((uint16_t)0x0200)            /*!<CTS Enable                  */9 j  M4 P3 x9 b8 \  z3 z, X
  68. #define  USART_CR3_CTSIE                     ((uint16_t)0x0400)            /*!<CTS Interrupt Enable        */1 o: r, M1 ^7 O$ ]# q/ \3 L, Z; l
  69. #define  USART_CR3_ONEBIT                    ((uint16_t)0x0800)            /*!<USART One bit method enable */  M1 W# Q  @9 u" k$ G) ~* n

  70. 1 a" k/ m+ b- l
  71. /******************  Bit definition for USART_GTPR register  ******************/
    9 U% c5 \! ^5 G' W
  72. #define  USART_GTPR_PSC                      ((uint16_t)0x00FF)            /*!<PSC[7:0] bits (Prescaler value) */9 M$ J& b, J6 {$ ], M0 |2 }3 r# Y
  73. #define  USART_GTPR_PSC_0                    ((uint16_t)0x0001)            /*!<Bit 0 */% s+ K( ]$ ^9 n
  74. #define  USART_GTPR_PSC_1                    ((uint16_t)0x0002)            /*!<Bit 1 */
    * I* M! R6 C- o, Q
  75. #define  USART_GTPR_PSC_2                    ((uint16_t)0x0004)            /*!<Bit 2 */3 K# z# z+ \0 O: Z. B4 L' Z$ u
  76. #define  USART_GTPR_PSC_3                    ((uint16_t)0x0008)            /*!<Bit 3 */2 V& ^7 t0 s: }' |: A& \. _& {+ r
  77. #define  USART_GTPR_PSC_4                    ((uint16_t)0x0010)            /*!<Bit 4 */
    # b! {: R3 b# W" K. c8 [+ E/ M  I
  78. #define  USART_GTPR_PSC_5                    ((uint16_t)0x0020)            /*!<Bit 5 */+ }* U. Y7 M/ y' m6 b0 f* I
  79. #define  USART_GTPR_PSC_6                    ((uint16_t)0x0040)            /*!<Bit 6 */% C+ ]7 d. \! {$ X* Q0 S; g
  80. #define  USART_GTPR_PSC_7                    ((uint16_t)0x0080)            /*!<Bit 7 */+ A# ?* G* q: N: [; l1 r1 I
  81. 3 q8 `4 Y. H' ~. R6 P8 x8 h
  82. #define  USART_GTPR_GT                       ((uint16_t)0xFF00)            /*!<Guard time value */
复制代码
5 q  _& F: g/ T0 t  z5 \7 {% c
04. USART相关函数0 L6 U* m' M$ }
  1. /*  Function used to set the USART configuration to the default reset state ***/ 5 `3 G& \7 [- M! n) N  {' t
  2. void USART_DeInit(USART_TypeDef* USARTx);
    9 p! G, o5 Q; ^7 ?/ S! ^9 |9 s
  3. ; G& n' H/ K$ K- n
  4. /* Initialization and Configuration functions *********************************/$ ~$ U9 `# l9 ]# A  ]3 d
  5. void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);
      x. t! m9 ~' |
  6. void USART_StructInit(USART_InitTypeDef* USART_InitStruct);+ E; e4 W& U6 U/ I) D) z1 z# \5 w
  7. void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct);# @! O; `) Y5 I6 C
  8. void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct);9 |% @( ^4 |; K- L7 T
  9. void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState);1 b& H; `: o" t/ e  w" \
  10. void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler);5 y! G' R1 k0 u) \" K$ X
  11. void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
    ( |1 E3 m5 H! f! e# d# L
  12. void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState);
    1 Z5 S9 z  K: J8 o% z( h8 m# O. Q
  13. : d5 U: @) i; }
  14. /* Data transfers functions ***************************************************/
    0 t- R. J8 y9 ~5 y# j$ A% }6 x
  15. void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);: n" H# u, O" v1 z! \8 `* t
  16. uint16_t USART_ReceiveData(USART_TypeDef* USARTx);
    + W! _# c0 J0 g! ]8 S; U* E

  17. - K- V6 T( _2 M2 Y
  18. /* Multi-Processor Communication functions ************************************/% f; J! Q6 G% Y
  19. void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address);
    " ^- x7 l4 j/ n3 ~  ~* V+ J
  20. void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp);. }+ L; o/ u5 K
  21. void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState);3 e" r: j" Y  g

  22. & R7 ?/ Y  E3 x8 ^. M
  23. /* LIN mode functions *********************************************************/
    $ f0 l# D6 o! ?* k
  24. void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength);
    . m; K( R& d0 ^1 Q# m
  25. void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState);* ?; D1 S+ w" B+ {) y2 m8 D
  26. void USART_SendBreak(USART_TypeDef* USARTx);" K9 Q4 V8 m& l, W

  27. & B+ u5 @, l7 f; O
  28. /* Half-duplex mode function **************************************************/
    # X* M0 u2 Q) J, z( E8 R
  29. void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState);
      j, B5 u: J( |! ~8 o! Y+ h  A) Z

  30.   c7 D6 E3 h9 ?
  31. /* Smartcard mode functions ***************************************************/4 }6 V& A2 R, B3 S/ w9 h' w8 m
  32. void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState);+ f1 C, O" c/ J
  33. void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState);
    + ?* @2 o; S8 O) @4 x' ~; d
  34. void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime);
    1 H2 U# Q  q4 B, e! g
  35. 0 h: a+ o3 [+ e2 q
  36. /* IrDA mode functions ********************************************************/8 {* [( ]8 \; o- f2 G' f& V
  37. void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode);
    " k7 u; E) F% f; v
  38. void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState);
    9 D! c9 R: j, B

  39.   _" j% r; B9 o7 V- U: ^
  40. /* DMA transfers management functions *****************************************/2 v* p$ A  X+ M  s
  41. void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);
    7 j* c0 ^& W6 u' ~6 ?

  42. ; v6 h  O! ?' r" y
  43. /* Interrupts and flags management functions **********************************/3 L/ t, I7 ]8 C% X: C% k3 E
  44. void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);
    7 r, S7 s& V7 Q# R: t) E; i2 a
  45. FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);- E* {% I5 B/ \. ^* T$ F- H
  46. void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG);- D' B  G6 C9 h. L2 Y! o8 ?
  47. ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);! ?1 z7 P4 y% P$ F8 W& S0 N
  48. void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);
复制代码
9 l3 N% v/ j4 V4 M8 \/ M
05. USART其它3 _, }7 Z) w& j
USART基地址
, V, m% u4 L1 e: p8 z5 N9 E/ ~
2 P/ h) K4 G2 g; I6 o0 Q
  1. #define USART2_BASE           (APB1PERIPH_BASE + 0x4400)
    / c" s, Z) w( u  `: a
  2. #define USART3_BASE           (APB1PERIPH_BASE + 0x4800)
      ]% M, E' x; p6 V$ D5 Y+ }1 w
  3. #define UART4_BASE            (APB1PERIPH_BASE + 0x4C00)( i, j& j( L. C6 f. X/ E
  4. #define UART5_BASE            (APB1PERIPH_BASE + 0x5000). g' B/ M+ @2 C8 B: r
  5. * C+ e" `1 z* B2 \
  6. #define USART1_BASE           (APB2PERIPH_BASE + 0x1000): G' f7 P( m" y- Z. H
  7. #define USART6_BASE           (APB2PERIPH_BASE + 0x1400)2 q1 w: |; i5 |
  8. #define UART9_BASE            (APB2PERIPH_BASE + 0x1800U)
    1 l8 l" n5 p) c9 ~1 C# s9 B
  9. #define UART10_BASE           (APB2PERIPH_BASE + 0x1C00U)
复制代码

6 y' c9 W% G9 @1 T& `0 N3 r% j8 s" J) \6 J& x3 \& J
赞 收藏 评论0 发布时间:2022-6-13 08:56

举报

0个回答

所属标签

相似技术帖

官网相关资源

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