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

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

[复制链接]
STMCU小助手 发布时间:2022-4-2 21:00
01. USART固件库概述3 B3 X/ N! q2 F. ]9 B
stm32f4xx_usart.h 函数的声明和类型的声明
7 ~( K% G1 F: _4 p9 V/ J
: f! K/ m" R, d( G7 istm32f4xx_usart.c 函数的实现
% Y+ R+ f+ `, J- }2 e' N0 n/ o; R% J
02. USART相关类型- s; m/ R1 h! C4 e
stm32f4xx_usart.h文件中& o- S, c" P9 y' P  O

, K( a# I/ W% s, a/ k# [USART_InitTypeDef类型% n" `; ~+ c- E% F7 i! W
- E" f& q& ~9 W

  1. $ i+ r* z. U; x* n8 d5 s. o% X
  2. /**
    ' p, p. J# P4 H6 e
  3.   * @brief  USART Init Structure definition  
    + b  J) @7 b! o( _" z
  4.   */ : e% ~  `' T: x( b9 h0 l

  5. 7 [, i* y4 M  p" ?
  6. typedef struct8 ]: ^  Q; h3 k9 D  d
  7. {8 |6 r5 |/ G, J9 M( }! Z- R, y
  8.   uint32_t USART_BaudRate;            /*!< This member configures the USART communication baud rate./ d. M4 ~; o/ u6 ]' |
  9.                                            The baud rate is computed using the following formula:* \. T1 o4 W6 |) {: l
  10.                                             - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (USART_InitStruct->USART_BaudRate)))1 J# `; \, j2 K9 W
  11.                                             - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 8 * (OVR8+1)) + 0.5 - @) T) o$ B" r9 e( E
  12.                                            Where OVR8 is the "oversampling by 8 mode" configuration bit in the CR1 register. */0 S1 G) X) Q8 f. @5 n( @
  13. $ H( v5 y4 ]) h" Z& \" V
  14.   uint16_t USART_WordLength;          /*!< Specifies the number of data bits transmitted or received in a frame.
    5 T" ]0 w4 N9 O
  15.                                            This parameter can be a value of @ref USART_Word_Length */
    $ u4 [3 b. ?  c4 t2 W1 a
  16. # Q$ Q& t) T% v( p) k
  17.   uint16_t USART_StopBits;            /*!< Specifies the number of stop bits transmitted.
    ! X9 q/ v7 A3 @5 S, i
  18.                                            This parameter can be a value of @ref USART_Stop_Bits *// l+ E8 m/ G4 n  j" A5 D
  19. + A) {6 L1 U* i8 }" z* v% t. G
  20.   uint16_t USART_Parity;              /*!< Specifies the parity mode./ ?; _7 B+ {+ p5 }  P* @
  21.                                            This parameter can be a value of @ref USART_Parity
    # g  _/ K% y! X: l! J1 ~' E
  22.                                            @note When parity is enabled, the computed parity is inserted) y- s" J3 S( I3 ]; f/ n
  23.                                                  at the MSB position of the transmitted data (9th bit when
    : t1 L& n4 ~+ G6 m9 R
  24.                                                  the word length is set to 9 data bits; 8th bit when the
    / p( ]; T: u; p: e1 y/ x. k* O
  25.                                                  word length is set to 8 data bits). */
    ) s' M. @% ^* V9 K

  26. & y& y$ J* ~7 E/ V
  27.   uint16_t USART_Mode;                /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.4 b0 v$ K# V# g4 \" s2 i* x
  28.                                            This parameter can be a value of @ref USART_Mode */$ l8 L2 O% G" S* ^' {) _; [/ N
  29. $ |0 b) j5 ]' m. o
  30.   uint16_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled% i" T: \1 D! J! w; T6 [9 x. K
  31.                                            or disabled.8 N; I  v, C' k
  32.                                            This parameter can be a value of @ref USART_Hardware_Flow_Control */
    5 W' _& b$ L9 H
  33. } USART_InitTypeDef;
    : a8 |+ s0 e+ d$ X1 b
复制代码

+ G# L5 o% d9 i* LUSART_ClockInitTypeDef类型0 D0 C, l$ B/ S: c, k8 x* u2 z

( `9 `9 A5 g4 U3 B
  1. /** 8 E* E/ k& a* O+ V5 ~& z
  2.   * @brief  USART Clock Init Structure definition  
    ! q& t4 l; e) o! M  f* ~9 m) n" k: C
  3.   */ 8 U! l# D# h' n
  4.   d" i+ B& o6 ?4 T
  5. typedef struct
    % _/ ]1 N* a# A* V' X7 Q
  6. {
    / \: a5 j3 X/ O$ ]# y
  7. * B- N. n# |% d
  8.   uint16_t USART_Clock;   /*!< Specifies whether the USART clock is enabled or disabled.
    & Y; J, ^5 T% X2 `1 v# D
  9.                                This parameter can be a value of @ref USART_Clock */, ^& q7 `; h' H3 m

  10. 7 V. n' n& R. S
  11.   uint16_t USART_CPOL;    /*!< Specifies the steady state of the serial clock.: Y  T6 I8 w/ |7 C' G
  12.                                This parameter can be a value of @ref USART_Clock_Polarity */, Y* _5 c, k  `) T/ `$ A( X6 R

  13. ( B% ?2 \- H* q0 o0 c  t- N8 ?$ M1 Q- r: ]
  14.   uint16_t USART_CPHA;    /*!< Specifies the clock transition on which the bit capture is made.
    - @) F3 e/ L. N3 e( t
  15.                                This parameter can be a value of @ref USART_Clock_Phase */9 H& E" |+ S& |( m, q  |/ s
  16. 5 P* u7 r) J% D3 v# K: Q  U# ?
  17.   uint16_t USART_LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted) x; }$ J' X+ w/ a2 s+ A
  18.                                data bit (MSB) has to be output on the SCLK pin in synchronous mode.
    8 Y4 ~7 I8 q( J9 T# _; ~  i: L. c
  19.                                This parameter can be a value of @ref USART_Last_Bit */
    6 c, T' j# ^& g7 {* R( ?; s
  20. } USART_ClockInitTypeDef;
复制代码
% T! E1 H$ B* F' o
USART外设
2 z$ R8 d7 |  _; L9 }. l  u
/ `& F1 Y3 A( W3 J) A3 v
  1. /** @defgroup USART_Exported_Constants
    8 H! f+ L6 y; u. Y5 d( O' K
  2.   * @{, q0 k0 @3 z# |8 `& _
  3.   */
    . ?+ X6 u+ K4 m- p, S% X
  4. ( `  p/ l' {8 h- B" u: @
  5. #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \' [9 q  g2 x! }- s1 y: Q6 G
  6.                                      ((PERIPH) == USART2) || \, ^+ Y7 }3 A7 B) A" E7 Z
  7.                                      ((PERIPH) == USART3) || \
    0 e# |- l8 {6 D; J- z9 v5 ^  m
  8.                                      ((PERIPH) == UART4)  || \5 H4 P1 D: |( o7 {
  9.                                      ((PERIPH) == UART5)  || \
    & M  m; ?7 J3 e0 p  _
  10.                                      ((PERIPH) == USART6) || \* ]) ?  s8 s& P$ Q
  11.                                      ((PERIPH) == UART7)  || \
    & H: A( A+ q" P* b2 _, L5 B4 ]
  12.                                      ((PERIPH) == UART8)  || \
    1 g$ [) V7 G) U3 _
  13.                                      ((PERIPH) == UART9)  || \
    + h9 ?4 L3 b6 ], p
  14.                                      ((PERIPH) == UART10))
    % r* E; H4 r8 R5 B6 ?$ [

  15.   r3 q2 {- ~' S
  16. #define IS_USART_1236_PERIPH(PERIPH) (((PERIPH) == USART1) || \
    2 L% W! w) [$ m2 D3 O+ U8 G5 |
  17.                                       ((PERIPH) == USART2) || \
    3 a: d$ s7 Q5 j: M# j! t& _
  18.                                       ((PERIPH) == USART3) || \2 x: n: `' L) K! m% @. c* j
  19.                                       ((PERIPH) == USART6))8 S: P8 s8 O% u, w
复制代码

8 C' [8 e6 d6 |" J- q0 aUSART_Word_Length) \2 L( h4 |( Q. z. G. m$ [
7 x! H) r. X5 A& {8 W& A" V  a

  1. : v3 m5 _6 ^; G4 B. i6 {
  2. /** @defgroup USART_Word_Length
    % ~9 z7 w: V2 a2 n. l0 X2 \
  3.   * @{# l" N' k: _. n) U/ S: Z0 H
  4.   */ + V* P3 V8 V' Y4 q# {! {

  5. 3 B$ u$ j! T, t- D9 }
  6. #define USART_WordLength_8b                  ((uint16_t)0x0000)
    # V/ K1 T$ C& q* D: l" X
  7. #define USART_WordLength_9b                  ((uint16_t)0x1000)8 K5 c! W4 y5 ^
  8. $ j# [  s, h5 i1 x
  9. #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \
    , b# H) [# H( D7 b5 m$ B: w, A
  10.                                       ((LENGTH) == USART_WordLength_9b))
复制代码
& U' f( L- F0 l: Q
USART_Stop_Bits7 u* p3 p8 e# v3 m6 _% _* a5 i8 U

6 W- D6 s8 o3 o
  1. /** @defgroup USART_Stop_Bits
    # F1 P5 |* M5 S0 b! `1 u$ o
  2.   * @{
    , G1 p% d* D* Y. o- t& U( H
  3.   */
    ; ~8 c! v2 Z2 p/ f- X; F
  4. ' s& J8 Y: [4 e4 Q, _+ h
  5. #define USART_StopBits_1                     ((uint16_t)0x0000), u5 J4 g$ [& F  _& U) l- A4 E& c0 u
  6. #define USART_StopBits_0_5                   ((uint16_t)0x1000)( H+ U* i4 V4 K- U4 B5 z( _
  7. #define USART_StopBits_2                     ((uint16_t)0x2000). q/ X& \) }2 h2 h8 S6 _# _( v3 f
  8. #define USART_StopBits_1_5                   ((uint16_t)0x3000)9 L3 d5 N( b2 w9 ^. |0 d; ?
  9. #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \
    5 ?3 {' ?3 h4 R7 {
  10.                                      ((STOPBITS) == USART_StopBits_0_5) || \
    # P1 l# Q$ T; X0 r$ S' a! ^
  11.                                      ((STOPBITS) == USART_StopBits_2) || \/ ?5 p4 U8 S4 `
  12.                                      ((STOPBITS) == USART_StopBits_1_5))9 Z3 p: o0 t; A& \" ~
复制代码

' o* J, x% F4 J8 R) F4 lUSART_Parity

  c' }- E* ?: z$ a) ^* U6 w2 Q: O! T, A, ^& m1 r+ n
  1. /** @defgroup USART_Parity 5 ~/ s% e8 {% J" }) n
  2.   * @{6 I1 S7 x6 w" r0 x0 f
  3.   */
    , y7 C; H4 Q7 z6 |  Y2 v. I
  4. : h1 u+ ~. G% q* {' A5 e7 {6 {
  5. #define USART_Parity_No                      ((uint16_t)0x0000)
    $ r1 [. }. c# w2 p5 u) @( d  A
  6. #define USART_Parity_Even                    ((uint16_t)0x0400)
    ! \, u; Q6 E" z" s; ?! ?' `4 U* c
  7. #define USART_Parity_Odd                     ((uint16_t)0x0600)
    - Q% L% g6 {& e: S
  8. #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \3 G4 V% |! K; M) L3 ]; l
  9.                                  ((PARITY) == USART_Parity_Even) || \3 G& f# W8 A! w
  10.                                  ((PARITY) == USART_Parity_Odd))
复制代码
& {7 ~( y3 F7 Z6 I4 Q
USART_Mode
  1. /** @defgroup USART_Mode
    . p$ K. F& s+ s. P
  2.   * @{4 O" T1 E* a" t1 L9 N
  3.   */
    + F) q, P' X8 q5 N+ C, ?( O7 }8 j

  4. 9 M" \7 @2 h8 O; H, N) B
  5. #define USART_Mode_Rx                        ((uint16_t)0x0004)3 [  m' |3 ~, V8 Y+ b
  6. #define USART_Mode_Tx                        ((uint16_t)0x0008)0 |' A9 y) `, c9 b& t6 r7 k
  7. #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00))
复制代码

+ k* \" f  e/ @- E" |USART_Hardware_Flow_Control
3 C9 r8 f7 L0 k; S5 ~( @  s
. F- z" }/ G' h8 e2 u" z4 o/ Y" u
  1. /** @defgroup USART_Hardware_Flow_Control ' S& N# G5 e; |
  2.   * @{
    % n$ `% Q, O( J+ h
  3.   */
    4 C. {% g& w; ^( g0 F7 v
  4. #define USART_HardwareFlowControl_None       ((uint16_t)0x0000)1 S6 ^' M& O2 s# Z9 H1 `
  5. #define USART_HardwareFlowControl_RTS        ((uint16_t)0x0100)% _, E! J$ d3 g( b# ~
  6. #define USART_HardwareFlowControl_CTS        ((uint16_t)0x0200)
    2 M/ l8 W( |( ?6 C  u# ~0 k% B
  7. #define USART_HardwareFlowControl_RTS_CTS    ((uint16_t)0x0300)
    3 m5 q1 C5 [8 ~. d
  8. #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\
    5 Y, ?; ?# T# Y- U6 z
  9.                               (((CONTROL) == USART_HardwareFlowControl_None) || \
    8 H- X) u1 {" K
  10.                                ((CONTROL) == USART_HardwareFlowControl_RTS) || \
    0 V2 v3 i3 A. t4 F- H1 W, }
  11.                                ((CONTROL) == USART_HardwareFlowControl_CTS) || \/ x/ ~5 N& q* m+ I
  12.                                ((CONTROL) == USART_HardwareFlowControl_RTS_CTS))
复制代码

! B* ^9 T( [) Q5 b6 ?USART_Clock
  1. /** @defgroup USART_Clock & s" u3 J7 E, R' _6 J1 H) b
  2.   * @{
    % \0 d5 `! E+ C/ v
  3.   */
    " s" j& t2 T  j& m% D2 @
  4. #define USART_Clock_Disable                  ((uint16_t)0x0000); I7 \4 J6 h; Y# \/ P, A8 @
  5. #define USART_Clock_Enable                   ((uint16_t)0x0800)4 y. j% b( I7 S3 o( z
  6. #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \
    1 X! A% d! d; Q' ?$ I7 O
  7.                                ((CLOCK) == USART_Clock_Enable))
复制代码
! o$ o7 e: p" R; I, d$ W
USART_Clock_Polarity
* e! i4 Q0 ~/ @  j( U# E) o. @8 v1 _$ G. \2 S7 ]* [9 T
  1. ' T% A) S9 `, p
  2. /** @defgroup USART_Clock_Polarity
    1 t) ?7 b' F8 X8 I/ A
  3.   * @{
    8 C4 ^" o/ o3 M% f
  4.   */3 b7 s$ n* N1 }5 E# {4 \8 z
  5. ! x  C3 D0 u$ F
  6. #define USART_CPOL_Low                       ((uint16_t)0x0000)! w2 v" x( d& o8 K  o, `
  7. #define USART_CPOL_High                      ((uint16_t)0x0400)
    ; K1 `. i2 q' o6 r- A
  8. #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High))/ `/ T5 W/ a- w3 `# b7 g& O
复制代码

& V( d7 p1 N& d: K" |8 x; zUSART_Clock_Phase  u2 ?) Q/ x# |) O& a/ ]
& T) r6 w- {+ D) p- h
  1. /** @defgroup USART_Clock_Phase
    $ m6 @: m! q* E' y& b
  2.   * @{& h: d( v) y# v( {* K
  3.   */$ g! [( K% l- |1 C6 V& |8 w+ ~

  4. " b4 q5 r' n: m- A) R) D  M1 Z
  5. #define USART_CPHA_1Edge                     ((uint16_t)0x0000)4 M. h! }2 B7 Q( ?' p
  6. #define USART_CPHA_2Edge                     ((uint16_t)0x0200)
    1 G& a+ y2 K; N8 G
  7. #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge))
复制代码

( T+ E1 x( S% TUSART_Last_Bit8 @& I3 i$ S+ l4 Z" X
. P  ?% H& D! Y3 T1 @: w
  1. /** @defgroup USART_Last_Bit
    1 _: @+ |" E0 l. V5 B5 {1 {. F7 _: S
  2.   * @{
    ' Y9 i" s6 a" L
  3.   */1 C8 {. b+ h7 x' f

  4. ! W5 J. H; ]( q4 c
  5. #define USART_LastBit_Disable                ((uint16_t)0x0000)
    7 C% ~/ l9 e5 v: n, W
  6. #define USART_LastBit_Enable                 ((uint16_t)0x0100)
    6 [; e1 o9 |0 ^1 C
  7. #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \
    - Z$ x9 x9 E/ M. @2 o- ]
  8.                                    ((LASTBIT) == USART_LastBit_Enable))
复制代码

0 m8 Z) q  P! A$ hUSART_Interrupt_definition
7 c; m1 R& s) ~3 s+ v7 S7 c
" M. q2 `, ^9 _+ l& {; X
  1. /** @defgroup USART_Interrupt_definition
    & p3 E$ M* L. ~1 i# v6 K* c
  2.   * @{$ v! ]/ ]) Z- \
  3.   */1 T8 I$ \: ?* R; j2 `
  4. # ~+ i0 U" u/ K5 Y/ H% x
  5. #define USART_IT_PE                          ((uint16_t)0x0028)
    6 |+ R0 h* a* n- S
  6. #define USART_IT_TXE                         ((uint16_t)0x0727)
    * _2 \3 ~5 Z$ N" l7 r! d' V# C
  7. #define USART_IT_TC                          ((uint16_t)0x0626): t- j, Y6 |6 d* e
  8. #define USART_IT_RXNE                        ((uint16_t)0x0525)
    ( q2 S/ y1 v0 J9 Z& M
  9. #define USART_IT_ORE_RX                      ((uint16_t)0x0325) /* In case interrupt is generated if the RXNEIE bit is set */4 C% K8 I  d# {) Q
  10. #define USART_IT_IDLE                        ((uint16_t)0x0424)- Q. K9 }' z; p/ ~$ r
  11. #define USART_IT_LBD                         ((uint16_t)0x0846)' F. S' r8 N2 _8 P1 m# E7 ?
  12. #define USART_IT_CTS                         ((uint16_t)0x096A)
    * I; ~% z& S! K; x6 d1 w
  13. #define USART_IT_ERR                         ((uint16_t)0x0060)$ |; {$ Y. Y  H! L
  14. #define USART_IT_ORE_ER                      ((uint16_t)0x0360) /* In case interrupt is generated if the EIE bit is set */
    + u; ~5 A0 _8 J2 n0 H
  15. #define USART_IT_NE                          ((uint16_t)0x0260)
    0 S- w( |' T: ]& p
  16. #define USART_IT_FE                          ((uint16_t)0x0160)
复制代码
  1. #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
    # G% R7 M. p6 r  `
  2.                                 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \" j' N- [6 ^6 [$ L) r- E
  3.                                 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
    " R6 L( U+ b4 C# q
  4.                                 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR))
    ) z* }) M; H$ N' e: S9 N. D
  5. #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
    % [* T; |+ F7 f6 f; R+ Y2 O
  6.                              ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
    . `; n6 u7 A8 {( n5 O) L3 d
  7.                              ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \3 p; }* M' O5 X- s+ M. i
  8.                              ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \" f" s+ G3 m7 v; l6 i
  9.                              ((IT) == USART_IT_ORE_RX) || ((IT) == USART_IT_ORE_ER) || \2 k1 S2 r! Q/ J1 ]* j, c9 I1 p
  10.                              ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE))
    4 k+ f: n; V. }
  11. #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \8 U( \8 d6 K- H; L, G5 u0 y
  12.                                ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS))
复制代码

! J* }0 Z" w8 w; s* D9 m* iUSART_DMA_Requests
! Q1 I% D( J3 I' g% ]. j
7 _2 E. H5 \3 u4 z$ p) N
  1. /** @defgroup USART_DMA_Requests
    , W$ n6 o. n7 r8 [9 X; G2 v; K1 B
  2.   * @{
    ) F1 v5 M+ E- @! i% c
  3.   */
    ) q" \" K( h7 n* o; `' d% J  |

  4. 0 I. U. K/ ^: |! V" H7 C
  5. #define USART_DMAReq_Tx                      ((uint16_t)0x0080)* h8 z# b7 [9 q% [, R; P& v: I
  6. #define USART_DMAReq_Rx                      ((uint16_t)0x0040)' X6 ~; n" D. _$ y4 J1 t
  7. #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00))
复制代码
$ _* d5 i- I( t
USART_WakeUp_methods
  1. /** @defgroup USART_WakeUp_methods
    ' Q+ g; \9 l) c& E
  2.   * @{
    # C. ]$ {* c; H" O7 Y+ t, {
  3.   */
    - k7 i/ }6 ]: t, B! h6 e" j
  4.   C* a) t& `! M3 {/ a
  5. #define USART_WakeUp_IdleLine                ((uint16_t)0x0000): w; _6 N4 S* G8 O
  6. #define USART_WakeUp_AddressMark             ((uint16_t)0x0800)4 Z$ O; q3 n( k% x& M) ]
  7. #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \2 z: O3 R: M, \7 z3 x
  8.                                  ((WAKEUP) == USART_WakeUp_AddressMark))
复制代码
- v0 {9 n+ F! e) d. W. V
USART_LIN_Break_Detection_Length
  1. /** @defgroup USART_LIN_Break_Detection_Length
    $ n% w4 b* v& ^, n% p( k
  2.   * @{
    ( ]  Y* |' Z8 i+ t) O
  3.   */1 l! _% m$ k9 |% K  E: o/ J

  4. * X7 @5 ~, |; L+ {. ^; k; N9 }
  5. #define USART_LINBreakDetectLength_10b      ((uint16_t)0x0000)4 t. \1 m& i3 C' G. ?3 G5 ]
  6. #define USART_LINBreakDetectLength_11b      ((uint16_t)0x0020)
    , Y2 p- |' W  o) M5 R6 A1 w
  7. #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \
    + \( _1 X. q8 }- m1 @
  8.                                (((LENGTH) == USART_LINBreakDetectLength_10b) || \4 k( W" ^+ v7 G7 [1 K+ g1 C
  9.                                 ((LENGTH) == USART_LINBreakDetectLength_11b))
    # t% ]1 e* ~* ^# C% k" q0 a. e! `
复制代码
5 |0 Y& c& ]2 y7 {" i
USART_IrDA_Low_Power

2 @# u' G. Z, P3 N7 Z# o
0 _6 ]* `/ m# Q7 Y4 Y7 K* V
  1. /** @defgroup USART_IrDA_Low_Power 2 z% h+ b! Y; ~* Z9 o
  2.   * @{" v: G1 b# R8 m: i
  3.   */
    , o7 n( y! g: E; \  X
  4. ' H! z" n0 m3 F$ g- V# d
  5. #define USART_IrDAMode_LowPower              ((uint16_t)0x0004)
      }; H! f4 I0 z7 c* L% f: z
  6. #define USART_IrDAMode_Normal                ((uint16_t)0x0000)+ ?9 s6 C; \; T0 s& `
  7. #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \" E: b% V; R/ ^
  8.                                   ((MODE) == USART_IrDAMode_Normal))
