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

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

[复制链接]
STMCU小助手 发布时间:2022-4-2 21:00
01. USART固件库概述
+ \3 C: x4 P: I4 s3 I4 Pstm32f4xx_usart.h 函数的声明和类型的声明8 g% A4 u4 h9 J
0 n; P0 j. R% m! ^! R
stm32f4xx_usart.c 函数的实现2 ?& X0 B' C/ x8 T' F1 X$ A
! L7 A' O  F: E- ^1 v: b
02. USART相关类型
6 s+ X. C5 A# C" @stm32f4xx_usart.h文件中
1 }! ^8 b. r3 A$ p' h) a, t* f0 h' z1 k" |$ ~& w
USART_InitTypeDef类型& \; D) ~  e: G  B

4 K& H6 J6 Y5 Y- o$ g

  1. 8 U. E, m  a. \5 L( F' V* W4 c
  2. /**
    4 s+ L  l! a/ }4 N! A9 u3 G* q
  3.   * @brief  USART Init Structure definition  
    % U* a" }# T0 I  H
  4.   */ 0 F1 k8 F% T4 }
  5. + g1 o8 y, L. ?, I; I; r4 E
  6. typedef struct
    & Z2 e/ C' p3 I8 Z" T2 {
  7. {
    & b- ?9 ]3 T) n5 ^; X4 k/ T# l
  8.   uint32_t USART_BaudRate;            /*!< This member configures the USART communication baud rate.' ~' h4 d: Q4 x# W
  9.                                            The baud rate is computed using the following formula:
    * }# G; b6 o) a! ^3 L$ a7 f3 i0 R
  10.                                             - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (USART_InitStruct->USART_BaudRate)))
    % R, C( x- _3 D
  11.                                             - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 8 * (OVR8+1)) + 0.5 3 ^4 q- G1 T6 }8 N" J) j7 B
  12.                                            Where OVR8 is the "oversampling by 8 mode" configuration bit in the CR1 register. */
    3 f7 K% W/ }0 h; k+ [: N, {# m6 K2 ~
  13. + j. P- S7 g$ v
  14.   uint16_t USART_WordLength;          /*!< Specifies the number of data bits transmitted or received in a frame., P8 s2 W1 f( b* _( s4 N
  15.                                            This parameter can be a value of @ref USART_Word_Length */) u5 j& ^2 R  O4 N' [! n
  16. # H6 I( g4 l) l, f$ u- r& ]
  17.   uint16_t USART_StopBits;            /*!< Specifies the number of stop bits transmitted.3 l1 b0 B) N; i$ {# z+ ]5 Y- J
  18.                                            This parameter can be a value of @ref USART_Stop_Bits */
    & C- e, X7 U2 Y1 f
  19. % H4 b2 [  B! p+ ]# z" a$ ^
  20.   uint16_t USART_Parity;              /*!< Specifies the parity mode.1 m; z7 c8 r2 y* M
  21.                                            This parameter can be a value of @ref USART_Parity
    ; |: W! m$ k1 `  @
  22.                                            @note When parity is enabled, the computed parity is inserted8 Z: M- y  \, l* }
  23.                                                  at the MSB position of the transmitted data (9th bit when# E( v; {/ e2 p. T' v# m& Y
  24.                                                  the word length is set to 9 data bits; 8th bit when the$ v2 s. f/ [" f
  25.                                                  word length is set to 8 data bits). */) c1 P4 _$ k6 i9 h7 u1 N

  26. . z3 R+ Y( B" `' W% @
  27.   uint16_t USART_Mode;                /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
    , o8 u: h: v. A
  28.                                            This parameter can be a value of @ref USART_Mode */
    1 w' @& [1 I2 E. {, V
  29. 2 o9 W% F' ~, s& J! {  L8 T. K. z
  30.   uint16_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled
    8 f, ?& m2 v. T4 B0 `2 ?# ?
  31.                                            or disabled.
    1 [) j1 @3 W7 @5 v
  32.                                            This parameter can be a value of @ref USART_Hardware_Flow_Control */
    . }$ G. D) ?/ e+ x7 f/ b
  33. } USART_InitTypeDef;
    ! u! k1 m: {; c0 ^
复制代码
6 X% G' y% Q5 J  Y
USART_ClockInitTypeDef类型% N# f( r' _3 V4 [7 b% G* Y. _) T4 Q
6 \3 R. W. @3 g+ ?' G: s% |
  1. /** 5 a+ I$ y1 K  E# Q& ^
  2.   * @brief  USART Clock Init Structure definition  9 `  B( ?+ I2 W
  3.   */ ) P8 D) @; W& b) o* }

  4. # ^3 N( ~" v" A$ i, }8 @
  5. typedef struct
    5 M# F9 J. z! S) l: ^) J- I& i
  6. {9 y0 W5 c' U, Q9 |2 Z  e

  7. $ ~* w* h! f5 Q, E* H: C7 t
  8.   uint16_t USART_Clock;   /*!< Specifies whether the USART clock is enabled or disabled.9 M& ^* y. r/ C+ A; r  t2 q
  9.                                This parameter can be a value of @ref USART_Clock *// |3 @2 d5 `  d% \; g* B) m2 X+ I

  10. 8 ~: @' V3 X* v9 ~0 S4 F
  11.   uint16_t USART_CPOL;    /*!< Specifies the steady state of the serial clock.
    ) u( c0 @7 [/ p0 R* H
  12.                                This parameter can be a value of @ref USART_Clock_Polarity */
    % P3 Z" s' x: h0 j, y1 u
  13.   }# y1 v7 \/ @; X  _0 o
  14.   uint16_t USART_CPHA;    /*!< Specifies the clock transition on which the bit capture is made.
    ( U' Z& |+ Z1 s3 d9 p3 A# q/ s+ W* G
  15.                                This parameter can be a value of @ref USART_Clock_Phase */3 J7 s0 t' c6 k* I1 N7 `# G3 c
  16. 6 ?0 A: k& P5 F! r
  17.   uint16_t USART_LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
    1 D1 l( ~3 B$ C8 P8 E& c6 L4 {* K
  18.                                data bit (MSB) has to be output on the SCLK pin in synchronous mode.+ H/ u+ E- C2 S% v, ^
  19.                                This parameter can be a value of @ref USART_Last_Bit */8 _2 d) o% D2 q% f
  20. } USART_ClockInitTypeDef;
复制代码
, V/ {+ j2 ?2 L0 ~# k) W& }
USART外设% R$ X/ }) I" A" h# F

