📄 91x_ssp.c
字号:
{
if(NewState == ENABLE)
{
/* Enable the selected SSP interrupts */
SSPx->IMSCR |= SSP_IT;
}
else
{
/* Disable the selected SSP interrupts */
SSPx->IMSCR &= ~SSP_IT;
}
}
/*******************************************************************************
* Function Name : SSP_DMACmd
* Description : Configures the SSP0 DMA interface.
* Input : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
* - SSP_DMATransfert : specifies the DMA transfert to be
* enabled or disabled. This parameter can be one of the
* following values:
* - SSP_DMA_Transmit: transmit Fifo DMA transfert
* - SSP_DMA_Receive : receive Fifo DMA transfert
* - NewState: new state of the DMA transfert.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void SSP_DMACmd(SSP_TypeDef* SSPx, u16 SSP_DMATransfert, FunctionalState NewState)
{
if(NewState == ENABLE)
{
if(SSP_DMATransfert == SSP_DMA_Transmit)
{
/* Enable DMA for the transmit FIFO */
SSPx->DMACR |= SSP_DMA_TransmitEnable;
}
else
{
/* Enable DMA for the receive FIFO */
SSPx->DMACR |= SSP_DMA_ReceiveEnable;
}
}
else
{
if(SSP_DMATransfert == SSP_DMA_Transmit)
{
/* Disable DMA for the transmit FIFO */
SSPx->DMACR &= SSP_DMA_TransmitDisable;
}
else
{
/* Disable DMA for the receive FIFO */
SSPx->DMACR &= SSP_DMA_ReceiveDisable;
}
}
}
/*******************************************************************************
* Function Name : SSP_SendData.
* Description : Transmits a Data through the SSP peripheral.
* Input : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
* - Data : Data to be transmitted.
* Output : None
* Return : None
*******************************************************************************/
void SSP_SendData(SSP_TypeDef* SSPx, u16 Data)
{
/* Write in the DR register the data to be sent */
SSPx->DR = Data;
}
/*******************************************************************************
* Function Name : SSP_ReceiveData.
* Description : Returns the most recent received data by the SSP peripheral.
* Input : SSPx: where x can be 0 or 1 to select the SSP peripheral.
* Output : None
* Return : The value of the received data.
*******************************************************************************/
u16 SSP_ReceiveData(SSP_TypeDef* SSPx)
{
/* Return the data in the DR register */
return SSPx->DR;
}
/*******************************************************************************
* Function Name : SSP_LoopBackConfig
* Description : Enable or disable the Loop back mode for the selected SSPx peripheral.
* Input : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
* - NewState: new state of the Loop Back mode.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None.
*******************************************************************************/
void SSP_LoopBackConfig(SSP_TypeDef* SSPx, FunctionalState NewState)
{
if(NewState == ENABLE)
{
/* Enable loop back mode */
SSPx->CR1 |= SSP_LoopBackMode_Enable;
}
else
{
/* Disable loop back mode */
SSPx->CR1 &= SSP_LoopBackMode_Disable;
}
}
/*******************************************************************************
* Function Name : SSP_GetFlagStatus
* Description : Checks whether the specified SSP flag is set or not.
* Input : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
* - SSP_FLAG: flag to check. This parameter can be one of the
* following values:
* - SSP_FLAG_Busy: busy flag
* - SSP_FLAG_RxFifoFull: Receive FIFO full flag
* - SSP_FLAG_RxFifoNotEmpty: Receive FIFO not empty flag
* - SSP_FLAG_TxFifoNotFull: Transmit FIFO not full flag
* - SSP_FLAG_TxFifoEmpty: Transmit FIFO empty flag
* - SSP_FLAG_TxFifo: Transmit FIFO half empty or less flag
* - SSP_FLAG_RxFifo: Receive FIFO half full or less flag
* - SSP_FLAG_RxTimeOut: Receive timeout flag
* - SSP_FLAG_RxOverrun: Receive overrun flag
* Output : None
* Return : The new state of SSP_Flag (SET or RESET).
*******************************************************************************/
FlagStatus SSP_GetFlagStatus(SSP_TypeDef* SSPx, u16 SSP_FLAG)
{
u32 SSPReg = 0, FlagPos = 0;
u32 StatusReg = 0;
/* Get the SSP register index */
SSPReg = SSP_FLAG >> 5;
/* Get the flag position */
FlagPos = SSP_FLAG & SSP_Flag_Mask;
/* Find the register of the flag to check */
if(SSPReg == 1)
{
/* The flag to check is in SR register */
StatusReg = SSPx->SR;
}
else if (SSPReg == 2)
{
/* The flag to check is in RISR register */
StatusReg = SSPx->RISR;
}
/* Check the status of the specified SSP flag */
if((StatusReg & (1 << FlagPos)) != RESET)
{
/* Return SET if the SSP flag is set */
return SET;
}
else
{
/* Return RESET if the SSP flag is reset */
return RESET;
}
}
/*******************************************************************************
* Function Name : SSP_ClearFlag
* Description : Clears the SSPx flags.
* Input : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
* - SSP_FLAG: flags to clear. This parameter one of the
* following values:
* - SSP_FLAG_RxTimeOut: Receive timeout flag
* - SSP_FLAG_RxOverrun: Receive overrun flag
* Output : None
* Return : None
*******************************************************************************/
void SSP_ClearFlag(SSP_TypeDef* SSPx, u16 SSP_FLAG)
{
u8 FlagPos = 0;
/* Get the flag position */
FlagPos = SSP_FLAG & SSP_Flag_Mask;
/* Clear the selected SSP flag */
SSPx->ICR = (1 << FlagPos);
}
/*******************************************************************************
* Function Name : SSP_GetITStatus
* Description : Checks whether the specified SSP interrupt flag is set or not.
* Input : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
* - SSP_IT: interrupt flag to check. This parameter can be one
* of the following values:
* - SSP_IT_TxFifo: Transmit FIFO half empty or less interrupt
* - SSP_IT_RxFifo: Receive FIFO half full or less interrupt
* - SSP_IT_RxTimeOut: Receive timeout interrupt
* - SSP_IT_RxOverrun: Receive overrun interrupt
* Output : None
* Return : The new state of SSP_IT flag (SET or RESET).
*******************************************************************************/
ITStatus SSP_GetITStatus(SSP_TypeDef* SSPx, u16 SSP_IT)
{
/* Check the status of the specified interrupt flag */
if((SSPx->MISR & SSP_IT) != RESET)
{
/* Return SET if the SSP interrupt flag is set */
return SET;
}
else
{
/* Return RESET if SSP interrupt flag is reset */
return RESET;
}
}
/*******************************************************************************
* Function Name : SSP_ClearITPendingBit
* Description : Clears the pending interrupt flags.
* Input : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
* - SSP_IT: interrupts pending bits to clear. This parameter
* can be any combination of the following values:
* - SSP_IT_RxTimeOut: Receive timeout interrupt
* - SSP_IT_RxOverrun: Receive overrun interrupt
* Output : None
* Return : None
*******************************************************************************/
void SSP_ClearITPendingBit(SSP_TypeDef* SSPx, u16 SSP_IT)
{
/* Clear the selected SSP interrupts pending bits */
SSPx->ICR = SSP_IT;
}
/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -