Interrupts and flags management functions.
More...
Interrupts and flags management functions.
IrDA mode functions.
===============================================================================
##### Interrupts and flags management functions #####
===============================================================================
[..]
This subsection provides a set of functions allowing to configure the USART
Interrupts sources, DMA channels requests and check or clear the flags or
pending bits status.
The user should identify which mode will be used in his application to manage
the communication: Polling mode, Interrupt mode or DMA mode.
*** Polling Mode ***
====================
[..]
In Polling Mode, the SPI communication can be managed by 10 flags:
(#) USART_FLAG_TXE : to indicate the status of the transmit buffer register
(#) USART_FLAG_RXNE : to indicate the status of the receive buffer register
(#) USART_FLAG_TC : to indicate the status of the transmit operation
(#) USART_FLAG_IDLE : to indicate the status of the Idle Line
(#) USART_FLAG_CTS : to indicate the status of the nCTS input
(#) USART_FLAG_LBD : to indicate the status of the LIN break detection
(#) USART_FLAG_NE : to indicate if a noise error occur
(#) USART_FLAG_FE : to indicate if a frame error occur
(#) USART_FLAG_PE : to indicate if a parity error occur
(#) USART_FLAG_ORE : to indicate if an Overrun error occur
[..]
In this Mode it is advised to use the following functions:
(+) FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);
(+) void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG);
*** Interrupt Mode ***
======================
[..]
In Interrupt Mode, the USART communication can be managed by 8 interrupt sources
and 10 pending bits:
(#) Pending Bits:
(##) USART_IT_TXE : to indicate the status of the transmit buffer register
(##) USART_IT_RXNE : to indicate the status of the receive buffer register
(##) USART_IT_TC : to indicate the status of the transmit operation
(##) USART_IT_IDLE : to indicate the status of the Idle Line
(##) USART_IT_CTS : to indicate the status of the nCTS input
(##) USART_IT_LBD : to indicate the status of the LIN break detection
(##) USART_IT_NE : to indicate if a noise error occur
(##) USART_IT_FE : to indicate if a frame error occur
(##) USART_IT_PE : to indicate if a parity error occur
(##) USART_IT_ORE : to indicate if an Overrun error occur
(#) Interrupt Source:
(##) USART_IT_TXE : specifies the interrupt source for the Tx buffer empty
interrupt.
(##) USART_IT_RXNE : specifies the interrupt source for the Rx buffer not
empty interrupt.
(##) USART_IT_TC : specifies the interrupt source for the Transmit complete
interrupt.
(##) USART_IT_IDLE : specifies the interrupt source for the Idle Line interrupt.
(##) USART_IT_CTS : specifies the interrupt source for the CTS interrupt.
(##) USART_IT_LBD : specifies the interrupt source for the LIN break detection
interrupt.
(##) USART_IT_PE : specifies the interrupt source for the parity error interrupt.
(##) USART_IT_ERR : specifies the interrupt source for the errors interrupt.
-@@- Some parameters are coded in order to use them as interrupt source
or as pending bits.
[..]
In this Mode it is advised to use the following functions:
(+) void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState);
(+) ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT);
(+) void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);
*** DMA Mode ***
================
[..]
In DMA Mode, the USART communication can be managed by 2 DMA Channel requests:
(#) USART_DMAReq_Tx: specifies the Tx buffer DMA transfer request
(#) USART_DMAReq_Rx: specifies the Rx buffer DMA transfer request
[..]
In this Mode it is advised to use the following function:
(+) void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState);
===============================================================================
##### IrDA mode functions #####
===============================================================================
[..] This subsection provides a set of functions allowing to manage the USART
IrDA communication.
[..] IrDA is a half duplex communication protocol. If the Transmitter is busy,
any data on the IrDA receive line will be ignored by the IrDA decoder
and if the Receiver is busy, data on the TX from the USART to IrDA will
not be encoded by IrDA. While receiving data, transmission should be
avoided as the data to be transmitted could be corrupted.
[..] IrDA communication is possible through the following procedure:
(#) Program the Baud rate, Word length = 8 bits, Stop bits, Parity,
Transmitter/Receiver modes and hardware flow control values using
the USART_Init() function.
(#) Configures the IrDA pulse width by configuring the prescaler using
the USART_SetPrescaler() function.
(#) Configures the IrDA USART_IrDAMode_LowPower or USART_IrDAMode_Normal
mode using the USART_IrDAConfig() function.
(#) Enable the IrDA using the USART_IrDACmd() function.
(#) Enable the USART using the USART_Cmd() function.
[..]
(@) A pulse of width less than two and greater than one PSC period(s) may or
may not be rejected.
(@) The receiver set up time should be managed by software. The IrDA physical
layer specification specifies a minimum of 10 ms delay between
transmission and reception (IrDA is a half duplex protocol).
(@) In IrDA mode, the following bits must be kept cleared:
(+@) LINEN, STOP and CLKEN bits in the USART_CR2 register.
(+@) SCEN and HDSEL bits in the USART_CR3 register.
void USART_ClearFlag |
( |
USART_TypeDef * |
USARTx, |
|
|
uint16_t |
USART_FLAG |
|
) |
| |
Clears the USARTx's pending flags.
- Parameters
-
USARTx | where x can be 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or UART peripheral. |
USART_FLAG | specifies the flag to clear. This parameter can be any combination of the following values:
- USART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5).
- USART_FLAG_LBD: LIN Break detection flag.
- USART_FLAG_TC: Transmission Complete flag.
- USART_FLAG_RXNE: Receive data register not empty flag.
|
- Note
- PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun error) and IDLE (Idle line detected) flags are cleared by software sequence: a read operation to USART_SR register (USART_GetFlagStatus()) followed by a read operation to USART_DR register (USART_ReceiveData()).
-
RXNE flag can be also cleared by a read to the USART_DR register (USART_ReceiveData()).
-
TC flag can be also cleared by software sequence: a read operation to USART_SR register (USART_GetFlagStatus()) followed by a write operation to USART_DR register (USART_SendData()).
-
TXE flag is cleared only by a write to the USART_DR register (USART_SendData()).
- Return values
-
Definition at line 1344 of file stm32f4xx_usart.c.
void USART_ClearITPendingBit |
( |
USART_TypeDef * |
USARTx, |
|
|
uint16_t |
USART_IT |
|
) |
| |
Clears the USARTx's interrupt pending bits.
- Parameters
-
USARTx | where x can be 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or UART peripheral. |
USART_IT | specifies the interrupt pending bit to clear. This parameter can be one of the following values:
- USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
- USART_IT_LBD: LIN Break detection interrupt
- USART_IT_TC: Transmission complete interrupt.
- USART_IT_RXNE: Receive Data register not empty interrupt.
|
- Note
- PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun error) and IDLE (Idle line detected) pending bits are cleared by software sequence: a read operation to USART_SR register (USART_GetITStatus()) followed by a read operation to USART_DR register (USART_ReceiveData()).
-
RXNE pending bit can be also cleared by a read to the USART_DR register (USART_ReceiveData()).
-
TC pending bit can be also cleared by software sequence: a read operation to USART_SR register (USART_GetITStatus()) followed by a write operation to USART_DR register (USART_SendData()).
-
TXE pending bit is cleared only by a write to the USART_DR register (USART_SendData()).
- Return values
-
Definition at line 1452 of file stm32f4xx_usart.c.
Checks whether the specified USART flag is set or not.
- Parameters
-
USARTx | where x can be 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or UART peripheral. |
USART_FLAG | specifies the flag to check. This parameter can be one of the following values:
- USART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5)
- USART_FLAG_LBD: LIN Break detection flag
- USART_FLAG_TXE: Transmit data register empty flag
- USART_FLAG_TC: Transmission Complete flag
- USART_FLAG_RXNE: Receive data register not empty flag
- USART_FLAG_IDLE: Idle Line detection flag
- USART_FLAG_ORE: OverRun Error flag
- USART_FLAG_NE: Noise Error flag
- USART_FLAG_FE: Framing Error flag
- USART_FLAG_PE: Parity Error flag
|
- Return values
-
The | new state of USART_FLAG (SET or RESET). |
Definition at line 1295 of file stm32f4xx_usart.c.
Checks whether the specified USART interrupt has occurred or not.
- Parameters
-
USARTx | where x can be 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or UART peripheral. |
USART_IT | specifies the USART interrupt source to check. This parameter can be one of the following values:
- USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
- USART_IT_LBD: LIN Break detection interrupt
- USART_IT_TXE: Transmit Data Register empty interrupt
- USART_IT_TC: Transmission complete interrupt
- USART_IT_RXNE: Receive Data register not empty interrupt
- USART_IT_IDLE: Idle line detection interrupt
- USART_IT_ORE_RX : OverRun Error interrupt if the RXNEIE bit is set
- USART_IT_ORE_ER : OverRun Error interrupt if the EIE bit is set
- USART_IT_NE: Noise Error interrupt
- USART_IT_FE: Framing Error interrupt
- USART_IT_PE: Parity Error interrupt
|
- Return values
-
The | new state of USART_IT (SET or RESET). |
Definition at line 1378 of file stm32f4xx_usart.c.
Enables or disables the USART's IrDA interface.
- Parameters
-
USARTx | Select the USART peripheral. This parameter can be one of the following values: USART1 or USART2 or USART3 or UART4 or UART5. |
NewState | new state of the IrDA mode. This parameter can be: ENABLE or DISABLE. |
- Return values
-
Definition at line 1437 of file stm32f30x_usart.c.
void USART_IrDAConfig |
( |
USART_TypeDef * |
USARTx, |
|
|
uint32_t |
USART_IrDAMode |
|
) |
| |
Configures the USART's IrDA interface.
- Parameters
-
USARTx | Select the USART peripheral. This parameter can be one of the following values: USART1 or USART2 or USART3 or UART4 or UART5. |
USART_IrDAMode | specifies the IrDA mode. This parameter can be one of the following values:
- USART_IrDAMode_LowPower
- USART_IrDAMode_Normal
|
- Return values
-
Definition at line 1419 of file stm32f30x_usart.c.
Enables or disables the specified USART interrupts.
- Parameters
-
USARTx | where x can be 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or UART peripheral. |
USART_IT | specifies the USART interrupt sources to be enabled or disabled. This parameter can be one of the following values:
- USART_IT_CTS: CTS change interrupt
- USART_IT_LBD: LIN Break detection interrupt
- USART_IT_TXE: Transmit Data Register empty interrupt
- USART_IT_TC: Transmission complete interrupt
- USART_IT_RXNE: Receive Data register not empty interrupt
- USART_IT_IDLE: Idle line detection interrupt
- USART_IT_PE: Parity Error interrupt
- USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
|
NewState | new state of the specified USARTx interrupts. This parameter can be: ENABLE or DISABLE. |
- Return values
-
Definition at line 1231 of file stm32f4xx_usart.c.