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

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

[复制链接]
STMCU小助手 发布时间:2022-6-13 08:56
01. USART固件库概述
stm32f4xx_usart.h 函数的声明和类型的声明

stm32f4xx_usart.c 函数的实现

02. USART相关类型
stm32f4xx_usart.h文件中

USART_InitTypeDef类型


  1. /**
  2.   * @brief  USART Init Structure definition  
  3.   */

  4. typedef struct
  5. {
  6.   uint32_t USART_BaudRate;            /*!< This member configures the USART communication baud rate.
  7.                                            The baud rate is computed using the following formula:
  8.                                             - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (USART_InitStruct->USART_BaudRate)))
  9.                                             - FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 8 * (OVR8+1)) + 0.5
  10.                                            Where OVR8 is the "oversampling by 8 mode" configuration bit in the CR1 register. */

  11.   uint16_t USART_WordLength;          /*!< Specifies the number of data bits transmitted or received in a frame.
  12.                                            This parameter can be a value of @ref USART_Word_Length */

  13.   uint16_t USART_StopBits;            /*!< Specifies the number of stop bits transmitted.
  14.                                            This parameter can be a value of @ref USART_Stop_Bits */

  15.   uint16_t USART_Parity;              /*!< Specifies the parity mode.
  16.                                            This parameter can be a value of @ref USART_Parity
  17.                                            @note When parity is enabled, the computed parity is inserted
  18.                                                  at the MSB position of the transmitted data (9th bit when
  19.                                                  the word length is set to 9 data bits; 8th bit when the
  20.                                                  word length is set to 8 data bits). */

  21.   uint16_t USART_Mode;                /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
  22.                                            This parameter can be a value of @ref USART_Mode */

  23.   uint16_t USART_HardwareFlowControl; /*!< Specifies wether the hardware flow control mode is enabled
  24.                                            or disabled.
  25.                                            This parameter can be a value of @ref USART_Hardware_Flow_Control */
  26. } USART_InitTypeDef;
复制代码

USART_ClockInitTypeDef类型

  1. /**
  2.   * @brief  USART Clock Init Structure definition  
  3.   */

  4. typedef struct
  5. {

  6.   uint16_t USART_Clock;   /*!< Specifies whether the USART clock is enabled or disabled.
  7.                                This parameter can be a value of @ref USART_Clock */

  8.   uint16_t USART_CPOL;    /*!< Specifies the steady state of the serial clock.
  9.                                This parameter can be a value of @ref USART_Clock_Polarity */

  10.   uint16_t USART_CPHA;    /*!< Specifies the clock transition on which the bit capture is made.
  11.                                This parameter can be a value of @ref USART_Clock_Phase */

  12.   uint16_t USART_LastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
  13.                                data bit (MSB) has to be output on the SCLK pin in synchronous mode.
  14.                                This parameter can be a value of @ref USART_Last_Bit */
  15. } USART_ClockInitTypeDef;
复制代码

USART外设

  1. /** @defgroup USART_Exported_Constants
  2.   * @{
  3.   */

  4. #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \
  5.                                      ((PERIPH) == USART2) || \
  6.                                      ((PERIPH) == USART3) || \
  7.                                      ((PERIPH) == UART4)  || \
  8.                                      ((PERIPH) == UART5)  || \
  9.                                      ((PERIPH) == USART6) || \
  10.                                      ((PERIPH) == UART7)  || \
  11.                                      ((PERIPH) == UART8)  || \
  12.                                      ((PERIPH) == UART9)  || \
  13.                                      ((PERIPH) == UART10))

  14. #define IS_USART_1236_PERIPH(PERIPH) (((PERIPH) == USART1) || \
  15.                                       ((PERIPH) == USART2) || \
  16.                                       ((PERIPH) == USART3) || \
  17.                                       ((PERIPH) == USART6))
复制代码

USART_Word_Length

  1. /** @defgroup USART_Word_Length
  2.   * @{
  3.   */

  4. #define USART_WordLength_8b                  ((uint16_t)0x0000)
  5. #define USART_WordLength_9b                  ((uint16_t)0x1000)

  6. #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \
  7.                                       ((LENGTH) == USART_WordLength_9b))