复制代码

5 G: Q, }- C' g* _+ H  g# dUSART_Flags
( o6 ~5 d$ ~4 a1 T% q5 \7 ^9 i! r* O1 [5 @: u) i
  1. /** @defgroup USART_Flags 2 E% ^- F2 Z/ |- @+ p: e; w
  2.   * @{
    ) d- A( }. q0 ?1 @  J
  3.   */' K4 [5 x3 g( r

  4. / x3 f, n7 e/ W- g
  5. #define USART_FLAG_CTS                       ((uint16_t)0x0200)
    - n0 }0 P, x/ j5 r5 j) o
  6. #define USART_FLAG_LBD                       ((uint16_t)0x0100)' O9 c5 g0 T& [0 h& R3 B
  7. #define USART_FLAG_TXE                       ((uint16_t)0x0080)8 s) `0 L8 A9 O, W- ]4 {
  8. #define USART_FLAG_TC                        ((uint16_t)0x0040)  j' d' E5 d. l" g" g
  9. #define USART_FLAG_RXNE                      ((uint16_t)0x0020)
    ) {! {8 ^. i3 b! K' @0 Y
  10. #define USART_FLAG_IDLE                      ((uint16_t)0x0010)
    9 I: q# y& |# ?4 s% f
  11. #define USART_FLAG_ORE                       ((uint16_t)0x0008). W8 M( C4 H$ `: C
  12. #define USART_FLAG_NE                        ((uint16_t)0x0004)2 @; p( [: X( C: ?
  13. #define USART_FLAG_FE                        ((uint16_t)0x0002)
    # ?% {. }( p' Q. s" p
  14. #define USART_FLAG_PE                        ((uint16_t)0x0001)
    % D  h- \/ Y. a
  15. #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \
    - C! J3 L, x! X7 \' v% F$ H
  16.                              ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \- I& X- n. s$ R. Y  d6 y, x
  17.                              ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \+ D) d! H3 c# F" W9 |# h
  18.                              ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \
    + F  B/ t; ?+ l8 a- C4 ^9 V
  19.                              ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE))
    & t3 k' y- j% e& s$ h! y0 @
  20. 9 A# D( W% ^  K
  21. #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00))& P( v1 E; U3 G5 N; n. n+ B0 s
  22. 9 E: H* a, A$ R; G. O. `
  23. #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 7500001))  F& j2 q+ m" c3 [6 g9 ~
  24. #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)
    * u0 C; l4 K' k! u8 Y) G
  25. #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF)
复制代码
( Q! ^* L6 N: F  h
03. USART相关其它宏3 ~+ Z" B/ s( {/ S) ?
USART_TypeDef

6 Q. v& l% ^2 o4 J- B
7 F; k7 }1 g4 L6 b  ]1 M2 U+ i
  1. /** 9 t5 }* }5 `' M* B7 l# z7 w% K: |" I+ X
  2.   * @brief Universal Synchronous Asynchronous Receiver Transmitter
    ' T! B9 D) T" _0 l
  3.   */
    , L6 B& y: }, Q. _" X! R$ W& E
  4. 4 F( ~6 l; D- u+ w8 P
  5. typedef struct9 S: D- m& z; n
  6. {
    ( P" Y% @7 n0 R. h" F" W
  7.   __IO uint16_t SR;         /*!< USART Status register,                   Address offset: 0x00 */  I2 L/ \0 p$ l1 ]2 i+ X8 J
  8.   uint16_t      RESERVED0;  /*!< Reserved, 0x02                                                */# ]8 u3 P, L4 V) L5 @7 c! y
  9.   __IO uint16_t DR;         /*!< USART Data register,                     Address offset: 0x04 */- c+ ]0 p" z+ \5 s; k7 A% U1 W
  10.   uint16_t      RESERVED1;  /*!< Reserved, 0x06                                                */
    1 j0 E' @! Y0 @* w. ~3 i
  11.   __IO uint16_t BRR;        /*!< USART Baud rate register,                Address offset: 0x08 */$ H8 r0 {7 I# v" H" [6 e- g
  12.   uint16_t      RESERVED2;  /*!< Reserved, 0x0A                                                */  F, z0 s1 C2 p
  13.   __IO uint16_t CR1;        /*!< USART Control register 1,                Address offset: 0x0C */# P- u6 L$ E; i$ Z
  14.   uint16_t      RESERVED3;  /*!< Reserved, 0x0E                                                */
    # t6 }# Q4 f- l& q! O0 d
  15.   __IO uint16_t CR2;        /*!< USART Control register 2,                Address offset: 0x10 */
    $ J+ A$ w! b- ^( ^
  16.   uint16_t      RESERVED4;  /*!< Reserved, 0x12                                                */
    ( z" V- t: w; D9 f
  17.   __IO uint16_t CR3;        /*!< USART Control register 3,                Address offset: 0x14 */
    + p9 |& m6 t3 P8 s/ K) U5 f
  18.   uint16_t      RESERVED5;  /*!< Reserved, 0x16                                                */: O! I" V# ]! M9 N3 N! f
  19.   __IO uint16_t GTPR;       /*!< USART Guard time and prescaler register, Address offset: 0x18 */( i) x+ T0 r: K0 d
  20.   uint16_t      RESERVED6;  /*!< Reserved, 0x1A                                                */% `% @6 v+ \* |: a! q
  21. } USART_TypeDef;
    ) L- H) @. k# D! v9 T
复制代码
  1. /******************************************************************************/' {; w7 P) f( F% @8 K. m8 A% O
  2. /*                                                                            */
    : w% |8 }% N* `- b+ \
  3. /*         Universal Synchronous Asynchronous Receiver Transmitter            */, ~: Q  b( _6 h. z) S. @
  4. /*                                                                            */
    5 _) X8 z" ^# T2 X
  5. /******************************************************************************/
    - l' Z8 L4 H; a
  6. /*******************  Bit definition for USART_SR register  *******************/& a* L+ \; `0 l( _* p
  7. #define  USART_SR_PE                         ((uint16_t)0x0001)            /*!<Parity Error                 */7 Q! J; f' k# U% k) A! Q9 e
  8. #define  USART_SR_FE                         ((uint16_t)0x0002)            /*!<Framing Error                */
    $ x: ~. k: L- [, ]7 g; j3 s/ R% E" x
  9. #define  USART_SR_NE                         ((uint16_t)0x0004)            /*!<Noise Error Flag             */
    ! y: o3 R$ l- W! W! R
  10. #define  USART_SR_ORE                        ((uint16_t)0x0008)            /*!<OverRun Error                */" x# s6 b6 Y% v# c+ r
  11. #define  USART_SR_IDLE                       ((uint16_t)0x0010)            /*!<IDLE line detected           */( @! j7 A" S" k! [
  12. #define  USART_SR_RXNE                       ((uint16_t)0x0020)            /*!<Read Data Register Not Empty */
    8 }" }' `/ x- R8 L
  13. #define  USART_SR_TC                         ((uint16_t)0x0040)            /*!<Transmission Complete        */9 `1 D1 m& b2 T4 e5 v% e: m) K' @; C2 [
  14. #define  USART_SR_TXE                        ((uint16_t)0x0080)            /*!<Transmit Data Register Empty */
    * g% j! B% j" \* s2 d; R
  15. #define  USART_SR_LBD                        ((uint16_t)0x0100)            /*!<LIN Break Detection Flag     */
    + q- `6 B/ @+ R1 u4 a
  16. #define  USART_SR_CTS                        ((uint16_t)0x0200)            /*!<CTS Flag                     */
    8 X6 y4 W" Y8 `( r! y
  17. 3 `; z  \% B, y$ V: ]; W2 ?
  18. /*******************  Bit definition for USART_DR register  *******************/
    ) c! N7 x- @5 s" u& u7 A  ~% R
  19. #define  USART_DR_DR                         ((uint16_t)0x01FF)            /*!<Data value */' Y* J* ?0 m! g

  20. , ]! k. l7 |0 C9 _( ]& E$ n
  21. /******************  Bit definition for USART_BRR register  *******************/: H0 F5 v$ j1 m1 S
  22. #define  USART_BRR_DIV_Fraction              ((uint16_t)0x000F)            /*!<Fraction of USARTDIV */0 m% W' V! h$ [; ~6 C
  23. #define  USART_BRR_DIV_Mantissa              ((uint16_t)0xFFF0)            /*!<Mantissa of USARTDIV */
    & f: F# P$ }( k% W) ?6 t6 m

  24. 2 S, x- z  X) ?+ A! k2 l
  25. /******************  Bit definition for USART_CR1 register  *******************/+ e+ j) o, h  C, c! [4 w+ {
  26. #define  USART_CR1_SBK                       ((uint16_t)0x0001)            /*!<Send Break                             */4 J) P; Z  n( x( ], i1 _
  27. #define  USART_CR1_RWU                       ((uint16_t)0x0002)            /*!<Receiver wakeup                        */
    ; X' Y0 ^! G: V
  28. #define  USART_CR1_RE                        ((uint16_t)0x0004)            /*!<Receiver Enable                        */
    : _. L- _3 @2 c* f# a
  29. #define  USART_CR1_TE                        ((uint16_t)0x0008)            /*!<Transmitter Enable                     */- y5 A. n1 G" c, z1 B: D6 h, b
  30. #define  USART_CR1_IDLEIE                    ((uint16_t)0x0010)            /*!<IDLE Interrupt Enable                  */% M: ^) h8 Z* ]2 f
  31. #define  USART_CR1_RXNEIE                    ((uint16_t)0x0020)            /*!<RXNE Interrupt Enable                  */
    6 S: {4 l* U. ]: {
  32. #define  USART_CR1_TCIE                      ((uint16_t)0x0040)            /*!<Transmission Complete Interrupt Enable */
    9 h) x" r% _' u2 R& e; M8 C
  33. #define  USART_CR1_TXEIE                     ((uint16_t)0x0080)            /*!<PE Interrupt Enable                    */
    % N# g7 Q9 A! _# i$ r& Q* i0 K
  34. #define  USART_CR1_PEIE                      ((uint16_t)0x0100)            /*!<PE Interrupt Enable                    */! y7 ~6 E$ I7 B% C& g6 S
  35. #define  USART_CR1_PS                        ((uint16_t)0x0200)            /*!<Parity Selection                       */6 O! }9 r0 i& p$ q! D
  36. #define  USART_CR1_PCE                       ((uint16_t)0x0400)            /*!<Parity Control Enable                  */
    5 Y' K3 b. p0 Y4 A) F1 K/ B
  37. #define  USART_CR1_WAKE                      ((uint16_t)0x0800)            /*!<Wakeup method                          */
    + n( I( E* X, y+ ]" b
  38. #define  USART_CR1_M                         ((uint16_t)0x1000)            /*!<Word length                            */
    $ ~) w" e0 T6 s3 S& G; `
  39. #define  USART_CR1_UE                        ((uint16_t)0x2000)            /*!<USART Enable                           */
    ! F1 w; i2 b: J/ X
  40. #define  USART_CR1_OVER8                     ((uint16_t)0x8000)            /*!<USART Oversampling by 8 enable         */% q5 `" m' f  q: _# f

  41. ; |1 O+ `) w0 v. }6 \
  42. /******************  Bit definition for USART_CR2 register  *******************/
    * s; t, t8 t$ z* C; H
  43. #define  USART_CR2_ADD                       ((uint16_t)0x000F)            /*!<Address of the USART node            */
    2 w, m' [  P' \+ ^) J: }( S
  44. #define  USART_CR2_LBDL                      ((uint16_t)0x0020)            /*!<LIN Break Detection Length           */
    * G; l1 V+ S3 c! T6 S# d4 Y$ W
  45. #define  USART_CR2_LBDIE                     ((uint16_t)0x0040)            /*!<LIN Break Detection Interrupt Enable */2 Z1 p: ]6 ^6 q$ j
  46. #define  USART_CR2_LBCL                      ((uint16_t)0x0100)            /*!<Last Bit Clock pulse                 */( m6 g3 z) ?9 Q# w' ~
  47. #define  USART_CR2_CPHA                      ((uint16_t)0x0200)            /*!<Clock Phase                          */7 e& W! O2 M0 Q- V9 ^* ~3 a. h- d
  48. #define  USART_CR2_CPOL                      ((uint16_t)0x0400)            /*!<Clock Polarity                       */
    0 p7 f( u) \5 F
  49. #define  USART_CR2_CLKEN                     ((uint16_t)0x0800)            /*!<Clock Enable                         */
    7 J1 F4 d8 {& f( _

  50. 3 F4 t7 q' D7 i3 I% R
  51. #define  USART_CR2_STOP                      ((uint16_t)0x3000)            /*!<STOP[1:0] bits (STOP bits) */
    : x/ J- Z( M7 D! K
  52. #define  USART_CR2_STOP_0                    ((uint16_t)0x1000)            /*!<Bit 0 */( s' X7 [/ }2 D7 q2 Z
  53. #define  USART_CR2_STOP_1                    ((uint16_t)0x2000)            /*!<Bit 1 */
    9 I3 m% R* [" Y; p' \- N+ R8 M% o

  54. * ]9 L7 Y6 y3 K; R
  55. #define  USART_CR2_LINEN                     ((uint16_t)0x4000)            /*!<LIN mode enable */
    # F: Z' B/ E* D5 W& Z9 L6 i

  56. & ?9 I3 \5 {+ n8 |& Y: j0 h% T, @
  57. /******************  Bit definition for USART_CR3 register  *******************/
    - Z) v0 x+ ^. T/ O6 r
  58. #define  USART_CR3_EIE                       ((uint16_t)0x0001)            /*!<Error Interrupt Enable      */
      e( p6 q" K: n6 S+ i( J+ X
  59. #define  USART_CR3_IREN                      ((uint16_t)0x0002)            /*!<IrDA mode Enable            */1 A0 K. g2 Z: ]/ v) V
  60. #define  USART_CR3_IRLP                      ((uint16_t)0x0004)            /*!<IrDA Low-Power              */  b" L8 ]% \% R- x3 ]
  61. #define  USART_CR3_HDSEL                     ((uint16_t)0x0008)            /*!<Half-Duplex Selection       */
    8 [) C- U/ s) C* |) |4 k8 {
  62. #define  USART_CR3_NACK                      ((uint16_t)0x0010)            /*!<Smartcard NACK enable       */" n7 \3 ^, f0 K( T7 ^) j: [; R
  63. #define  USART_CR3_SCEN                      ((uint16_t)0x0020)            /*!<Smartcard mode enable       */( {" A; M0 R( n0 I+ P1 D
  64. #define  USART_CR3_DMAR                      ((uint16_t)0x0040)            /*!<DMA Enable Receiver         */5 S" S/ U. ]+ \0 o( Z( i
  65. #define  USART_CR3_DMAT                      ((uint16_t)0x0080)            /*!<DMA Enable Transmitter      */
    7 d: E/ u: Y  m# d; B& R, P, g- x/ L
  66. #define  USART_CR3_RTSE                      ((uint16_t)0x0100)            /*!<RTS Enable                  */$ M" @/ O( w4 w) b
  67. #define  USART_CR3_CTSE                      ((uint16_t)0x0200)            /*!<CTS Enable                  */' T) F# k1 q" P, Q
  68. #define  USART_CR3_CTSIE                     ((uint16_t)0x0400)            /*!<CTS Interrupt Enable        */
    $ b  C3 _! m% c" x* U
  69. #define  USART_CR3_ONEBIT                    ((uint16_t)0x0800)            /*!<USART One bit method enable */. P0 c! g( F9 q
  70. 2 ]* [5 {" d2 N5 u/ {
  71. /******************  Bit definition for USART_GTPR register  ******************/
    ( T' `* {1 P2 s( P# j
  72. #define  USART_GTPR_PSC                      ((uint16_t)0x00FF)            /*!<PSC[7:0] bits (Prescaler value) */: u) U7 H% p7 F
  73. #define  USART_GTPR_PSC_0                    ((uint16_t)0x0001)            /*!<Bit 0 *// C6 R& o+ {8 J5 |
  74. #define  USART_GTPR_PSC_1                    ((uint16_t)0x0002)            /*!<Bit 1 */
    " U* J# c) b( U4 ?& E% R% Z7 s
  75. #define  USART_GTPR_PSC_2                    ((uint16_t)0x0004)            /*!<Bit 2 */( ?- P& M) j# r0 e$ Q
  76. #define  USART_GTPR_PSC_3                    ((uint16_t)0x0008)            /*!<Bit 3 */
    - w$ t& ^9 {+ A; Q, ^
  77. #define  USART_GTPR_PSC_4                    ((uint16_t)0x0010)            /*!<Bit 4 */
    5 e7 K; z( k! c! R- ^
  78. #define  USART_GTPR_PSC_5                    ((uint16_t)0x0020)            /*!<Bit 5 *// y4 p# P) L2 b
  79. #define  USART_GTPR_PSC_6                    ((uint16_t)0x0040)            /*!<Bit 6 */
    : ~2 @5 D6 E" b) [9 `& g. P
  80. #define  USART_GTPR_PSC_7                    ((uint16_t)0x0080)            /*!<Bit 7 */" a7 k* T2 w& D$ I7 N
  81. : {/ |, B) Y) U  l+ Q
  82. #define  USART_GTPR_GT                       ((uint16_t)0xFF00)            /*!<Guard time value */
复制代码
) x- K, M9 I) d
04. USART相关函数
6 H2 U$ ?1 f- ?* g& {& m
  1. /*  Function used to set the USART configuration to the default reset state ***/
    ( @+ r; ^% R7 G
  2. void USART_DeInit(USART_TypeDef* USARTx);8 f: i  \, N6 o0 m- F% c: Z1 `" O

  3. % I7 d; v- G4 ^& I8 ]0 C! I
  4. /* Initialization and Configuration functions *********************************/
    % e' g( b1 A. u- |3 F
  5. void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);
    # C: L* ?; }7 b
  6. void USART_StructInit(USART_InitTypeDef* USART_InitStruct);! h- o, {# }3 ?- [
  7. void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct);" E7 N7 u- J( d# s4 v: W! M
  8. void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct);8 k; o5 {4 u( k4 H
  9. void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
    & Z8 ~/ Y+ U( }4 d1 l7 R( E/ u
  10. void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler);+ y! C" b* j$ R' d
  11. void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
    ' {8 _% m4 t8 U! h- X" W- v+ H
  12. void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState);
    " j' Q% P8 j' i' D2 g4 \: G

  13. 8 W) G' l& c/ C& a6 J. v: E9 q
  14. /* Data transfers functions ***************************************************/
    % `$ y! l5 ~& b( `* h/ U! x7 `, e2 D
  15. void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);
    ; E, |) [7 G( K  j0 a1 m( w
  16. uint16_t USART_ReceiveData(USART_TypeDef* USARTx);- e1 z* D. w/ ?

  17. ' V% r/ X# S" b# ]6 ]+ g$ t0 t
  18. /* Multi-Processor Communication functions ************************************/( O8 K# L0 v6 \( y% E
  19. void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address);, Z, V% t  B0 m5 ^
  20. void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp);
    ; v3 Q$ S/ U, I4 ]  Q( j; s, S
  21. void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState);* J! V, O9 e  m2 S: W: V

  22. & u: R+ e& f+ w" q; p; j
  23. /* LIN mode functions *********************************************************/
    & I/ H2 ?( E  P( R& Z% `
  24. void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength);
      Q$ V3 I) v4 l& L5 m* y* N
  25. void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState);
      K. s' f1 ^; A( S+ w8 \) T# [
  26. void USART_SendBreak(USART_TypeDef* USARTx);
    * x: y& k# l% Q
  27. $ [2 Q1 o; }9 c6 A* u* P: j
  28. /* Half-duplex mode function **************************************************/# u9 t* e" [+ G6 ~# s2 T
  29. void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState);
    ! @: Y( R. x# M% _3 a  \, E

  30. 7 S6 Q6 t( {: V
  31. /* Smartcard mode functions ***************************************************/
    ' W: }- A  z8 n- `1 t- v6 @/ C3 b
  32. void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState);' d+ A3 ], L( q
  33. void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState);; D) ~$ M. ]& d7 Q; ^7 G
  34. void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime);) Y: {1 S9 G$ u$ Q6 b$ w7 j
  35. / t" {- f; t& L- D! L( t( \
  36. /* IrDA mode functions ********************************************************/
    & J9 W  S( E# c
  37. void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode);5 \) Q# L7 Z( r8 l1 X2 \, [& L3 O
  38. void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState);! t! F( h6 ?( B7 b0 ]$ Z3 Q' t$ K( K

  39. / D2 n/ g) o9 r
  40. /* DMA transfers management functions *****************************************/9 V$ k1 X0 f/ |, ]! [8 x) W
  41. void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);
    5 q* x8 p1 @8 ~
  42. 1 R1 l( a( E4 v7 g) F1 B
  43. /* Interrupts and flags management functions **********************************/
    2 f" h2 @; |+ N- B% ^
  44. void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);
    4 K! H2 \: M" S* Y6 C" W
  45. FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);
    ! h4 O& X& G' E
  46. void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG);
    9 r; l  ]- F& N3 Q2 E0 r' }+ z) L
  47. ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);# t2 P5 P1 P6 v7 C" p& x8 m) t+ e
  48. void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);* z; `& ?, |4 W& V
复制代码
9 m! P/ l; f  V! s; e1 x  ^5 l& k: U
05. USART其它
5 p7 u* S0 E% o" M, FUSART基地址

0 ?6 x  x5 \& z) d* l9 X% G0 T# I) Z6 E% d: X4 l
  1. #define USART2_BASE           (APB1PERIPH_BASE + 0x4400)* N2 M: n" f6 w7 O: N4 V; u4 h
  2. #define USART3_BASE           (APB1PERIPH_BASE + 0x4800): g- b9 L! k- c: `- }' r. ]" x
  3. #define UART4_BASE            (APB1PERIPH_BASE + 0x4C00)+ c) @2 M- F* S! S
  4. #define UART5_BASE            (APB1PERIPH_BASE + 0x5000)
      s% x3 |0 L; ?" z6 t2 H  o+ C) ?

  5. , D* u* Y! e7 e& r3 [' A9 h
  6. #define USART1_BASE           (APB2PERIPH_BASE + 0x1000)6 g* c3 K7 `# o: i- {; o7 E
  7. #define USART6_BASE           (APB2PERIPH_BASE + 0x1400)6 W% [- z7 J1 A5 w/ s) H5 H
  8. #define UART9_BASE            (APB2PERIPH_BASE + 0x1800U)
    ( c4 L. x% Q, z% J6 c# q
  9. #define UART10_BASE           (APB2PERIPH_BASE + 0x1C00U)
复制代码
: \% q6 `9 U) ?4 ~( @

, W% L5 M  Q" u) X) q
8 p) Z! a  Q1 ~/ D/ }9 y. n
赞 收藏 评论0 发布时间:2022-4-2 21:00

举报

0个回答

所属标签

相似技术帖

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