30 #ifndef __STM32F30x_USART_H 31 #define __STM32F30x_USART_H 38 #include "stm32f30x.h" 58 uint32_t USART_BaudRate;
110 #define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART1) || \ 111 ((PERIPH) == USART2) || \ 112 ((PERIPH) == USART3) || \ 113 ((PERIPH) == UART4) || \ 116 #define IS_USART_123_PERIPH(PERIPH) (((PERIPH) == USART1) || \ 117 ((PERIPH) == USART2) || \ 118 ((PERIPH) == USART3)) 120 #define IS_USART_1234_PERIPH(PERIPH) (((PERIPH) == USART1) || \ 121 ((PERIPH) == USART2) || \ 122 ((PERIPH) == USART3) || \ 130 #define USART_WordLength_8b ((uint32_t)0x00000000) 131 #define USART_WordLength_9b USART_CR1_M 132 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WordLength_8b) || \ 133 ((LENGTH) == USART_WordLength_9b)) 142 #define USART_StopBits_1 ((uint32_t)0x00000000) 143 #define USART_StopBits_2 USART_CR2_STOP_1 144 #define USART_StopBits_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) 145 #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \ 146 ((STOPBITS) == USART_StopBits_2) || \ 147 ((STOPBITS) == USART_StopBits_1_5)) 156 #define USART_Parity_No ((uint32_t)0x00000000) 157 #define USART_Parity_Even USART_CR1_PCE 158 #define USART_Parity_Odd (USART_CR1_PCE | USART_CR1_PS) 159 #define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_No) || \ 160 ((PARITY) == USART_Parity_Even) || \ 161 ((PARITY) == USART_Parity_Odd)) 170 #define USART_Mode_Rx USART_CR1_RE 171 #define USART_Mode_Tx USART_CR1_TE 172 #define IS_USART_MODE(MODE) ((((MODE) & (uint32_t)0xFFFFFFF3) == 0x00) && \ 173 ((MODE) != (uint32_t)0x00)) 182 #define USART_HardwareFlowControl_None ((uint32_t)0x00000000) 183 #define USART_HardwareFlowControl_RTS USART_CR3_RTSE 184 #define USART_HardwareFlowControl_CTS USART_CR3_CTSE 185 #define USART_HardwareFlowControl_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE) 186 #define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)\ 187 (((CONTROL) == USART_HardwareFlowControl_None) || \ 188 ((CONTROL) == USART_HardwareFlowControl_RTS) || \ 189 ((CONTROL) == USART_HardwareFlowControl_CTS) || \ 190 ((CONTROL) == USART_HardwareFlowControl_RTS_CTS)) 199 #define USART_Clock_Disable ((uint32_t)0x00000000) 200 #define USART_Clock_Enable USART_CR2_CLKEN 201 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_Clock_Disable) || \ 202 ((CLOCK) == USART_Clock_Enable)) 211 #define USART_CPOL_Low ((uint32_t)0x00000000) 212 #define USART_CPOL_High USART_CR2_CPOL 213 #define IS_USART_CPOL(CPOL) (((CPOL) == USART_CPOL_Low) || ((CPOL) == USART_CPOL_High)) 223 #define USART_CPHA_1Edge ((uint32_t)0x00000000) 224 #define USART_CPHA_2Edge USART_CR2_CPHA 225 #define IS_USART_CPHA(CPHA) (((CPHA) == USART_CPHA_1Edge) || ((CPHA) == USART_CPHA_2Edge)) 235 #define USART_LastBit_Disable ((uint32_t)0x00000000) 236 #define USART_LastBit_Enable USART_CR2_LBCL 237 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LastBit_Disable) || \ 238 ((LASTBIT) == USART_LastBit_Enable)) 247 #define USART_DMAReq_Tx USART_CR3_DMAT 248 #define USART_DMAReq_Rx USART_CR3_DMAR 249 #define IS_USART_DMAREQ(DMAREQ) ((((DMAREQ) & (uint32_t)0xFFFFFF3F) == 0x00) && \ 250 ((DMAREQ) != (uint32_t)0x00)) 260 #define USART_DMAOnError_Enable ((uint32_t)0x00000000) 261 #define USART_DMAOnError_Disable USART_CR3_DDRE 262 #define IS_USART_DMAONERROR(DMAERROR) (((DMAERROR) == USART_DMAOnError_Disable)|| \ 263 ((DMAERROR) == USART_DMAOnError_Enable)) 272 #define USART_WakeUp_IdleLine ((uint32_t)0x00000000) 273 #define USART_WakeUp_AddressMark USART_CR1_WAKE 274 #define IS_USART_MUTEMODE_WAKEUP(WAKEUP) (((WAKEUP) == USART_WakeUp_IdleLine) || \ 275 ((WAKEUP) == USART_WakeUp_AddressMark)) 284 #define USART_AddressLength_4b ((uint32_t)0x00000000) 285 #define USART_AddressLength_7b USART_CR2_ADDM7 286 #define IS_USART_ADDRESS_DETECTION(ADDRESS) (((ADDRESS) == USART_AddressLength_4b) || \ 287 ((ADDRESS) == USART_AddressLength_7b)) 296 #define USART_WakeUpSource_AddressMatch ((uint32_t)0x00000000) 297 #define USART_WakeUpSource_StartBit USART_CR3_WUS_1 298 #define USART_WakeUpSource_RXNE (uint32_t)(USART_CR3_WUS_0 | USART_CR3_WUS_1) 299 #define IS_USART_STOPMODE_WAKEUPSOURCE(SOURCE) (((SOURCE) == USART_WakeUpSource_AddressMatch) || \ 300 ((SOURCE) == USART_WakeUpSource_StartBit) || \ 301 ((SOURCE) == USART_WakeUpSource_RXNE)) 310 #define USART_LINBreakDetectLength_10b ((uint32_t)0x00000000) 311 #define USART_LINBreakDetectLength_11b USART_CR2_LBDL 312 #define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH) \ 313 (((LENGTH) == USART_LINBreakDetectLength_10b) || \ 314 ((LENGTH) == USART_LINBreakDetectLength_11b)) 323 #define USART_IrDAMode_LowPower USART_CR3_IRLP 324 #define USART_IrDAMode_Normal ((uint32_t)0x00000000) 325 #define IS_USART_IRDA_MODE(MODE) (((MODE) == USART_IrDAMode_LowPower) || \ 326 ((MODE) == USART_IrDAMode_Normal)) 335 #define USART_DEPolarity_High ((uint32_t)0x00000000) 336 #define USART_DEPolarity_Low USART_CR3_DEP 337 #define IS_USART_DE_POLARITY(POLARITY) (((POLARITY) == USART_DEPolarity_Low) || \ 338 ((POLARITY) == USART_DEPolarity_High)) 347 #define USART_InvPin_Tx USART_CR2_TXINV 348 #define USART_InvPin_Rx USART_CR2_RXINV 349 #define IS_USART_INVERSTION_PIN(PIN) ((((PIN) & (uint32_t)0xFFFCFFFF) == 0x00) && \ 350 ((PIN) != (uint32_t)0x00)) 360 #define USART_AutoBaudRate_StartBit ((uint32_t)0x00000000) 361 #define USART_AutoBaudRate_FallingEdge USART_CR2_ABRMODE_0 362 #define USART_AutoBaudRate_0x7FFrame USART_CR2_ABRMODE_1 363 #define USART_AutoBaudRate_0x55Frame (USART_CR2_ABRMODE_0 | USART_CR2_ABRMODE_1) 364 #define IS_USART_AUTOBAUDRATE_MODE(MODE) (((MODE) == USART_AutoBaudRate_StartBit) || \ 365 ((MODE) == USART_AutoBaudRate_FallingEdge) || \ 366 ((MODE) == USART_AutoBaudRate_0x7FFrame) || \ 367 ((MODE) == USART_AutoBaudRate_0x55Frame)) 376 #define USART_OVRDetection_Enable ((uint32_t)0x00000000) 377 #define USART_OVRDetection_Disable USART_CR3_OVRDIS 378 #define IS_USART_OVRDETECTION(OVR) (((OVR) == USART_OVRDetection_Enable)|| \ 379 ((OVR) == USART_OVRDetection_Disable)) 387 #define USART_Request_ABRRQ USART_RQR_ABRRQ 388 #define USART_Request_SBKRQ USART_RQR_SBKRQ 389 #define USART_Request_MMRQ USART_RQR_MMRQ 390 #define USART_Request_RXFRQ USART_RQR_RXFRQ 391 #define USART_Request_TXFRQ USART_RQR_TXFRQ 393 #define IS_USART_REQUEST(REQUEST) (((REQUEST) == USART_Request_TXFRQ) || \ 394 ((REQUEST) == USART_Request_RXFRQ) || \ 395 ((REQUEST) == USART_Request_MMRQ) || \ 396 ((REQUEST) == USART_Request_SBKRQ) || \ 397 ((REQUEST) == USART_Request_ABRRQ)) 405 #define USART_FLAG_REACK USART_ISR_REACK 406 #define USART_FLAG_TEACK USART_ISR_TEACK 407 #define USART_FLAG_WU USART_ISR_WUF 408 #define USART_FLAG_RWU USART_ISR_RWU 409 #define USART_FLAG_SBK USART_ISR_SBKF 410 #define USART_FLAG_CM USART_ISR_CMF 411 #define USART_FLAG_BUSY USART_ISR_BUSY 412 #define USART_FLAG_ABRF USART_ISR_ABRF 413 #define USART_FLAG_ABRE USART_ISR_ABRE 414 #define USART_FLAG_EOB USART_ISR_EOBF 415 #define USART_FLAG_RTO USART_ISR_RTOF 416 #define USART_FLAG_nCTSS USART_ISR_CTS 417 #define USART_FLAG_CTS USART_ISR_CTSIF 418 #define USART_FLAG_LBD USART_ISR_LBD 419 #define USART_FLAG_TXE USART_ISR_TXE 420 #define USART_FLAG_TC USART_ISR_TC 421 #define USART_FLAG_RXNE USART_ISR_RXNE 422 #define USART_FLAG_IDLE USART_ISR_IDLE 423 #define USART_FLAG_ORE USART_ISR_ORE 424 #define USART_FLAG_NE USART_ISR_NE 425 #define USART_FLAG_FE USART_ISR_FE 426 #define USART_FLAG_PE USART_ISR_PE 427 #define IS_USART_FLAG(FLAG) (((FLAG) == USART_FLAG_PE) || ((FLAG) == USART_FLAG_TXE) || \ 428 ((FLAG) == USART_FLAG_TC) || ((FLAG) == USART_FLAG_RXNE) || \ 429 ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_LBD) || \ 430 ((FLAG) == USART_FLAG_CTS) || ((FLAG) == USART_FLAG_ORE) || \ 431 ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE) || \ 432 ((FLAG) == USART_FLAG_nCTSS) || ((FLAG) == USART_FLAG_RTO) || \ 433 ((FLAG) == USART_FLAG_EOB) || ((FLAG) == USART_FLAG_ABRE) || \ 434 ((FLAG) == USART_FLAG_ABRF) || ((FLAG) == USART_FLAG_BUSY) || \ 435 ((FLAG) == USART_FLAG_CM) || ((FLAG) == USART_FLAG_SBK) || \ 436 ((FLAG) == USART_FLAG_RWU) || ((FLAG) == USART_FLAG_WU) || \ 437 ((FLAG) == USART_FLAG_TEACK)|| ((FLAG) == USART_FLAG_REACK)) 439 #define IS_USART_CLEAR_FLAG(FLAG) (((FLAG) == USART_FLAG_WU) || ((FLAG) == USART_FLAG_TC) || \ 440 ((FLAG) == USART_FLAG_IDLE) || ((FLAG) == USART_FLAG_ORE) || \ 441 ((FLAG) == USART_FLAG_NE) || ((FLAG) == USART_FLAG_FE) || \ 442 ((FLAG) == USART_FLAG_LBD) || ((FLAG) == USART_FLAG_CTS) || \ 443 ((FLAG) == USART_FLAG_RTO) || ((FLAG) == USART_FLAG_EOB) || \ 444 ((FLAG) == USART_FLAG_CM) || ((FLAG) == USART_FLAG_PE)) 459 #define USART_IT_WU ((uint32_t)0x00140316) 460 #define USART_IT_CM ((uint32_t)0x0011010E) 461 #define USART_IT_EOB ((uint32_t)0x000C011B) 462 #define USART_IT_RTO ((uint32_t)0x000B011A) 463 #define USART_IT_PE ((uint32_t)0x00000108) 464 #define USART_IT_TXE ((uint32_t)0x00070107) 465 #define USART_IT_TC ((uint32_t)0x00060106) 466 #define USART_IT_RXNE ((uint32_t)0x00050105) 467 #define USART_IT_IDLE ((uint32_t)0x00040104) 468 #define USART_IT_LBD ((uint32_t)0x00080206) 469 #define USART_IT_CTS ((uint32_t)0x0009030A) 470 #define USART_IT_ERR ((uint32_t)0x00000300) 471 #define USART_IT_ORE ((uint32_t)0x00030300) 472 #define USART_IT_NE ((uint32_t)0x00020300) 473 #define USART_IT_FE ((uint32_t)0x00010300) 475 #define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \ 476 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \ 477 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \ 478 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR) || \ 479 ((IT) == USART_IT_RTO) || ((IT) == USART_IT_EOB) || \ 480 ((IT) == USART_IT_CM) || ((IT) == USART_IT_WU)) 482 #define IS_USART_GET_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \ 483 ((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \ 484 ((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \ 485 ((IT) == USART_IT_CTS) || ((IT) == USART_IT_ORE) || \ 486 ((IT) == USART_IT_NE) || ((IT) == USART_IT_FE) || \ 487 ((IT) == USART_IT_RTO) || ((IT) == USART_IT_EOB) || \ 488 ((IT) == USART_IT_CM) || ((IT) == USART_IT_WU)) 490 #define IS_USART_CLEAR_IT(IT) (((IT) == USART_IT_TC) || ((IT) == USART_IT_PE) || \ 491 ((IT) == USART_IT_FE) || ((IT) == USART_IT_NE) || \ 492 ((IT) == USART_IT_ORE) || ((IT) == USART_IT_IDLE) || \ 493 ((IT) == USART_IT_LBD) || ((IT) == USART_IT_CTS) || \ 494 ((IT) == USART_IT_RTO) || ((IT) == USART_IT_EOB) || \ 495 ((IT) == USART_IT_CM) || ((IT) == USART_IT_WU)) 504 #define IS_USART_BAUDRATE(BAUDRATE) (((BAUDRATE) > 0) && ((BAUDRATE) < 0x005B8D81)) 505 #define IS_USART_DE_ASSERTION_DEASSERTION_TIME(TIME) ((TIME) <= 0x1F) 506 #define IS_USART_AUTO_RETRY_COUNTER(COUNTER) ((COUNTER) <= 0x7) 507 #define IS_USART_TIMEOUT(TIMEOUT) ((TIMEOUT) <= 0x00FFFFFF) 508 #define IS_USART_DATA(DATA) ((DATA) <= 0x1FF) void USART_AddressDetectionConfig(USART_TypeDef *USARTx, uint32_t USART_AddressLength)
Configure the the USART Address detection length.
void USART_IrDAConfig(USART_TypeDef *USARTx, uint32_t USART_IrDAMode)
Configures the USART's IrDA interface.
void USART_AutoBaudRateConfig(USART_TypeDef *USARTx, uint32_t USART_AutoBaudRate)
Selects the USART auto baud rate method.
void USART_OverrunDetectionConfig(USART_TypeDef *USARTx, uint32_t USART_OVRDetection)
Enables or disables the USART's Overrun detection.
void USART_ITConfig(USART_TypeDef *USARTx, uint32_t USART_IT, FunctionalState NewState)
Enables or disables the specified USART interrupts.
uint32_t USART_HardwareFlowControl
void USART_SetDEAssertionTime(USART_TypeDef *USARTx, uint32_t USART_DEAssertionTime)
Sets the specified RS485 DE assertion time.
void USART_StopModeWakeUpSourceConfig(USART_TypeDef *USARTx, uint32_t USART_WakeUpSource)
Selects the USART WakeUp method form stop mode.
Universal Synchronous Asynchronous Receiver Transmitter.
void USART_SetDEDeassertionTime(USART_TypeDef *USARTx, uint32_t USART_DEDeassertionTime)
Sets the specified RS485 DE deassertion time.
void USART_DataInvCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the binary data inversion.
void USART_SWAPPinCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the swap Tx/Rx pins.
void USART_DeInit(USART_TypeDef *USARTx)
Deinitializes the USARTx peripheral registers to their default reset values.
void USART_DirectionModeCmd(USART_TypeDef *USARTx, uint32_t USART_DirectionMode, FunctionalState NewState)
Enables or disables the USART's transmitter or receiver.
void USART_MSBFirstCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's most significant bit first transmitted/received following the start b...
void USART_LINBreakDetectLengthConfig(USART_TypeDef *USARTx, uint32_t USART_LINBreakDetectLength)
Sets the USART LIN Break detection length.
void USART_ClearFlag(USART_TypeDef *USARTx, uint32_t USART_FLAG)
Clears the USARTx's pending flags.
void USART_OverSampling8Cmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's 8x oversampling mode.
FlagStatus USART_GetFlagStatus(USART_TypeDef *USARTx, uint32_t USART_FLAG)
Checks whether the specified USART flag is set or not.
void USART_InvPinCmd(USART_TypeDef *USARTx, uint32_t USART_InvPin, FunctionalState NewState)
Enables or disables the Pin(s) active level inversion.
uint16_t USART_ReceiveData(USART_TypeDef *USARTx)
Returns the most recent received data by the USARTx peripheral.
void USART_SetAutoRetryCount(USART_TypeDef *USARTx, uint8_t USART_AutoCount)
Sets the Smart Card number of retries in transmit and receive.
void USART_OneBitMethodCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's one bit sampling method.
USART Clock Init Structure definition.
void USART_DECmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's DE functionality.
void USART_SetPrescaler(USART_TypeDef *USARTx, uint8_t USART_Prescaler)
Sets the system clock prescaler.
void USART_MuteModeCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's mute mode.
void USART_DMACmd(USART_TypeDef *USARTx, uint32_t USART_DMAReq, FunctionalState NewState)
Enables or disables the USART's DMA interface.
void USART_ReceiverTimeOutCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the receiver Time Out feature.
void USART_StructInit(USART_InitTypeDef *USART_InitStruct)
Fills each USART_InitStruct member with its default value.
void USART_HalfDuplexCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's Half Duplex communication.
void USART_STOPModeCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the specified USART peripheral in STOP Mode.
void USART_Init(USART_TypeDef *USARTx, USART_InitTypeDef *USART_InitStruct)
Initializes the USARTx peripheral according to the specified parameters in the USART_InitStruct ...
uint32_t USART_WordLength
void USART_DMAReceptionErrorConfig(USART_TypeDef *USARTx, uint32_t USART_DMAOnError)
Enables or disables the USART's DMA interface when reception error occurs.
void USART_LINCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's LIN mode.
void USART_Cmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the specified USART peripheral.
void USART_MuteModeWakeUpConfig(USART_TypeDef *USARTx, uint32_t USART_WakeUp)
Selects the USART WakeUp method from mute mode.
void USART_ClearITPendingBit(USART_TypeDef *USARTx, uint32_t USART_IT)
Clears the USARTx's interrupt pending bits.
void USART_SmartCardNACKCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables NACK transmission.
ITStatus USART_GetITStatus(USART_TypeDef *USARTx, uint32_t USART_IT)
Checks whether the specified USART interrupt has occurred or not.
void USART_SetBlockLength(USART_TypeDef *USARTx, uint8_t USART_BlockLength)
Sets the Smart Card Block length.
void USART_SetReceiverTimeOut(USART_TypeDef *USARTx, uint32_t USART_ReceiverTimeOut)
Sets the receiver Time Out value.
void USART_ClockInit(USART_TypeDef *USARTx, USART_ClockInitTypeDef *USART_ClockInitStruct)
Initializes the USARTx peripheral Clock according to the specified parameters in the USART_ClockInitS...
void USART_AutoBaudRateCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the Auto Baud Rate.
void USART_DEPolarityConfig(USART_TypeDef *USARTx, uint32_t USART_DEPolarity)
Configures the USART's DE polarity.
USART Init Structure definition.
void USART_SetAddress(USART_TypeDef *USARTx, uint8_t USART_Address)
Sets the address of the USART node.
void USART_IrDACmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's IrDA interface.
void USART_ClockStructInit(USART_ClockInitTypeDef *USART_ClockInitStruct)
Fills each USART_ClockInitStruct member with its default value.
void USART_SmartCardCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's Smart Card mode.
void USART_RequestCmd(USART_TypeDef *USARTx, uint32_t USART_Request, FunctionalState NewState)
Enables the specified USART's Request.
void USART_SetGuardTime(USART_TypeDef *USARTx, uint8_t USART_GuardTime)
Sets the specified USART guard time.
void USART_SendData(USART_TypeDef *USARTx, uint16_t Data)
Transmits single data through the USARTx peripheral.