复制代码

USART_Stop_Bits

  1. /** @defgroup USART_Stop_Bits
  2.   * @{
  3.   */

  4. #define USART_StopBits_1                     ((uint16_t)0x0000)
  5. #define USART_StopBits_0_5                   ((uint16_t)0x1000)
  6. #define USART_StopBits_2                     ((uint16_t)0x2000)
  7. #define USART_StopBits_1_5                   ((uint16_t)0x3000)
  8. #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \
  9.                                      ((STOPBITS) == USART_StopBits_0_5) || \
  10.                                      ((STOPBITS) == USART_StopBits_2) || \
  11.                                      ((STOPBITS) == USART_StopBits_1_5))
复制代码

USART_Parity

  1. /** @defgroup USART_Parity
  2.   * @{
  3.   */

  4. #define USART_Parity_No                      ((uint16_t)0x0000)
  5. #define USART_Parity_Even                    ((uint16_t)0x0400)
  6. #define USART_Parity_Odd                     ((uint16_t)0x0600)
  7. #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \
  8.                                  ((PARITY) == USART_Parity_Even) || \
  9.                                  ((PARITY) == USART_Parity_Odd))
复制代码

USART_Mode

  1. /** @defgroup USART_Mode
  2.   * @{
  3.   */

  4. #define USART_Mode_Rx                        ((uint16_t)0x0004)
  5. #define USART_Mode_Tx                        ((uint16_t)0x0008)
  6. #define IS_USART_MODE(MODE) ((((MODE) & (uint16_t)0xFFF3) == 0x00) && ((MODE) != (uint16_t)0x00))
复制代码

USART_Hardware_Flow_Control

  1. /** @defgroup USART_Hardware_Flow_Control
  2.   * @{
  3.   */
  4. #define USART_HardwareFlowControl_None       ((uint16_t)0x0000)
  5. #define USART_HardwareFlowControl_RTS        ((uint16_t)0x0100)
  6. #define USART_HardwareFlowControl_CTS        ((uint16_t)0x0200)
  7. #define USART_HardwareFlowControl_RTS_CTS    ((uint16_t)0x0300)
  8. #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\
  9.                               (((CONTROL) == USART_HardwareFlowControl_None) || \
  10.                                ((CONTROL) == USART_HardwareFlowControl_RTS) || \
  11.                                ((CONTROL) == USART_HardwareFlowControl_CTS) || \
  12.                                ((CONTROL) == USART_HardwareFlowControl_RTS_CTS))
复制代码

USART_Clock

  1. /** @defgroup USART_Clock
  2.   * @{
  3.   */
  4. #define USART_Clock_Disable                  ((uint16_t)0x0000)
  5. #define USART_Clock_Enable                   ((uint16_t)0x0800)
  6. #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \
  7.                                ((CLOCK) == USART_Clock_Enable))
复制代码

USART_Clock_Polarity


  1. /** @defgroup USART_Clock_Polarity
  2.   * @{
  3.   */

  4. #define USART_CPOL_Low                       ((uint16_t)0x0000)
  5. #define USART_CPOL_High                      ((uint16_t)0x0400)
  6. #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High))
复制代码

USART_Clock_Phase

  1. /** @defgroup USART_Clock_Phase
  2.   * @{
  3.   */

  4. #define USART_CPHA_1Edge                     ((uint16_t)0x0000)
  5. #define USART_CPHA_2Edge                     ((uint16_t)0x0200)
  6. #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge))
复制代码

USART_Last_Bit

  1. /** @defgroup USART_Last_Bit
  2.   * @{
  3.   */

  4. #define USART_LastBit_Disable                ((uint16_t)0x0000)
  5. #define USART_LastBit_Enable                 ((uint16_t)0x0100)
  6. #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \
  7.                                    ((LASTBIT) == USART_LastBit_Enable))
复制代码

USART_Interrupt_definition

  1. /** @defgroup USART_Interrupt_definition
  2.   * @{
  3.   */

  4. #define USART_IT_PE                          ((uint16_t)0x0028)
  5. #define USART_IT_TXE                         ((uint16_t)0x0727)
  6. #define USART_IT_TC                          ((uint16_t)0x0626)
  7. #define USART_IT_RXNE                        ((uint16_t)0x0525)
  8. #define USART_IT_ORE_RX                      ((uint16_t)0x0325) /* In case interrupt is generated if the RXNEIE bit is set */
  9. #define USART_IT_IDLE                        ((uint16_t)0x0424)
  10. #define USART_IT_LBD                         ((uint16_t)0x0846)
  11. #define USART_IT_CTS                         ((uint16_t)0x096A)
  12. #define USART_IT_ERR                         ((uint16_t)0x0060)
  13. #define USART_IT_ORE_ER                      ((uint16_t)0x0360) /* In case interrupt is generated if the EIE bit is set */
  14. #define USART_IT_NE                          ((uint16_t)0x0260)
  15. #define USART_IT_FE                          ((uint16_t)0x0160)
复制代码
  1. #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
  2.                                 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
  3.                                 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
  4.                                 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR))
  5. #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
  6.                              ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
  7.                              ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
  8.                              ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \
  9.                              ((IT) == USART_IT_ORE_RX) || ((IT) == USART_IT_ORE_ER) || \
  10.                              ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE))
  11. #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
  12.                                ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS))
复制代码

USART_DMA_Requests

  1. /** @defgroup USART_DMA_Requests
  2.   * @{
  3.   */

  4. #define USART_DMAReq_Tx                      ((uint16_t)0x0080)
  5. #define USART_DMAReq_Rx                      ((uint16_t)0x0040)
  6. #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint16_t)0xFF3F) == 0x00) && ((DMAREQ) != (uint16_t)0x00))
复制代码


USART_WakeUp_methods

  1. /** @defgroup USART_WakeUp_methods
  2.   * @{
  3.   */

  4. #define USART_WakeUp_IdleLine                ((uint16_t)0x0000)
  5. #define USART_WakeUp_AddressMark             ((uint16_t)0x0800)
  6. #define IS_USART_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \
  7.                                  ((WAKEUP) == USART_WakeUp_AddressMark))
复制代码

USART_LIN_Break_Detection_Length
  1. /** @defgroup USART_LIN_Break_Detection_Length
  2.   * @{
  3.   */

  4. #define USART_LINBreakDetectLength_10b      ((uint16_t)0x0000)
  5. #define USART_LINBreakDetectLength_11b      ((uint16_t)0x0020)
  6. #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \
  7.                                (((LENGTH) == USART_LINBreakDetectLength_10b) || \
  8.                                 ((LENGTH) == USART_LINBreakDetectLength_11b))
复制代码

USART_IrDA_Low_Power

  1. /** @defgroup USART_IrDA_Low_Power
  2.   * @{
  3.   */

  4. #define USART_IrDAMode_LowPower              ((uint16_t)0x0004)
  5. #define USART_IrDAMode_Normal                ((uint16_t)0x0000)
  6. #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \
  7.                                   ((MODE) == USART_IrDAMode_Normal))
复制代码

USART_Flags

  1. /** @defgroup USART_Flags
  2.   * @{
  3.   */

  4. #define USART_FLAG_CTS                       ((uint16_t)0x0200)
  5. #define USART_FLAG_LBD                       ((uint16_t)0x0100)
  6. #define USART_FLAG_TXE                       ((uint16_t)0x0080)
  7. #define USART_FLAG_TC                        ((uint16_t)0x0040)
  8. #define USART_FLAG_RXNE                      ((uint16_t)0x0020)
  9. #define USART_FLAG_IDLE                      ((uint16_t)0x0010)
  10. #define USART_FLAG_ORE                       ((uint16_t)0x0008)
  11. #define USART_FLAG_NE                        ((uint16_t)0x0004)
  12. #define USART_FLAG_FE                        ((uint16_t)0x0002)
  13. #define USART_FLAG_PE                        ((uint16_t)0x0001)
  14. #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \
  15.                              ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \
  16.                              ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \
  17.                              ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \
  18.                              ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE))

  19. #define IS_USART_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFC9F) == 0x00) && ((FLAG) != (uint16_t)0x00))

  20. #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 7500001))
  21. #define IS_USART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)
  22. #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF)
复制代码

03. USART相关其它宏
USART_TypeDef

  1. /**
  2.   * @brief Universal Synchronous Asynchronous Receiver Transmitter
  3.   */

  4. typedef struct
  5. {
  6.   __IO uint16_t SR;         /*!< USART Status register,                   Address offset: 0x00 */
  7.   uint16_t      RESERVED0;  /*!< Reserved, 0x02                                                */
  8.   __IO uint16_t DR;         /*!< USART Data register,                     Address offset: 0x04 */
  9.   uint16_t      RESERVED1;  /*!< Reserved, 0x06                                                */
  10.   __IO uint16_t BRR;        /*!< USART Baud rate register,                Address offset: 0x08 */
  11.   uint16_t      RESERVED2;  /*!< Reserved, 0x0A                                                */
  12.   __IO uint16_t CR1;        /*!< USART Control register 1,                Address offset: 0x0C */
  13.   uint16_t      RESERVED3;  /*!< Reserved, 0x0E                                                */
  14.   __IO uint16_t CR2;        /*!< USART Control register 2,                Address offset: 0x10 */
  15.   uint16_t      RESERVED4;  /*!< Reserved, 0x12                                                */
  16.   __IO uint16_t CR3;        /*!< USART Control register 3,                Address offset: 0x14 */
  17.   uint16_t      RESERVED5;  /*!< Reserved, 0x16                                                */
  18.   __IO uint16_t GTPR;       /*!< USART Guard time and prescaler register, Address offset: 0x18 */
  19.   uint16_t      RESERVED6;  /*!< Reserved, 0x1A                                                */
  20. } USART_TypeDef;
复制代码
  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*         Universal Synchronous Asynchronous Receiver Transmitter            */
  4. /*                                                                            */
  5. /******************************************************************************/
  6. /*******************  Bit definition for USART_SR register  *******************/
  7. #define  USART_SR_PE                         ((uint16_t)0x0001)            /*!<Parity Error                 */
  8. #define  USART_SR_FE                         ((uint16_t)0x0002)            /*!<Framing Error                */
  9. #define  USART_SR_NE                         ((uint16_t)0x0004)            /*!<Noise Error Flag             */
  10. #define  USART_SR_ORE                        ((uint16_t)0x0008)            /*!<OverRun Error                */
  11. #define  USART_SR_IDLE                       ((uint16_t)0x0010)            /*!<IDLE line detected           */
  12. #define  USART_SR_RXNE                       ((uint16_t)0x0020)            /*!<Read Data Register Not Empty */
  13. #define  USART_SR_TC                         ((uint16_t)0x0040)            /*!<Transmission Complete        */
  14. #define  USART_SR_TXE                        ((uint16_t)0x0080)            /*!<Transmit Data Register Empty */
  15. #define  USART_SR_LBD                        ((uint16_t)0x0100)            /*!<LIN Break Detection Flag     */
  16. #define  USART_SR_CTS                        ((uint16_t)0x0200)            /*!<CTS Flag                     */

  17. /*******************  Bit definition for USART_DR register  *******************/
  18. #define  USART_DR_DR                         ((uint16_t)0x01FF)            /*!<Data value */

  19. /******************  Bit definition for USART_BRR register  *******************/
  20. #define  USART_BRR_DIV_Fraction              ((uint16_t)0x000F)            /*!<Fraction of USARTDIV */
  21. #define  USART_BRR_DIV_Mantissa              ((uint16_t)0xFFF0)            /*!<Mantissa of USARTDIV */

  22. /******************  Bit definition for USART_CR1 register  *******************/
  23. #define  USART_CR1_SBK                       ((uint16_t)0x0001)            /*!<Send Break                             */
  24. #define  USART_CR1_RWU                       ((uint16_t)0x0002)            /*!<Receiver wakeup                        */
  25. #define  USART_CR1_RE                        ((uint16_t)0x0004)            /*!<Receiver Enable                        */
  26. #define  USART_CR1_TE                        ((uint16_t)0x0008)            /*!<Transmitter Enable                     */
  27. #define  USART_CR1_IDLEIE                    ((uint16_t)0x0010)            /*!<IDLE Interrupt Enable                  */
  28. #define  USART_CR1_RXNEIE                    ((uint16_t)0x0020)            /*!<RXNE Interrupt Enable                  */
  29. #define  USART_CR1_TCIE                      ((uint16_t)0x0040)            /*!<Transmission Complete Interrupt Enable */
  30. #define  USART_CR1_TXEIE                     ((uint16_t)0x0080)            /*!<PE Interrupt Enable                    */
  31. #define  USART_CR1_PEIE                      ((uint16_t)0x0100)            /*!<PE Interrupt Enable                    */
  32. #define  USART_CR1_PS                        ((uint16_t)0x0200)            /*!<Parity Selection                       */
  33. #define  USART_CR1_PCE                       ((uint16_t)0x0400)            /*!<Parity Control Enable                  */
  34. #define  USART_CR1_WAKE                      ((uint16_t)0x0800)            /*!<Wakeup method                          */
  35. #define  USART_CR1_M                         ((uint16_t)0x1000)            /*!<Word length                            */
  36. #define  USART_CR1_UE                        ((uint16_t)0x2000)            /*!<USART Enable                           */
  37. #define  USART_CR1_OVER8                     ((uint16_t)0x8000)            /*!<USART Oversampling by 8 enable         */

  38. /******************  Bit definition for USART_CR2 register  *******************/
  39. #define  USART_CR2_ADD                       ((uint16_t)0x000F)            /*!<Address of the USART node            */
  40. #define  USART_CR2_LBDL                      ((uint16_t)0x0020)            /*!<LIN Break Detection Length           */
  41. #define  USART_CR2_LBDIE                     ((uint16_t)0x0040)            /*!<LIN Break Detection Interrupt Enable */
  42. #define  USART_CR2_LBCL                      ((uint16_t)0x0100)            /*!<Last Bit Clock pulse                 */
  43. #define  USART_CR2_CPHA                      ((uint16_t)0x0200)            /*!<Clock Phase                          */
  44. #define  USART_CR2_CPOL                      ((uint16_t)0x0400)            /*!<Clock Polarity                       */
  45. #define  USART_CR2_CLKEN                     ((uint16_t)0x0800)            /*!<Clock Enable                         */

  46. #define  USART_CR2_STOP                      ((uint16_t)0x3000)            /*!<STOP[1:0] bits (STOP bits) */
  47. #define  USART_CR2_STOP_0                    ((uint16_t)0x1000)            /*!<Bit 0 */
  48. #define  USART_CR2_STOP_1                    ((uint16_t)0x2000)            /*!<Bit 1 */

  49. #define  USART_CR2_LINEN                     ((uint16_t)0x4000)            /*!<LIN mode enable */

  50. /******************  Bit definition for USART_CR3 register  *******************/
  51. #define  USART_CR3_EIE                       ((uint16_t)0x0001)            /*!<Error Interrupt Enable      */
  52. #define  USART_CR3_IREN                      ((uint16_t)0x0002)            /*!<IrDA mode Enable            */
  53. #define  USART_CR3_IRLP                      ((uint16_t)0x0004)            /*!<IrDA Low-Power              */
  54. #define  USART_CR3_HDSEL                     ((uint16_t)0x0008)            /*!<Half-Duplex Selection       */
  55. #define  USART_CR3_NACK                      ((uint16_t)0x0010)            /*!<Smartcard NACK enable       */
  56. #define  USART_CR3_SCEN                      ((uint16_t)0x0020)            /*!<Smartcard mode enable       */
  57. #define  USART_CR3_DMAR                      ((uint16_t)0x0040)            /*!<DMA Enable Receiver         */
  58. #define  USART_CR3_DMAT                      ((uint16_t)0x0080)            /*!<DMA Enable Transmitter      */
  59. #define  USART_CR3_RTSE                      ((uint16_t)0x0100)            /*!<RTS Enable                  */
  60. #define  USART_CR3_CTSE                      ((uint16_t)0x0200)            /*!<CTS Enable                  */
  61. #define  USART_CR3_CTSIE                     ((uint16_t)0x0400)            /*!<CTS Interrupt Enable        */
  62. #define  USART_CR3_ONEBIT                    ((uint16_t)0x0800)            /*!<USART One bit method enable */

  63. /******************  Bit definition for USART_GTPR register  ******************/
  64. #define  USART_GTPR_PSC                      ((uint16_t)0x00FF)            /*!<PSC[7:0] bits (Prescaler value) */
  65. #define  USART_GTPR_PSC_0                    ((uint16_t)0x0001)            /*!<Bit 0 */
  66. #define  USART_GTPR_PSC_1                    ((uint16_t)0x0002)            /*!<Bit 1 */
  67. #define  USART_GTPR_PSC_2                    ((uint16_t)0x0004)            /*!<Bit 2 */
  68. #define  USART_GTPR_PSC_3                    ((uint16_t)0x0008)            /*!<Bit 3 */
  69. #define  USART_GTPR_PSC_4                    ((uint16_t)0x0010)            /*!<Bit 4 */
  70. #define  USART_GTPR_PSC_5                    ((uint16_t)0x0020)            /*!<Bit 5 */
  71. #define  USART_GTPR_PSC_6                    ((uint16_t)0x0040)            /*!<Bit 6 */
  72. #define  USART_GTPR_PSC_7                    ((uint16_t)0x0080)            /*!<Bit 7 */

  73. #define  USART_GTPR_GT                       ((uint16_t)0xFF00)            /*!<Guard time value */
复制代码

04. USART相关函数
  1. /*  Function used to set the USART configuration to the default reset state ***/
  2. void USART_DeInit(USART_TypeDef* USARTx);

  3. /* Initialization and Configuration functions *********************************/
  4. void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);
  5. void USART_StructInit(USART_InitTypeDef* USART_InitStruct);
  6. void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct);
  7. void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct);
  8. void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
  9. void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler);
  10. void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState);
  11. void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState);

  12. /* Data transfers functions ***************************************************/
  13. void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);
  14. uint16_t USART_ReceiveData(USART_TypeDef* USARTx);

  15. /* Multi-Processor Communication functions ************************************/
  16. void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address);
  17. void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp);
  18. void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState);

  19. /* LIN mode functions *********************************************************/
  20. void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength);
  21. void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  22. void USART_SendBreak(USART_TypeDef* USARTx);

  23. /* Half-duplex mode function **************************************************/
  24. void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState);

  25. /* Smartcard mode functions ***************************************************/
  26. void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  27. void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState);
  28. void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime);

  29. /* IrDA mode functions ********************************************************/
  30. void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode);
  31. void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState);

  32. /* DMA transfers management functions *****************************************/
  33. void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);

  34. /* Interrupts and flags management functions **********************************/
  35. void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);
  36. FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);
  37. void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG);
  38. ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);
  39. void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);
复制代码

05. USART其它
USART基地址

  1. #define USART2_BASE           (APB1PERIPH_BASE + 0x4400)
  2. #define USART3_BASE           (APB1PERIPH_BASE + 0x4800)
  3. #define UART4_BASE            (APB1PERIPH_BASE + 0x4C00)
  4. #define UART5_BASE            (APB1PERIPH_BASE + 0x5000)

  5. #define USART1_BASE           (APB2PERIPH_BASE + 0x1000)
  6. #define USART6_BASE           (APB2PERIPH_BASE + 0x1400)
  7. #define UART9_BASE            (APB2PERIPH_BASE + 0x1800U)
  8. #define UART10_BASE           (APB2PERIPH_BASE + 0x1C00U)
复制代码


收藏 评论0 发布时间:2022-6-13 08:56

举报

0个回答

所属标签

相似技术帖

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版