Interrupts and flags management functions.
More...
|
void | SPI_I2S_ITConfig (SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState) |
| Enables or disables the specified SPI/I2S interrupts. More...
|
|
FlagStatus | SPI_I2S_GetFlagStatus (SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG) |
| Checks whether the specified SPIx/I2Sx flag is set or not. More...
|
|
void | SPI_I2S_ClearFlag (SPI_TypeDef *SPIx, uint16_t SPI_I2S_FLAG) |
| Clears the SPIx CRC Error (CRCERR) flag. More...
|
|
ITStatus | SPI_I2S_GetITStatus (SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT) |
| Checks whether the specified SPIx/I2Sx interrupt has occurred or not. More...
|
|
void | SPI_I2S_ClearITPendingBit (SPI_TypeDef *SPIx, uint8_t SPI_I2S_IT) |
| Clears the SPIx CRC Error (CRCERR) interrupt pending bit. More...
|
|
Interrupts and flags management functions.
===============================================================================
Interrupts and flags management functions
===============================================================================
This section provides a set of functions allowing to configure the SPI Interrupts
sources 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/I2S communication can be managed by 9 flags:
1. SPI_I2S_FLAG_TXE : to indicate the status of the transmit buffer register
2. SPI_I2S_FLAG_RXNE : to indicate the status of the receive buffer register
3. SPI_I2S_FLAG_BSY : to indicate the state of the communication layer of the SPI.
4. SPI_FLAG_CRCERR : to indicate if a CRC Calculation error occur
5. SPI_FLAG_MODF : to indicate if a Mode Fault error occur
6. SPI_I2S_FLAG_OVR : to indicate if an Overrun error occur
7. I2S_FLAG_TIFRFE: to indicate a Frame Format error occurs.
8. I2S_FLAG_UDR: to indicate an Underrun error occurs.
9. I2S_FLAG_CHSIDE: to indicate Channel Side.
@note Do not use the BSY flag to handle each data transmission or reception. It is
better to use the TXE and RXNE flags instead.
In this Mode it is advised to use the following functions:
- FlagStatus SPI_I2S_GetFlagStatus(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG);
- void SPI_I2S_ClearFlag(SPI_TypeDef* SPIx, uint16_t SPI_I2S_FLAG);
Interrupt Mode
===============
In Interrupt Mode, the SPI communication can be managed by 3 interrupt sources
and 7 pending bits:
Pending Bits:
-------------
1. SPI_I2S_IT_TXE : to indicate the status of the transmit buffer register
2. SPI_I2S_IT_RXNE : to indicate the status of the receive buffer register
3. SPI_IT_CRCERR : to indicate if a CRC Calculation error occur (available in SPI mode only)
4. SPI_IT_MODF : to indicate if a Mode Fault error occur (available in SPI mode only)
5. SPI_I2S_IT_OVR : to indicate if an Overrun error occur
6. I2S_IT_UDR : to indicate an Underrun Error occurs (available in I2S mode only).
7. I2S_FLAG_TIFRFE : to indicate a Frame Format error occurs (available in TI mode only).
Interrupt Source:
-----------------
1. SPI_I2S_IT_TXE: specifies the interrupt source for the Tx buffer empty
interrupt.
2. SPI_I2S_IT_RXNE : specifies the interrupt source for the Rx buffer not
empty interrupt.
3. SPI_I2S_IT_ERR : specifies the interrupt source for the errors interrupt.
In this Mode it is advised to use the following functions:
- void SPI_I2S_ITConfig(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT, FunctionalState NewState);
- ITStatus SPI_I2S_GetITStatus(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT);
- void SPI_I2S_ClearITPendingBit(SPI_TypeDef* SPIx, uint8_t SPI_I2S_IT);
DMA Mode
========
In DMA Mode, the SPI communication can be managed by 2 DMA Channel requests:
1. SPI_I2S_DMAReq_Tx: specifies the Tx buffer DMA transfer request
2. SPI_I2S_DMAReq_Rx: specifies the Rx buffer DMA transfer request
In this Mode it is advised to use the following function:
- void SPI_I2S_DMACmd(SPI_TypeDef* SPIx, uint16_t SPI_I2S_DMAReq, FunctionalState NewState);
void SPI_I2S_ClearFlag |
( |
SPI_TypeDef * |
SPIx, |
|
|
uint16_t |
SPI_I2S_FLAG |
|
) |
| |
Clears the SPIx CRC Error (CRCERR) flag.
- Parameters
-
SPIx,: | To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3 in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode. |
SPI_I2S_FLAG,: | specifies the SPI flag to clear. This function clears only CRCERR flag.
- SPI_FLAG_CRCERR: CRC Error flag.
|
- Note
- OVR (OverRun error) flag is cleared by software sequence: a read operation to SPI_DR register (SPI_I2S_ReceiveData()) followed by a read operation to SPI_SR register (SPI_I2S_GetFlagStatus()).
-
UDR (UnderRun error) flag is cleared by a read operation to SPI_SR register (SPI_I2S_GetFlagStatus()).
-
MODF (Mode Fault) flag is cleared by software sequence: a read/write operation to SPI_SR register (SPI_I2S_GetFlagStatus()) followed by a write operation to SPI_CR1 register (SPI_Cmd() to enable the SPI).
- Return values
-
void SPI_I2S_ClearITPendingBit |
( |
SPI_TypeDef * |
SPIx, |
|
|
uint8_t |
SPI_I2S_IT |
|
) |
| |
Clears the SPIx CRC Error (CRCERR) interrupt pending bit.
- Parameters
-
SPIx,: | To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3 in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode. |
SPI_I2S_IT,: | specifies the SPI interrupt pending bit to clear. This function clears only CRCERR interrupt pending bit.
- SPI_IT_CRCERR: CRC Error interrupt.
|
- Note
- OVR (OverRun Error) interrupt pending bit is cleared by software sequence: a read operation to SPI_DR register (SPI_I2S_ReceiveData()) followed by a read operation to SPI_SR register (SPI_I2S_GetITStatus()).
-
UDR (UnderRun Error) interrupt pending bit is cleared by a read operation to SPI_SR register (SPI_I2S_GetITStatus()).
-
MODF (Mode Fault) interrupt pending bit is cleared by software sequence: a read/write operation to SPI_SR register (SPI_I2S_GetITStatus()) followed by a write operation to SPI_CR1 register (SPI_Cmd() to enable the SPI).
- Return values
-
FlagStatus SPI_I2S_GetFlagStatus |
( |
SPI_TypeDef * |
SPIx, |
|
|
uint16_t |
SPI_I2S_FLAG |
|
) |
| |
Checks whether the specified SPIx/I2Sx flag is set or not.
- Parameters
-
SPIx,: | To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3 in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode. |
SPI_I2S_FLAG,: | specifies the SPI flag to check. This parameter can be one of the following values:
- SPI_I2S_FLAG_TXE: Transmit buffer empty flag.
- SPI_I2S_FLAG_RXNE: Receive buffer not empty flag.
- SPI_I2S_FLAG_BSY: Busy flag.
- SPI_I2S_FLAG_OVR: Overrun flag.
- SPI_FLAG_MODF: Mode Fault flag.
- SPI_FLAG_CRCERR: CRC Error flag.
- SPI_I2S_FLAG_TIFRFE: Format Error.
- I2S_FLAG_UDR: Underrun Error flag.
- I2S_FLAG_CHSIDE: Channel Side flag.
|
- Return values
-
The | new state of SPI_I2S_FLAG (SET or RESET). |
ITStatus SPI_I2S_GetITStatus |
( |
SPI_TypeDef * |
SPIx, |
|
|
uint8_t |
SPI_I2S_IT |
|
) |
| |
Checks whether the specified SPIx/I2Sx interrupt has occurred or not.
- Parameters
-
SPIx,: | To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3 in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode. |
SPI_I2S_IT,: | specifies the SPI interrupt source to check. This parameter can be one of the following values:
- SPI_I2S_IT_TXE: Transmit buffer empty interrupt.
- SPI_I2S_IT_RXNE: Receive buffer not empty interrupt.
- SPI_I2S_IT_OVR: Overrun interrupt.
- SPI_IT_MODF: Mode Fault interrupt.
- SPI_IT_CRCERR: CRC Error interrupt.
- I2S_IT_UDR: Underrun interrupt.
- SPI_I2S_IT_TIFRFE: Format Error interrupt.
|
- Return values
-
The | new state of SPI_I2S_IT (SET or RESET). |
void SPI_I2S_ITConfig |
( |
SPI_TypeDef * |
SPIx, |
|
|
uint8_t |
SPI_I2S_IT, |
|
|
FunctionalState |
NewState |
|
) |
| |
Enables or disables the specified SPI/I2S interrupts.
- Parameters
-
SPIx,: | To select the SPIx/I2Sx peripheral, where x can be: 1, 2 or 3 in SPI mode or 2 or 3 in I2S mode or I2Sxext for I2S full duplex mode. |
SPI_I2S_IT,: | specifies the SPI interrupt source to be enabled or disabled. This parameter can be one of the following values:
- SPI_I2S_IT_TXE: Tx buffer empty interrupt mask
- SPI_I2S_IT_RXNE: Rx buffer not empty interrupt mask
- SPI_I2S_IT_ERR: Error interrupt mask
|
NewState,: | new state of the specified SPI interrupt. This parameter can be: ENABLE or DISABLE. |
- Return values
-