⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 71x_bspi.c

📁 STR7系列32位ARM控制器的固件库
💻 C
📖 第 1 页 / 共 2 页
字号:
*                    where x can be 0 or 1.
*                  - NewState: specifies whether capturing the first data sample
*                    on the first edge of SCK is enabled or disabled.
*                     ENABLE: enable capturing the first data sample on the
*                     first edge of SCK.
*                     DISABLE: enable capturing the first data sample on the
*                     second edge of SCK.
* Output         : None.
* Return         : None.
*******************************************************************************/
void BSPI_ClkFEdge(BSPI_TypeDef *BSPIx, FunctionalState NewState)
{
  if (NewState == ENABLE)
  {
    BSPIx->CSR1 &= ~BSPI_CPHA_Mask;
  }
  else
  {
    BSPIx->CSR1 |= BSPI_CPHA_Mask;
  }
}

/*******************************************************************************
* Function Name  : BSPI_ClkActiveHigh
* Description    : Configures the clock to be active high or low.
* Input          : - BSPIx: selects BSPI peripheral to be configured 
*                    where x can be 0 or 1.
*                  - NewState: specifies whether the clock is active high or low.
*                     ENABLE: Configures the clock to be active High.
*                     DISABLE: Configures the clock to be active Low.
* Output         : None.
* Return         : None.
*******************************************************************************/
void BSPI_ClkActiveHigh(BSPI_TypeDef *BSPIx, FunctionalState NewState)
{
  if (NewState == ENABLE)
  {
    BSPIx->CSR1 &= ~BSPI_CPOL_Mask;
  }
  else
  { 
    BSPIx->CSR1 |= BSPI_CPOL_Mask;
  }
}

/*******************************************************************************
* Function Name  : BSPI_FifoDisable
* Description    : Disables the FIFO of the specified BSPI.
* Input          : - BSPIx: selects BSPI peripheral to be configured 
*                    where x can be 0 or 1.
* Output         : None.
* Return         : None.
*******************************************************************************/
void BSPI_FifoDisable(BSPI_TypeDef *BSPIx)
{
  BSPIx->CSR2 |= BSPI_DFIFO_Mask;
}

/*******************************************************************************
* Function Name  : BSPI_ClockDividerConfig
* Description    : Configures BSPI clock divider.
* Input          : - BSPIx: selects BSPI peripheral to be configured 
*                    where x can be 0 or 1.
*                  - Div: holds the value of the clock divider.
* Output         : None.
* Return         : None.
*******************************************************************************/
void BSPI_ClockDividerConfig(BSPI_TypeDef *BSPIx, u8 Div)
{
  BSPIx->CLK = Div;
}

/*******************************************************************************
* Function Name  : BSPI_FlagStatus
* Description    : Checks whether the specified BSPI Flag is set or not.
* Input          : - BSPIx: selects BSPI peripheral to be configured 
*                    where x can be 0 or 1.
*                  - flag: specifies the flag to see the status.
* Output         : None.
* Return         : The status of the specified flag.
*                   SET: if the tested flag is set.
*                   RESET: if the corresponding flag is reset.
*******************************************************************************/
FlagStatus BSPI_FlagStatus(BSPI_TypeDef *BSPIx, BSPI_Flags flag)
{
  if (BSPIx->CSR2 & flag)
  {
    return SET;	
  }
  else
  {
    return RESET;	
  }
}

/*******************************************************************************
* Function Name  : BSPI_WordSend
* Description    : Transmit a single Word.
* Input          : - BSPIx: selects BSPI peripheral to be configured 
*                    where x can be 0 or 1.
*                  - Data: the word which will be transmitted.
* Output         : None.
* Return         : None.
*******************************************************************************/
void BSPI_WordSend(BSPI_TypeDef *BSPIx, u16 Data)
{
  /* If the word length has been configured as 8-bits word length */	
  if ((BSPIx->CSR1 & 0x0400) == 0)
  {
    Data <<= 8;
  }
  
  BSPIx->TXR = Data;
}

/*******************************************************************************
* Function Name  : BSPI_ByteBufferSend
* Description    : Transmits 8 bit format data from a buffer.
* Input          : - BSPIx: selects BSPI peripheral to be used where
*                    x can be 0 or 1.
*                  - PtrToBuffer: is an 'u8' pointer to the first byte of the
*                    buffer to be transmitted.
*                  - NbOfWords: the number of words saved in the buffer 
*                    to be sent.
* Output         : None.
* Return         : None.
*******************************************************************************/
void BSPI_ByteBufferSend(BSPI_TypeDef *BSPIx, u8 *PtrToBuffer, u8 NbOfWords)
{
  vu8 SendWord = 0;
  
  while (SendWord < NbOfWords)
  {
    BSPI_WordSend(BSPIx, *(PtrToBuffer + SendWord));
    SendWord++;
  }
}

/*******************************************************************************
* Function Name  : BSPI_WordBufferSend
* Description    : Transmits 16 bits data format from a buffer.
* Input          : - BSPIx: selects BSPI peripheral to be used where
*                    x can be 0 or 1.
*                  - PtrToBuffer: is an 'u16' pointer to the first word of the
*                    buffer to be transmitted.
*                  - NbOfWords: indicates the number of words saved in
*                    the buffer to be sent.
* Output         : None.
* Return         : None.
*******************************************************************************/
void BSPI_WordBufferSend(BSPI_TypeDef *BSPIx, u16 *PtrToBuffer, u8 NbOfWords)
{
  vu8 SendWord = 0;
  
  while (SendWord < NbOfWords)
  {
    BSPI_WordSend(BSPIx, *(PtrToBuffer + SendWord));
    SendWord++;
  }
}

/*******************************************************************************
* Function Name  : BSPI_WordReceive
* Description    : Returns the recent received word.
* Input          : - BSPIx: selects BSPI peripheral to be used where
*                    x can be 0 or 1.
* Output         : None.
* Return         : The value of the received word.
*******************************************************************************/
u16 BSPI_WordReceive(BSPI_TypeDef *BSPIx)
{
  /* If the word length has been configured as 8-bits word length */
  if((BSPIx->CSR1 & 0x0400) == 0)
  {
    return BSPIx->RXR >> 8 ;
  }
  else
  {
    return BSPIx->RXR;	
  }
}

/*******************************************************************************
* Function Name  : BSPI_ByteBufferReceive
* Description    : Receives number of data words and stores them in user defined
*                  area.
* Input          : - BSPIx: selects BSPI peripheral to be used where
*                    x can be 0 or 1.
*                  - PtrToBuffer: is an 'u8' pointer to the first word of the
*                    defined area to save the received buffer.
*                  - NbOfWords: indicates the number of bytes to be received
*                    in the buffer.
* Output         : The received data.
* Return         : None.
*******************************************************************************/
void BSPI_ByteBufferReceive(BSPI_TypeDef *BSPIx, u8 *PtrToBuffer, u8 NbOfWords)
{
  vu8 ReceiveWord = 0;
  
  while (ReceiveWord < NbOfWords)
  {
    *(PtrToBuffer + ReceiveWord) = BSPI_WordReceive(BSPIx);
    ReceiveWord++;
  }
}

/*******************************************************************************
* Function Name  : BSPI_WordBufferReceive
* Description    : Receives number of 16-bit data words and stores them in user 
*                  defined area.
* Input          : - BSPIx: selects BSPI peripheral to be used where
*                    x can be 0 or 1.
*                  - PtrToBuffer: is an 'u16' pointer to the first word of the
*                    defined area to save the received buffer.
*                  - NbOfWords: indicates the number of words to be received
*                    in the buffer.
* Output         : The received data.
* Return         : None.
*******************************************************************************/
void BSPI_WordBufferReceive(BSPI_TypeDef *BSPIx, u16 *PtrToBuffer, u8 NbOfWords)
{
  vu8 ReceiveWord = 0;
  
  while (ReceiveWord < NbOfWords)
  {
    *(PtrToBuffer + ReceiveWord) = BSPI_WordReceive(BSPIx);
    ReceiveWord++;
  }
}

/*******************************************************************************
* Function Name  : BSPI_ErrItSrc
* Description    : Enables or disables the specified error interrupt.
* Input          : - BSPIx: selects BSPI peripheral to be used where
*                    x can be 0 or 1.
*                  - BSPI_IE: specifies the BSPI error interrupt.
*                  - NewState: specified whether the BSPI interrupt is enabled 
*                    or disabled.
*                     ENABLE  to enable interrupt.
*                     DISABLE to disable interrupt.
* Output         : None.
* Return         : None.
*******************************************************************************/
void BSPI_ErrItSrc(BSPI_TypeDef *BSPIx, BSPI_IT_ERR BSPI_IE,
                   FunctionalState NewState)
{
  if (NewState == ENABLE)
  {
    BSPIx->CSR1 |= BSPI_IE;
  }
  else
  {
    BSPIx->CSR1 &= ~BSPI_IE;
  }
}

/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -