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

📄 73x_bspi.c

📁 国外LPC2000系列的一些源程序,请大家快快下载
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************** (C) COPYRIGHT 2005 STMicroelectronics ********************
* File Name          : 73x_bspi.c
* Author             : MCD Application Team
* Date First Issued  : 09/27/2005 :  V1.0
* Description        : This file provides all the BSPI software functions.
**********************************************************************************
* History:
* 09/27/2005 :  V1.0
**********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
* CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
* OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
* OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
* CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*********************************************************************************/

/* Standard include ----------------------------------------------------------*/
#include "73x_bspi.h"
#include "73x_cfg.h"


/* Include of other module interface headers ---------------------------------*/
/* Local includes ------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Interface functions -------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/*******************************************************************************
* Function Name  : BSPI_DeInit
* Description    : Deinitializes the BSPIx peripheral registers to their default
*                  reset values.
* Input          : BSPIx: where x can be 0, 1 or 2 to select the BSPI peripheral.
* Output         : None
* Return         : None
*******************************************************************************/
void BSPI_DeInit(BSPI_TypeDef* BSPIx)
{
 
  if( BSPIx == BSPI0)
  {
   CFG_PeripheralClockConfig(CFG_CLK_BSPI0,DISABLE);
   CFG_PeripheralClockConfig(CFG_CLK_BSPI0,ENABLE);
  }
  else if  ( BSPIx == BSPI1)
  {
  
   CFG_PeripheralClockConfig(CFG_CLK_BSPI1,DISABLE);
   CFG_PeripheralClockConfig(CFG_CLK_BSPI1,ENABLE);
  }
  else if  ( BSPIx == BSPI2)
  {
   CFG_PeripheralClockConfig(CFG_CLK_BSPI2,DISABLE);
   CFG_PeripheralClockConfig(CFG_CLK_BSPI2,ENABLE);
  }
  
}

/*******************************************************************************
* Function Name  : BSPI_Init
* Description    : Initializes the BSPIx  peripheral according to the specified
*                  parameters in the BSPI_InitTypeDef structure.
* Input          : - BSPIx: where x can be 0, 1 or 2 to select the BSPI peripheral.
*                  - BSPI_InitStruct: pointer to a BSPI_InitTypeDef structure that
*                    contains the configuration information for the specified BSPI
*                    peripheral.
* Output         : None
* Return         : None
******************************************************************************/
void BSPI_Init(BSPI_TypeDef* BSPIx, BSPI_InitTypeDef* BSPI_InitStruct)
{
  u8 FIFO_Size = 0;

  BSPIx->CSR1 &= BSPI_CSR1_Mask;
  BSPIx->CSR2 &= BSPI_CSR2_Mask;
  BSPIx->CSR3 &= BSPI_CSR3_Mask;

  if(BSPI_InitStruct->BSPI_Mode == BSPI_Mode_Master)
  {
    /* configure the baud rate */
    BSPIx->CLK = BSPI_InitStruct->BSPI_CLKDivider;
    
    /* configure the status of the Slave Select pin */
    BSPIx->CSR3 |= BSPI_InitStruct->BSPI_SSPin;
  }
  
  /* configure the Clock Polarity */
  BSPIx->CSR1 |= BSPI_InitStruct->BSPI_CPOL;

  /* configure the Clock Phase */
  BSPIx->CSR1 |= BSPI_InitStruct->BSPI_CPHA;

  /* configure the BSPI mode of operation */
  BSPIx->CSR1 |= BSPI_InitStruct->BSPI_Mode;

  /* configure the word length */
  BSPIx->CSR1 |= BSPI_InitStruct->BSPI_WordLength;

  /* configure the Receive FIFO size */
  if(BSPI_InitStruct->BSPI_RxFifoSize > 0 && BSPI_InitStruct->BSPI_RxFifoSize < 17)
  {
    FIFO_Size = BSPI_InitStruct->BSPI_RxFifoSize - 1;
    /* clear the RFS[3:0] bits */
    BSPIx->CSR1 &=  BSPI_RxFifoSize_Mask;
    /* set the RFS[3:0] bits according to FIFO_Size value */
    BSPIx->CSR1 |= FIFO_Size << 12;
  }
  else
  {
    BSPIx->CSR1 &= BSPI_RxFifoSize_Mask;
  }

  /* configure the Transmit FIFO size */
  if(BSPI_InitStruct->BSPI_TxFifoSize > 0 && BSPI_InitStruct->BSPI_TxFifoSize < 17)
  {
    FIFO_Size = BSPI_InitStruct->BSPI_TxFifoSize -1;
    /* clear the TFS[3:0] bits */
    BSPIx->CSR2 &=  BSPI_TxFifoSize_Mask;
    /* set the TFS[3:0] bits according to FIFO_Size value */
    BSPIx->CSR2 |= FIFO_Size << 10;
  }
  else
  {
    BSPIx->CSR2 &= BSPI_TxFifoSize_Mask;
  }
}

/*******************************************************************************
* Function Name  : BSPI_Cmd
* Description    : Enables or disables the specified BSPI peripheral.
* Input          : - BSPIx: where x can be 0, 1 or 2 to select the BSPI peripheral.
*                  - NewState: new state of the  BSPIx peripheral. This parameter
*                    can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void BSPI_Cmd(BSPI_TypeDef* BSPIx, FunctionalState NewState)
{
  if(NewState == ENABLE)
  {
    BSPIx->CSR1 |= BSPI_Enable;
  }
  else
  {
    BSPIx->CSR1 &= BSPI_Disable;
  }
}

/*******************************************************************************
* Function Name  : BSPI_StructInit
* Description    : Fills in a BSPI_InitTypeDef structure with the reset value of
*                  each parameter.
* Input          : BSPI_InitStruct : pointer to a BSPI_InitTypeDef structure
                   which will be initialized.
* Output         : None
* Return         : None
*******************************************************************************/
void BSPI_StructInit(BSPI_InitTypeDef* BSPI_InitStruct)
{
  /* initialize the BSPI_SSPin member */
  BSPI_InitStruct->BSPI_SSPin = BSPI_SSPin_Used;

  /* initialize the BSPI_CLKDivider member */
  BSPI_InitStruct->BSPI_CLKDivider = 6;

  /* initialize the BSPI_CPOL member */
  BSPI_InitStruct->BSPI_CPOL = BSPI_CPOL_High;

  /* initialize the BSPI_CPHA member */
  BSPI_InitStruct->BSPI_CPHA = BSPI_CPHA_1Edge;

  /* initialize the BSPI_Mode member */
  BSPI_InitStruct->BSPI_Mode = BSPI_Mode_Slave;

  /* initialize the BSPI_WordLength member */
  BSPI_InitStruct->BSPI_WordLength = BSPI_WordLength_8b;
  
  /* initialize the BSPI_RxFifoSize member */
  BSPI_InitStruct->BSPI_RxFifoSize = 0;

  /* initialize the BSPI_TxFifoSize member */
  BSPI_InitStruct->BSPI_TxFifoSize = 0;

⌨️ 快捷键说明

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