Interrupts and flags management functions.
More...
|
void | USART_ITConfig (USART_TypeDef *USARTx, uint16_t USART_IT, FunctionalState NewState) |
| Enables or disables the specified USART interrupts. More...
|
|
FlagStatus | USART_GetFlagStatus (USART_TypeDef *USARTx, uint16_t USART_FLAG) |
| Checks whether the specified USART flag is set or not. More...
|
|
void | USART_ClearFlag (USART_TypeDef *USARTx, uint16_t USART_FLAG) |
| Clears the USARTx's pending flags. More...
|
|
ITStatus | USART_GetITStatus (USART_TypeDef *USARTx, uint16_t USART_IT) |
| Checks whether the specified USART interrupt has occurred or not. More...
|
|
void | USART_ClearITPendingBit (USART_TypeDef *USARTx, uint16_t USART_IT) |
| Clears the USARTx's interrupt pending bits. More...
|
|
Interrupts and flags management 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:
1. USART_FLAG_TXE : to indicate the status of the transmit buffer register
2. USART_FLAG_RXNE : to indicate the status of the receive buffer register
3. USART_FLAG_TC : to indicate the status of the transmit operation
4. USART_FLAG_IDLE : to indicate the status of the Idle Line
5. USART_FLAG_CTS : to indicate the status of the nCTS input
6. USART_FLAG_LBD : to indicate the status of the LIN break detection
7. USART_FLAG_NE : to indicate if a noise error occur
8. USART_FLAG_FE : to indicate if a frame error occur
9. USART_FLAG_PE : to indicate if a parity error occur
10. 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:
-------------
1. USART_IT_TXE : to indicate the status of the transmit buffer register
2. USART_IT_RXNE : to indicate the status of the receive buffer register
3. USART_IT_TC : to indicate the status of the transmit operation
4. USART_IT_IDLE : to indicate the status of the Idle Line
5. USART_IT_CTS : to indicate the status of the nCTS input
6. USART_IT_LBD : to indicate the status of the LIN break detection
7. USART_IT_NE : to indicate if a noise error occur
8. USART_IT_FE : to indicate if a frame error occur
9. USART_IT_PE : to indicate if a parity error occur
10. USART_IT_ORE : to indicate if an Overrun error occur
Interrupt Source:
-----------------
1. USART_IT_TXE : specifies the interrupt source for the Tx buffer empty
interrupt.
2. USART_IT_RXNE : specifies the interrupt source for the Rx buffer not
empty interrupt.
3. USART_IT_TC : specifies the interrupt source for the Transmit complete
interrupt.
4. USART_IT_IDLE : specifies the interrupt source for the Idle Line interrupt.
5. USART_IT_CTS : specifies the interrupt source for the CTS interrupt.
6. USART_IT_LBD : specifies the interrupt source for the LIN break detection
interrupt.
7. USART_IT_PE : specifies the interrupt source for the parity error interrupt.
8. USART_IT_ERR : specifies the interrupt source for the errors interrupt.
@note 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:
1. USART_DMAReq_Tx: specifies the Tx buffer DMA transfer request
2. 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);
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 or 6 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
-
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 or 6 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
-
FlagStatus USART_GetFlagStatus |
( |
USART_TypeDef * |
USARTx, |
|
|
uint16_t |
USART_FLAG |
|
) |
| |
Checks whether the specified USART flag is set or not.
- Parameters
-
USARTx,: | where x can be 1, 2, 3, 4, 5 or 6 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). |
ITStatus USART_GetITStatus |
( |
USART_TypeDef * |
USARTx, |
|
|
uint16_t |
USART_IT |
|
) |
| |
Checks whether the specified USART interrupt has occurred or not.
- Parameters
-
USARTx,: | where x can be 1, 2, 3, 4, 5 or 6 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). |
void USART_ITConfig |
( |
USART_TypeDef * |
USARTx, |
|
|
uint16_t |
USART_IT, |
|
|
FunctionalState |
NewState |
|
) |
| |
Enables or disables the specified USART interrupts.
- Parameters
-
USARTx,: | where x can be 1, 2, 3, 4, 5 or 6 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
-