* {3 w* m) Z; I; y
  1. /** @defgroup USART_Exported_Constants
    : p) H3 h- I+ D/ [5 M
  2.   * @{
    + v  p; V: W8 N& \
  3.   */ , r6 G+ N. C+ S0 `8 \; h3 E

  4. 6 E8 v: v, h  F) y  B1 Y+ T
  5. #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \
    1 F# V: a, @' _
  6.                                      ((PERIPH) == USART2) || \0 L# h/ K3 X8 w% ~* @
  7.                                      ((PERIPH) == USART3) || \/ E' _9 H4 @! N6 A
  8.                                      ((PERIPH) == UART4)  || \
    & Z0 U% ]! ~* |% @9 c
  9.                                      ((PERIPH) == UART5)  || \
    5 }0 W" H+ g7 ~8 s, V$ u, F
  10.                                      ((PERIPH) == USART6) || \% V1 @6 ]6 N4 T' H: }: K# D! d5 {
  11.                                      ((PERIPH) == UART7)  || \, x9 B" q# {* J3 u, N) P; {
  12.                                      ((PERIPH) == UART8)  || \2 K# L% o3 o/ |' H2 B! D
  13.                                      ((PERIPH) == UART9)  || \  @& E$ x* |9 i; H* Y
  14.                                      ((PERIPH) == UART10)) 6 y6 {% h) @# t3 c# M" F* c

  15. 1 @: B9 _' w9 I0 z- e( v/ ]
  16. #define IS_USART_1236_PERIPH(PERIPH) (((PERIPH) == USART1) || \1 K2 q( _$ d! r
  17.                                       ((PERIPH) == USART2) || \* l9 m8 x+ D" v& M! b- p3 S9 s% b
  18.                                       ((PERIPH) == USART3) || \
    0 \, ?5 L$ ~+ h0 M9 S. Y# D
  19.                                       ((PERIPH) == USART6))
    ! l7 d2 b5 _" C! ?, {& n
复制代码

: }1 S% b# h8 ~2 C3 ?% P; l$ x9 @USART_Word_Length
( S( Z0 H3 c& \$ M# n' Z/ z, j: N7 M4 [
  1. 8 D: J# ~" _9 R  R# Z- b+ ~
  2. /** @defgroup USART_Word_Length   Z/ ?5 }  e$ W  ]4 N
  3.   * @{
    4 U1 j3 W" g* g( P
  4.   */ # U5 x- f/ f' g; L$ j

  5. 2 |0 `2 S! \  |2 c" }
  6. #define USART_WordLength_8b                  ((uint16_t)0x0000)
    / B% p- Q* o) n5 V$ Q8 u
  7. #define USART_WordLength_9b                  ((uint16_t)0x1000)$ }1 K' N9 R/ y
  8. ! f8 r$ {3 b+ ^" S! u: E
  9. #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \0 f. H* _6 K# y% p& z. F: W3 t' e
  10.                                       ((LENGTH) == USART_WordLength_9b))
复制代码

: B+ m+ D  ], u$ Y$ iUSART_Stop_Bits( ~- G: y3 [+ i+ o9 H
. o7 d$ q/ r5 H5 y
  1. /** @defgroup USART_Stop_Bits
    4 `5 _7 Y( J% y
  2.   * @{
    + `2 @- [% C1 w6 c, S, k
  3.   */ 8 Y  t7 g6 B$ W" C
  4. & r+ {. \( Q: H! w5 K
  5. #define USART_StopBits_1                     ((uint16_t)0x0000)
    & ^* N# J; q$ U" L. d
  6. #define USART_StopBits_0_5                   ((uint16_t)0x1000)
    ! U5 y& l- t$ m0 Y
  7. #define USART_StopBits_2                     ((uint16_t)0x2000)
    " @( S0 M; z( Q7 N
  8. #define USART_StopBits_1_5                   ((uint16_t)0x3000)
    ' E5 P; r/ l& c/ `! V7 h
  9. #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \
    3 d/ g! j- w' o8 ?
  10.                                      ((STOPBITS) == USART_StopBits_0_5) || \. _$ M6 F, u/ ]: j$ _. e4 q
  11.                                      ((STOPBITS) == USART_StopBits_2) || \
    " K4 c0 g) h6 R0 q: j- k
  12.                                      ((STOPBITS) == USART_StopBits_1_5))+ K1 t3 l" j, |/ I: M6 B
复制代码
; o; X, h5 M( n) S% V
USART_Parity

+ d: A$ |; [! i1 c9 ]- S9 ~, p4 R; A+ i$ H7 I( J6 g
  1. /** @defgroup USART_Parity
    1 P- G" v  D  S9 y9 X6 C
  2.   * @{
    - q/ ^- t- ]- l7 x
  3.   */   u( |  _! i. e9 P) p/ p2 \  R
  4. : j6 ]0 y4 j- g7 T! f& w, U+ M
  5. #define USART_Parity_No                      ((uint16_t)0x0000)" Z2 |2 d* @7 h
  6. #define USART_Parity_Even                    ((uint16_t)0x0400)
    / }- P6 l5 H- A& U; k1 I8 \
  7. #define USART_Parity_Odd                     ((uint16_t)0x0600)
    % b4 L/ Q$ b: c+ Q# D0 A
  8. #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \
    ) a9 F0 z' L1 U
  9.                                  ((PARITY) == USART_Parity_Even) || \
    ! d. K* v/ b1 Z/ @  J9 q
  10.                                  ((PARITY) == USART_Parity_Odd))
复制代码

% O! \3 a1 Y5 t" q" g/ g" M# TUSART_Mode
  1. /** @defgroup USART_Mode
    ! u* N8 ~) P% l7 F( h
  2.   * @{
    ; `. Y9 i' `9 J/ w$ p8 H5 U( c
  3.   */ ) W( ^6 v, _5 D  P

  4. . g, E' L9 f8 ^& R$ S, o  w
  5. #define USART_Mode_Rx                        ((uint16_t)0x0004)
    - C" f8 j7 y8 S7 Z8 i) F# C
  6. #define USART_Mode_Tx                        ((uint16_t)0x0008), u/ |. M3 V" U" L- _
  7. #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00))
复制代码
, f$ v3 t" _0 D# F. `( @
USART_Hardware_Flow_Control

- r2 w0 a& ^9 `
& g* g& z( O) \% e* C( V
  1. /** @defgroup USART_Hardware_Flow_Control : Z7 P! u" z8 U
  2.   * @{
    5 D" U, b8 m2 X# a6 M
  3.   */
    7 L9 [& X6 @7 e
  4. #define USART_HardwareFlowControl_None       ((uint16_t)0x0000)
    : h, n2 y1 H' `1 K  t* p' @
  5. #define USART_HardwareFlowControl_RTS        ((uint16_t)0x0100), q; w. N0 y2 }7 c+ N
  6. #define USART_HardwareFlowControl_CTS        ((uint16_t)0x0200)
    7 g$ X$ h, U: O: B6 X
  7. #define USART_HardwareFlowControl_RTS_CTS    ((uint16_t)0x0300)
    2 _4 L$ G. h* s8 x9 ], c
  8. #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\; x6 H* Z4 F. L& a0 }/ g: ~
  9.                               (((CONTROL) == USART_HardwareFlowControl_None) || \
    1 r" k. x( _7 k( Q" [
  10.                                ((CONTROL) == USART_HardwareFlowControl_RTS) || \
    % v( _  ]7 V  l7 l2 L
  11.                                ((CONTROL) == USART_HardwareFlowControl_CTS) || \
    / P' ^5 L- R, i8 U: `, \3 i
  12.                                ((CONTROL) == USART_HardwareFlowControl_RTS_CTS))
复制代码
3 E" b0 H/ r* |; L
USART_Clock
  1. /** @defgroup USART_Clock 4 b% \2 M2 V5 n$ y2 z6 y: K
  2.   * @{) S+ k9 }5 s) m* n2 u' F
  3.   */ / Y! ~& T# Q5 q$ z) P: d% [
  4. #define USART_Clock_Disable                  ((uint16_t)0x0000): u3 o6 I) o  `* g" n4 i, Z
  5. #define USART_Clock_Enable                   ((uint16_t)0x0800)
    0 P, [# l% D/ G8 u
  6. #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \# \4 b7 {3 ^( l; n9 k
  7.                                ((CLOCK) == USART_Clock_Enable))
复制代码

& S5 d' t8 X9 _0 nUSART_Clock_Polarity) X3 g7 v$ b  S2 o6 B  r: o
: s( M: G) G5 H
  1. " @4 ?1 f6 }( Z$ L* p* l5 {
  2. /** @defgroup USART_Clock_Polarity ( |. [" d! X9 G1 s
  3.   * @{
    7 W. a$ ^, W+ j- J1 a
  4.   */0 J7 W7 i, v8 l9 \4 t2 d# a+ {  M
  5. * g, `; u6 {$ d" a& q+ Z- q
  6. #define USART_CPOL_Low                       ((uint16_t)0x0000). B9 `% ^0 L+ J7 I: p9 A' K$ g
  7. #define USART_CPOL_High                      ((uint16_t)0x0400)
      |8 \  H1 F2 x7 Q2 U
  8. #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High))
      Z% a$ q$ Q3 }! b4 A  x. m
复制代码
( K+ a( h6 t. D0 @+ D/ n
USART_Clock_Phase
! d$ G4 t: l- A5 a0 ], ?) J! G6 [) R. j$ i/ g& Y  {- E
  1. /** @defgroup USART_Clock_Phase9 b# U4 x3 m" `( _
  2.   * @{! J  N' D2 f  y5 s+ Z) N* ]
  3.   */
    5 F* }5 S% o) \% |  J0 W' g* Z, q

  4. ' y! H+ Y/ x# J/ V0 V- Y# Q  t' q
  5. #define USART_CPHA_1Edge                     ((uint16_t)0x0000)
    + ?3 T5 }& @' X# z8 k/ F
  6. #define USART_CPHA_2Edge                     ((uint16_t)0x0200)
    2 ?9 p# N% t4 K4 l1 l" r/ y; C
  7. #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge))
复制代码

$ C( f- c) O. lUSART_Last_Bit
5 D7 [" S9 M2 O4 _* c7 I/ j) s8 ~6 S3 \9 L  g
  1. /** @defgroup USART_Last_Bit9 b3 S* \' K! m  ~6 d3 v
  2.   * @{; N  s) x6 Z$ y) Y3 i8 i
  3.   *// D0 ^2 i  c* q. f8 z
  4. / h/ T6 R% I" [
  5. #define USART_LastBit_Disable                ((uint16_t)0x0000)
    1 a* l/ F: d" Q' d* z- T
  6. #define USART_LastBit_Enable                 ((uint16_t)0x0100)+ W7 p5 ~  m$ }" G
  7. #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \% l# q( |; w& ]' U' S# c* x
  8.                                    ((LASTBIT) == USART_LastBit_Enable))
复制代码

* y$ C* Z; z$ {( F2 G6 M9 |! XUSART_Interrupt_definition
. D" h* E# L) [2 R7 m( Z, o
. ^! i9 b$ W' L, `8 Q
  1. /** @defgroup USART_Interrupt_definition 4 T$ Z9 C2 ]0 l: K
  2.   * @{* A4 {5 v# T2 i2 |" k
  3.   */
    0 _( q5 m; r! F5 D8 X- v
  4. 7 j# N2 i: t. T
  5. #define USART_IT_PE                          ((uint16_t)0x0028)" [) z$ Y4 y, S" Q( ^
  6. #define USART_IT_TXE                         ((uint16_t)0x0727)
    - @& f7 Q2 _1 W. v5 w7 ^
  7. #define USART_IT_TC                          ((uint16_t)0x0626)
    4 j' e3 O' z; f7 a4 e  i
  8. #define USART_IT_RXNE                        ((uint16_t)0x0525)9 l$ m# Q9 ~/ s
  9. #define USART_IT_ORE_RX                      ((uint16_t)0x0325) /* In case interrupt is generated if the RXNEIE bit is set */
    , s& Z) B$ ]2 A: o( ]
  10. #define USART_IT_IDLE                        ((uint16_t)0x0424)
    - @: [/ S& ?8 E2 @
  11. #define USART_IT_LBD                         ((uint16_t)0x0846)  E! _8 P# S4 [9 E* ~& l" Q
  12. #define USART_IT_CTS                         ((uint16_t)0x096A)
    . b4 X! C9 N+ a+ X$ b2 L1 n
  13. #define USART_IT_ERR                         ((uint16_t)0x0060)
    5 h. R+ ^: v3 I. r) v: M
  14. #define USART_IT_ORE_ER                      ((uint16_t)0x0360) /* In case interrupt is generated if the EIE bit is set */- Y& b- ^2 E. V- z7 G( F0 J' \5 z; ~
  15. #define USART_IT_NE                          ((uint16_t)0x0260)
    & p. X0 g7 e( _
  16. #define USART_IT_FE                          ((uint16_t)0x0160)
复制代码
  1. #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \! M# T& U! s, _+ F  @: i
  2.                                 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \4 _2 f/ |' t0 Z6 l
  3.                                 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
    4 l" T8 L# C% k6 _5 i% K
  4.                                 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR))
    3 p5 ^7 Z5 c. ~  f  x" G
  5. #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \' K. Z) B+ t$ k5 w! @
  6.                              ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \8 a2 I* P$ g' E. P2 s2 X+ }
  7.                              ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \4 k4 i/ C' r7 w2 e  j, H
  8.                              ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \
    7 o$ R. S5 C, _
  9.                              ((IT) == USART_IT_ORE_RX) || ((IT) == USART_IT_ORE_ER) || \
    ( _: V8 Y, U9 I
  10.                              ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE))
    , \: {9 t2 o! {# @7 y1 M* P: m
  11. #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
    7 l2 t  ?8 U) R1 }
  12.                                ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS))
复制代码

2 S( a, k. P1 h+ _USART_DMA_Requests
" F; f" g( x8 ~8 g! _2 q+ J' \- r
9 N( p% \& _0 Z% B+ Y% V
  1. /** @defgroup USART_DMA_Requests
    / |4 C! f; Y; u" _) b! R! q
  2.   * @{7 P# ~* c6 l  o) `" q9 k% k
  3.   */* Y3 l: C6 _0 U: ~' m
  4. $ p. x& F; W6 c  g/ M6 [( x7 j
  5. #define USART_DMAReq_Tx                      ((uint16_t)0x0080)8 N: R; V( m' K) A6 ~$ ^
  6. #define USART_DMAReq_Rx                      ((uint16_t)0x0040)
    " K2 [% [/ }+ z9 s5 P
  7. #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00))
复制代码
8 B( g2 z) p% D9 h# |: Z
USART_WakeUp_methods
  1. /** @defgroup USART_WakeUp_methods, c6 F9 e  p& f  V% a! b- m3 e
  2.   * @{9 z& u% _. @; j& V" O: M
  3.   */1 R5 _( ?) O, ?1 R5 D5 u2 G$ P# `8 g

  4. , ~; p' e% ^1 J$ b6 y7 r  A
  5. #define USART_WakeUp_IdleLine                ((uint16_t)0x0000)
    , u* W! K. ~% n+ K" m
  6. #define USART_WakeUp_AddressMark             ((uint16_t)0x0800)0 w, [- x: D) ^, U
  7. #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \
      c$ q) e8 Z5 k. [
  8.                                  ((WAKEUP) == USART_WakeUp_AddressMark))
复制代码

' b0 w0 O' ?& n) o+ x$ ]USART_LIN_Break_Detection_Length
  1. /** @defgroup USART_LIN_Break_Detection_Length
    % P, `$ F, f5 R+ r# V7 H+ [6 J6 @0 B
  2.   * @{
    ; G8 U) N- e* [2 u9 c# q$ ^: ?1 Z* r
  3.   */
    ; e1 g& C) {. A( ]- n( T

  4. 2 E8 y# s* n3 M; d  w
  5. #define USART_LINBreakDetectLength_10b      ((uint16_t)0x0000): Y9 G# ^% h* ]2 }0 R; u
  6. #define USART_LINBreakDetectLength_11b      ((uint16_t)0x0020)# @! e9 J  B& M' X
  7. #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \
    " p- b$ p! a. c
  8.                                (((LENGTH) == USART_LINBreakDetectLength_10b) || \
    * ^! E. d8 P! i" {7 f( M3 d
  9.                                 ((LENGTH) == USART_LINBreakDetectLength_11b)), g( B* X0 i8 s& \
复制代码

8 P6 ?4 A" d2 B, DUSART_IrDA_Low_Power

2 o( Z* c, n( Y
, u0 ]- P3 m, R5 f' I( U
  1. /** @defgroup USART_IrDA_Low_Power
    9 p, Z3 X; v+ [6 O) T% F
  2.   * @{6 J9 b/ J5 D2 ~* ~
  3.   */0 @. I. q4 f3 @* b% [* @4 F# j4 ?* S

  4. - H' R; v; b% t7 E9 J
  5. #define USART_IrDAMode_LowPower              ((uint16_t)0x0004)
      l2 ]/ Y% w/ M5 R! C4 P+ i8 t
  6. #define USART_IrDAMode_Normal                ((uint16_t)0x0000)
    3 q, Y5 d7 Z3 Y5 s
  7. #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \! w6 Y1 e  J" {* u& p
  8.                                   ((MODE) == USART_IrDAMode_Normal))
复制代码
! F8 {6 B5 L) z. c. M4 u
USART_Flags6 @1 V, \" c* R8 Y& s

4 Z/ j! e" W! P
  1. /** @defgroup USART_Flags $ s5 E4 _. ]' T
  2.   * @{& r; E* `) t  o& T+ T5 K
  3.   */
    % q9 a! w* l# v; E! m* X' M

  4. - c% Q3 l- F; l3 z3 Q$ |: a
  5. #define USART_FLAG_CTS                       ((uint16_t)0x0200)
    , q. ]% v9 O! S2 y8 E
  6. #define USART_FLAG_LBD                       ((uint16_t)0x0100)
    : v% P2 A3 F2 z8 I
  7. #define USART_FLAG_TXE                       ((uint16_t)0x0080)9 S4 e2 g0 v* X+ N5 Y; Q5 |
  8. #define USART_FLAG_TC                        ((uint16_t)0x0040)
    ; G7 z1 u4 v$ C& q# j  P: F- ?
  9. #define USART_FLAG_RXNE                      ((uint16_t)0x0020)0 K; |; w& ]5 c2 L9 V
  10. #define USART_FLAG_IDLE                      ((uint16_t)0x0010)8 Z- [; n, t5 B1 j3 ?
  11. #define USART_FLAG_ORE                       ((uint16_t)0x0008): U/ s: L; h. _3 Z
  12. #define USART_FLAG_NE                        ((uint16_t)0x0004)! ?+ u( }" Z- |' V/ }# L; J7 q
  13. #define USART_FLAG_FE                        ((uint16_t)0x0002)
    , U7 b" V, K3 s1 T2 S
  14. #define USART_FLAG_PE                        ((uint16_t)0x0001)( m/ F) D, P, ~# I8 F
  15. #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \
    6 b1 B1 t  r. a
  16.                              ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \
    ! y2 o$ r2 O( q/ N" }1 D
  17.                              ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \1 {' f+ x0 w: V" b' O1 f
  18.                              ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \+ Z9 ]# q+ i: d1 B+ s# c& n: D$ N+ ~
  19.                              ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE))7 D' M0 }  m3 |. W! X; k: i3 n
  20. - v8 Z1 x9 x6 A+ k( j
  21. #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00))
    1 F8 N7 _  V/ u9 V  `& |
  22. : A  z; [# y8 w/ \; G
  23. #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 7500001))
    , j% |& q. g# k" x+ L
  24. #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)
    ! _% ~8 _! ^2 L$ P
  25. #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF)
复制代码
* ]2 I$ A, @5 K# i9 a& a
03. USART相关其它宏' {. M# h6 |; e; e% Q$ [+ B
USART_TypeDef

( P  Y, ~4 i; [! F' L" v" p: x
4 [7 v  p; A% ?
  1. /**
    . k& w- ?8 a( V, D  x4 U) P- D
  2.   * @brief Universal Synchronous Asynchronous Receiver Transmitter
    # \0 N# o. Q! I6 j& l) }2 _' R, V" e
  3.   */
    9 Q8 e/ B; D/ ?
  4. ; A8 U3 V* I1 ^$ V! I! F
  5. typedef struct& B* L8 B+ w& `7 x" K0 P3 C1 Q
  6. {
    1 J9 S; {! }( V+ f" A
  7.   __IO uint16_t SR;         /*!< USART Status register,                   Address offset: 0x00 */$ v9 t9 G) l6 o( k; t- r8 J% h
  8.   uint16_t      RESERVED0;  /*!< Reserved, 0x02                                                */
    / M# x/ T( Q. G; u8 A1 Q/ X- d
  9.   __IO uint16_t DR;         /*!< USART Data register,                     Address offset: 0x04 */
    % W- W5 |; N9 e' q8 s8 P  |
  10.   uint16_t      RESERVED1;  /*!< Reserved, 0x06                                                */
    " u( m6 u% E/ B! C, ]! L
  11.   __IO uint16_t BRR;        /*!< USART Baud rate register,                Address offset: 0x08 */
      E% Y% [' w7 ^6 _; H0 f0 G& @$ ^
  12.   uint16_t      RESERVED2;  /*!< Reserved, 0x0A                                                */, z- C( L/ g# y" w
  13.   __IO uint16_t CR1;        /*!< USART Control register 1,                Address offset: 0x0C */+ T8 o8 S% t  H. N, @0 D4 n" z
  14.   uint16_t      RESERVED3;  /*!< Reserved, 0x0E                                                */- z0 E; ^6 [9 O
  15.   __IO uint16_t CR2;        /*!< USART Control register 2,                Address offset: 0x10 */( }7 z! z% \6 {+ z# e
  16.   uint16_t      RESERVED4;  /*!< Reserved, 0x12                                                */
    5 Z- t9 Q/ c/ g! e& ^& ~; N
  17.   __IO uint16_t CR3;        /*!< USART Control register 3,                Address offset: 0x14 */
    : {8 J& B( F2 @( v
  18.   uint16_t      RESERVED5;  /*!< Reserved, 0x16                                                */
    6 V; i  c1 `0 g( @( j
  19.   __IO uint16_t GTPR;       /*!< USART Guard time and prescaler register, Address offset: 0x18 */2 r7 C; ]8 j/ e3 v* T
  20.   uint16_t      RESERVED6;  /*!< Reserved, 0x1A                                                */
    6 W+ x$ \0 b. H/ u  W
  21. } USART_TypeDef;
    0 F4 Z9 n) b6 \. M
复制代码
  1. /******************************************************************************/
    / a# |/ ]2 J" A# f2 n& ^$ ~$ {
  2. /*                                                                            */
    8 E7 a! p; e1 d$ A/ l
  3. /*         Universal Synchronous Asynchronous Receiver Transmitter            */( i8 ]4 ?. G# i$ W$ g& B0 e
  4. /*                                                                            */( x# e! l( O9 l+ I' w! g; N# a
  5. /******************************************************************************/% |7 \1 m8 L3 S+ ], G
  6. /*******************  Bit definition for USART_SR register  *******************/
    6 I; Z& L- H0 F1 D! q) e
  7. #define  USART_SR_PE                         ((uint16_t)0x0001)            /*!<Parity Error                 */) B- d; b+ M, J7 n4 s. @
  8. #define  USART_SR_FE                         ((uint16_t)0x0002)            /*!<Framing Error                */
    ' B* z) e6 a: s% m3 f
  9. #define  USART_SR_NE                         ((uint16_t)0x0004)            /*!<Noise Error Flag             */
    - L$ g' O; B/ D5 c" g, ^$ }- G% ^" d
  10. #define  USART_SR_ORE                        ((uint16_t)0x0008)            /*!<OverRun Error                */
    . k3 X# n9 A7 E% g( p: f
  11. #define  USART_SR_IDLE                       ((uint16_t)0x0010)            /*!<IDLE line detected           */
    5 J, v1 x5 Q" U5 H4 W; r" c2 U
  12. #define  USART_SR_RXNE                       ((uint16_t)0x0020)            /*!<Read Data Register Not Empty */. H+ b  d& a; |
  13. #define  USART_SR_TC                         ((uint16_t)0x0040)            /*!<Transmission Complete        */
    4 R; _7 F7 X  s
  14. #define  USART_SR_TXE                        ((uint16_t)0x0080)            /*!<Transmit Data Register Empty */: R7 M+ m' M5 h1 Z. Z* A
  15. #define  USART_SR_LBD                        ((uint16_t)0x0100)            /*!<LIN Break Detection Flag     */
    6 M1 B2 Y) B; D% L) d
  16. #define  USART_SR_CTS                        ((uint16_t)0x0200)            /*!<CTS Flag                     */
    " g# o$ ?5 x3 t4 |( j6 Y$ a

  17. ) K9 e3 x) y' U1 o
  18. /*******************  Bit definition for USART_DR register  *******************/
    : y: m# ], X- r9 w
  19. #define  USART_DR_DR                         ((uint16_t)0x01FF)            /*!<Data value */
    * `* k4 F, v: @+ q/ {2 B  ^0 w

  20. " x3 \: e/ l" g! Q! @
  21. /******************  Bit definition for USART_BRR register  *******************/- d& v. ~6 ~6 p7 \  E2 ]' u  j
  22. #define  USART_BRR_DIV_Fraction              ((uint16_t)0x000F)            /*!<Fraction of USARTDIV */
    3 f0 X& c* g. m9 l
  23. #define  USART_BRR_DIV_Mantissa              ((uint16_t)0xFFF0)            /*!<Mantissa of USARTDIV */
    3 K) K/ c, m+ }' S1 k, {

  24. ( c" S6 R- F# A1 ?, ?" n+ h
  25. /******************  Bit definition for USART_CR1 register  *******************/( e8 _1 k# W" L
  26. #define  USART_CR1_SBK                       ((uint16_t)0x0001)            /*!<Send Break                             */& j9 v3 g6 ~2 m
  27. #define  USART_CR1_RWU                       ((uint16_t)0x0002)            /*!<Receiver wakeup                        */
    ) Q- u' q; H9 ]  d* I$ l
  28. #define  USART_CR1_RE                        ((uint16_t)0x0004)            /*!<Receiver Enable                        */$ v5 j' X8 D  w3 M8 J( {  [! \% T, E
  29. #define  USART_CR1_TE                        ((uint16_t)0x0008)            /*!<Transmitter Enable                     */
    % I$ A4 O& t! ~( r5 o) j3 @% U
  30. #define  USART_CR1_IDLEIE                    ((uint16_t)0x0010)            /*!<IDLE Interrupt Enable                  */) A% {! o; B, Y. o: t  o
  31. #define  USART_CR1_RXNEIE                    ((uint16_t)0x0020)            /*!<RXNE Interrupt Enable                  */
    ( r* l# w/ e9 {
  32. #define  USART_CR1_TCIE                      ((uint16_t)0x0040)            /*!<Transmission Complete Interrupt Enable *// R/ e- N8 o0 U* x- ^$ a" r
  33. #define  USART_CR1_TXEIE                     ((uint16_t)0x0080)            /*!<PE Interrupt Enable                    */" i6 m6 M! P# G1 p
  34. #define  USART_CR1_PEIE                      ((uint16_t)0x0100)            /*!<PE Interrupt Enable                    */. s; f( S5 h, Z3 G0 k/ L7 B  f( {
  35. #define  USART_CR1_PS                        ((uint16_t)0x0200)            /*!<Parity Selection                       */
    $ ?& R% k- l9 g$ Z$ o4 c0 w
  36. #define  USART_CR1_PCE                       ((uint16_t)0x0400)            /*!<Parity Control Enable                  */
    3 L5 E* p/ K9 l) k
  37. #define  USART_CR1_WAKE                      ((uint16_t)0x0800)            /*!<Wakeup method                          */
    + s. E# T2 O& K) @/ D. Q& ]
  38. #define  USART_CR1_M                         ((uint16_t)0x1000)            /*!<Word length                            */
      k& h* v/ p5 [1 V* M2 i
  39. #define  USART_CR1_UE                        ((uint16_t)0x2000)            /*!<USART Enable                           */
    ! x4 i+ o( I7 y; s0 C7 n
  40. #define  USART_CR1_OVER8                     ((uint16_t)0x8000)            /*!<USART Oversampling by 8 enable         */
    : A% s8 U$ h' I( g# I6 z3 f! J

  41. 6 b& ^" G  ~" [. R, @' M' r: Z4 \
  42. /******************  Bit definition for USART_CR2 register  *******************/8 H% n2 g/ x" L7 w/ W$ w
  43. #define  USART_CR2_ADD                       ((uint16_t)0x000F)            /*!<Address of the USART node            */+ C8 o: u% P+ F
  44. #define  USART_CR2_LBDL                      ((uint16_t)0x0020)            /*!<LIN Break Detection Length           */7 C. P' H2 Q" |7 f
  45. #define  USART_CR2_LBDIE                     ((uint16_t)0x0040)            /*!<LIN Break Detection Interrupt Enable */2 Y# q7 Q* T! Q% E0 L4 B/ h
  46. #define  USART_CR2_LBCL                      ((uint16_t)0x0100)            /*!<Last Bit Clock pulse                 */
    ! p  P3 I  _! l. ?2 a% k, O/ [
  47. #define  USART_CR2_CPHA                      ((uint16_t)0x0200)            /*!<Clock Phase                          */0 i- D  C/ R0 h& s* f3 ?0 ^4 h3 K+ M' j
  48. #define  USART_CR2_CPOL                      ((uint16_t)0x0400)            /*!<Clock Polarity                       */: w: y7 E, h" C, k
  49. #define  USART_CR2_CLKEN                     ((uint16_t)0x0800)            /*!<Clock Enable                         */
    % D% b5 K8 Z& D# d4 X1 {, n

  50. . I9 d3 q3 ?1 j( ~$ x1 E: a
  51. #define  USART_CR2_STOP                      ((uint16_t)0x3000)            /*!<STOP[1:0] bits (STOP bits) */
    7 t; v/ C( Q0 q, [/ s( F6 w
  52. #define  USART_CR2_STOP_0                    ((uint16_t)0x1000)            /*!<Bit 0 */
    ( d4 F8 N: D0 N
  53. #define  USART_CR2_STOP_1                    ((uint16_t)0x2000)            /*!<Bit 1 */
    # `9 w/ ~5 Z% _
  54. - H: L& T' a% d- a( A
  55. #define  USART_CR2_LINEN                     ((uint16_t)0x4000)            /*!<LIN mode enable */5 `) I9 f3 y' V! w6 D9 u
  56. " a& M  x, `+ A: P. F$ p! ~; X
  57. /******************  Bit definition for USART_CR3 register  *******************/
    / K; M# {1 p, N2 L8 S
  58. #define  USART_CR3_EIE                       ((uint16_t)0x0001)            /*!<Error Interrupt Enable      */8 N5 [; m0 _/ [" t7 V# m  F
  59. #define  USART_CR3_IREN                      ((uint16_t)0x0002)            /*!<IrDA mode Enable            */$ Y9 l/ G0 G& p2 |
  60. #define  USART_CR3_IRLP                      ((uint16_t)0x0004)            /*!<IrDA Low-Power              */
    0 I- X& w+ x7 ^% m) Y
  61. #define  USART_CR3_HDSEL                     ((uint16_t)0x0008)            /*!<Half-Duplex Selection       */
    - O; L: P9 Q" |" b$ |
  62. #define  USART_CR3_NACK                      ((uint16_t)0x0010)            /*!<Smartcard NACK enable       */' Q& p, v+ k+ G5 ]' I
  63. #define  USART_CR3_SCEN                      ((uint16_t)0x0020)            /*!<Smartcard mode enable       */1 M7 F3 [2 S: a' v' j5 ?% c
  64. #define  USART_CR3_DMAR                      ((uint16_t)0x0040)            /*!<DMA Enable Receiver         */
    / W6 ]* y/ z5 ~- R- @9 P+ P) J
  65. #define  USART_CR3_DMAT                      ((uint16_t)0x0080)            /*!<DMA Enable Transmitter      */. }  `, J* T- y3 y" ~
  66. #define  USART_CR3_RTSE                      ((uint16_t)0x0100)            /*!<RTS Enable                  */
    * T: S. m" m. X
  67. #define  USART_CR3_CTSE                      ((uint16_t)0x0200)            /*!<CTS Enable                  */
    ) N! I2 ~1 H! e, K% R6 b
  68. #define  USART_CR3_CTSIE                     ((uint16_t)0x0400)            /*!<CTS Interrupt Enable        */
      _3 g% T7 b7 v% u7 c- x/ r: v
  69. #define  USART_CR3_ONEBIT                    ((uint16_t)0x0800)            /*!<USART One bit method enable */7 g/ a  V# H8 H3 I+ U

  70. 8 s0 ^3 V/ y, v2 i, G
  71. /******************  Bit definition for USART_GTPR register  ******************/: a- U/ s  X$ c' h2 r1 k4 m  ]* j
  72. #define  USART_GTPR_PSC                      ((uint16_t)0x00FF)            /*!<PSC[7:0] bits (Prescaler value) */
    # t2 l; F$ I! l/ w0 m1 w
  73. #define  USART_GTPR_PSC_0                    ((uint16_t)0x0001)            /*!<Bit 0 */! H# w) C7 _' M$ k, S( Y
  74. #define  USART_GTPR_PSC_1                    ((uint16_t)0x0002)            /*!<Bit 1 */6 s6 x. H( L8 {# c4 d
  75. #define  USART_GTPR_PSC_2                    ((uint16_t)0x0004)            /*!<Bit 2 */
    : \5 e6 o0 ~0 s$ I, C6 _+ p
  76. #define  USART_GTPR_PSC_3                    ((uint16_t)0x0008)            /*!<Bit 3 */
    " C) @" p! U4 U/ {$ Q0 Y
  77. #define  USART_GTPR_PSC_4                    ((uint16_t)0x0010)            /*!<Bit 4 */) S" C! q" i) f
  78. #define  USART_GTPR_PSC_5                    ((uint16_t)0x0020)            /*!<Bit 5 */! T+ W# ]) F' n) p) z
  79. #define  USART_GTPR_PSC_6                    ((uint16_t)0x0040)            /*!<Bit 6 */; Q( F/ b/ p" e0 ]6 X
  80. #define  USART_GTPR_PSC_7                    ((uint16_t)0x0080)            /*!<Bit 7 */, l2 w0 b. H. L
  81. 3 `" \7 T& H. l, ]8 |
  82. #define  USART_GTPR_GT                       ((uint16_t)0xFF00)            /*!<Guard time value */
复制代码

5 N6 N) d0 I4 R04. USART相关函数

5 Q( V$ r. t* e* [  `& |
  1. /*  Function used to set the USART configuration to the default reset state ***/
    ! {) e" D" [5 a$ ~0 s
  2. void USART_DeInit(USART_TypeDef* USARTx);
    0 D4 x; N) R! i8 a5 j2 l

  3. . @- o5 @4 V/ E# g
  4. /* Initialization and Configuration functions *********************************// o+ F7 S9 v/ Y# {# M8 }8 d
  5. void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);) k, y& L/ `) F& c' Z; t1 w: R
  6. void USART_StructInit(USART_InitTypeDef* USART_InitStruct);
    9 w9 k+ ], m2 D( o2 O
  7. void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct);
    # E$ h% c  Z, _2 @
  8. void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct);
    # K2 a8 V2 l! p4 R5 k9 o
  9. void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
    8 }" C5 L  Y. Q& A
  10. void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler);1 F6 [- B( ^! E3 H" a& B
  11. void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
    1 U' Q+ W- y5 u6 _/ ~: L
  12. void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState);
      M. T; R0 h: p: t% ^

  13. ' M8 R' k$ n7 R$ X5 p: H
  14. /* Data transfers functions ***************************************************/
    1 ~9 x3 V, @8 H/ n  ?3 z
  15. void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);
    2 j8 }# Z7 S4 ~; Y5 ^* u$ Z
  16. uint16_t USART_ReceiveData(USART_TypeDef* USARTx);
    / M: ^, G$ v* C' ^; @! C% J

  17. 1 [2 ?& l' T' u" I& @6 m
  18. /* Multi-Processor Communication functions ************************************/: X- F5 a) L" t
  19. void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address);" M* ?+ V3 z3 w8 N
  20. void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp);
    * ^& W& m  B. a1 i$ c6 V3 O
  21. void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState);
      m1 P* Z, d* B$ f
  22. 4 M2 s4 S. V* t+ M
  23. /* LIN mode functions *********************************************************/
    % Z; h* f1 G# f+ i* |) T$ [  t
  24. void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength);+ Y" x5 D: \/ z! ^1 |$ q
  25. void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState);
    $ L  n" x3 ~- ?) R4 c
  26. void USART_SendBreak(USART_TypeDef* USARTx);3 `* L# B: g6 A: r; p

  27. - W# z2 _3 Q, E5 N. C
  28. /* Half-duplex mode function **************************************************/
    9 T* \2 u4 s- w6 ]% E
  29. void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState);
    3 i& A1 I3 A2 a* @0 @3 Z
  30. 8 f: _0 c: b4 W, |) z5 x" \" }
  31. /* Smartcard mode functions ***************************************************/
    4 e1 O& p4 O6 h$ F8 i5 L  [
  32. void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState);
    # V6 i7 V$ n: A+ ~
  33. void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState);
    & O  `5 N7 I) R' C' ^9 f! x/ Y
  34. void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime);% Y! F$ W. A/ j. \
  35. % Z5 x- \0 s  a& r. O( R
  36. /* IrDA mode functions ********************************************************/
    8 j, k, j) w' m0 e8 Q6 b3 \
  37. void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode);! C" G7 p' E9 P  \% M3 e3 c, s
  38. void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState);
    2 i& e; ?' ?) p/ \, w- ~

  39. 8 a: ~* [/ x# G6 i
  40. /* DMA transfers management functions *****************************************/8 x6 l8 v0 {2 r# m0 o; k% U
  41. void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);
    5 r( t" R# G2 U, d1 G& ?, i$ \* R" y

  42.   g9 ?7 Q: }; C) s7 u! b/ W! T3 }
  43. /* Interrupts and flags management functions **********************************/, Y) w/ C" I: B$ B; c3 V
  44. void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);
    " n+ R" V5 x5 O1 ^
  45. FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);* a- ]# c5 x' M  v; k
  46. void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG);
    # X  p2 b# G. b% F' k8 W, X+ u
  47. ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);
    6 U& ]: ?+ c& p  I
  48. void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);9 {; @& h' c3 Q3 d) w3 G/ {
复制代码

) j% W  w4 @9 ]5 X6 l( J0 B: d. j05. USART其它
# o/ D" _/ t' [+ p7 l& K! a) fUSART基地址
- n% r4 N+ F' C6 l

% I) `8 K+ `6 V9 L  u# `
  1. #define USART2_BASE           (APB1PERIPH_BASE + 0x4400)
    6 h  i0 L# a6 e5 q- r3 s- V% x
  2. #define USART3_BASE           (APB1PERIPH_BASE + 0x4800)! N7 \5 {  o7 O. }# g) t8 n3 x4 P
  3. #define UART4_BASE            (APB1PERIPH_BASE + 0x4C00)
    " @) t2 F/ j' {2 I' E3 {1 Y9 `
  4. #define UART5_BASE            (APB1PERIPH_BASE + 0x5000)8 `3 ~9 F" o4 c9 s
  5. ; M+ {7 y5 E5 i7 k1 x
  6. #define USART1_BASE           (APB2PERIPH_BASE + 0x1000)% W3 V. G- D+ N) Z
  7. #define USART6_BASE           (APB2PERIPH_BASE + 0x1400)2 }7 z0 ?6 b" d( E# G/ H
  8. #define UART9_BASE            (APB2PERIPH_BASE + 0x1800U)7 F" H; v& C: D+ ^3 ]3 L! u5 v
  9. #define UART10_BASE           (APB2PERIPH_BASE + 0x1C00U)
复制代码
& B% h0 Z4 Y" [5 k/ K% Q
: R# H  `, Y7 w, X8 U2 Z4 l  @  S6 L

. c2 O, i+ E8 F, f
赞 收藏 评论0 发布时间:2022-4-2 21:00

举报

0个回答

所属标签

相似技术帖

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