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

📄 91x_ssp.c

📁 a set or ARM9 examples by STM
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name          : 91x_ssp.c
* Author             : MCD Application Team
* Date First Issued  : 05/18/2006 : Version 1.0
* Description        : This file provides all the SSP software functions.
********************************************************************************
* History:
* 05/24/2006 : Version 1.1
* 05/18/2006 : Version 1.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.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "91x_ssp.h"
#include "91x_scu.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/

/* SSP peripheral Enable */
#define SSP_Enable   0x0002
#define SSP_Disable  0xFFFD

/* SSP Loop Back Mode Enable */
#define SSP_LoopBackMode_Enable   0x0001
#define SSP_LoopBackMode_Disable  0xFFFE

/* SSP Flag Mask */
#define SSP_Flag_Mask  0x001F

/* SSP DMA transmit/ receive enable/disable Masks */
#define SSP_DMA_TransmitEnable   0x0002
#define SSP_DMA_TransmitDisable  0xFFFD
#define SSP_DMA_ReceiveEnable    0x0001
#define SSP_DMA_ReceiveDisable   0xFFFE

/* SSP Masks */
#define SSP_FrameFormat_Mask     0xFFCF
#define SSP_DataSize_Mask        0xFFF0
#define SSP_ClockRate_Mask       0x00FF
#define SSP_ClockPrescaler_Mask  0xFF00

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/*******************************************************************************
* Function Name  : SSP_DeInit
* Description    : Deinitializes the SSPx peripheral registers to their default
*                  reset values.
* Input          : SSPx: where x can be 0 or 1 to select the SSP peripheral.
* Output         : None
* Return         : None
*******************************************************************************/
void SSP_DeInit(SSP_TypeDef* SSPx)
{
  if(SSPx == SSP0)
  {
    /* Reset the SSP0 registers values*/
    SCU_APBPeriphReset(__SSP0,ENABLE);
    SCU_APBPeriphReset(__SSP0,DISABLE);
  }
  else if (SSPx == SSP1)
  {
    /* Reset the SSP1 registers values*/
    SCU_APBPeriphReset(__SSP1,ENABLE);
    SCU_APBPeriphReset(__SSP1,DISABLE);
  }
}

/*******************************************************************************
* Function Name  : SSP_Init
* Description    : Initializes the SSPx  peripheral according to the specified
*                  parameters in the SSP_InitTypeDef structure.
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
*                  - SSP_InitStruct: pointer to a SSP_InitTypeDef structure that
*                    contains the configuration information for the specified SSP
*                    peripheral.
* Output         : None
* Return         : None
*******************************************************************************/
void SSP_Init(SSP_TypeDef* SSPx, SSP_InitTypeDef* SSP_InitStruct)
{
  if(SSP_InitStruct->SSP_FrameFormat == SSP_FrameFormat_Motorola)
  {
    /* Set the Motorola frame format */
    SSPx->CR0 &= SSP_FrameFormat_Motorola;
    /* Configure the Clock polarity */
    if(SSP_InitStruct->SSP_CPOL == SSP_CPOL_High)
    {
      /* SCK is held high when no data is being transfered */
      SSPx->CR0 |= SSP_CPOL_High;
    }
    else
    {
      /* SCK is held low when no data is being transfered */
      SSPx->CR0 &= SSP_CPOL_Low;
    }
    /* Configure the Clock Phase */
    if(SSP_InitStruct->SSP_CPHA == SSP_CPHA_2Edge)
    {
      /* Data captured on second clock edge */
      SSPx->CR0 |= SSP_CPHA_2Edge;
    }
    else
    {
      /* Data captured on first clock edge */
      SSPx->CR0 &= SSP_CPHA_1Edge;
    }
  }
   /* Configure the Frame format */
  else
  {
    /* Clear the FRF[1:0] bits */
    SSPx->CR0 &= SSP_FrameFormat_Mask;
    /* Set the TI frame format */
    SSPx->CR0 |= SSP_InitStruct->SSP_FrameFormat;
  }
  /* Configure the Mode */
  if(SSP_InitStruct->SSP_Mode == SSP_Mode_Slave)
  {
    /* Set the slave mode */
    SSPx->CR1 |= SSP_Mode_Slave;
    /* Configure the Slave output */
    if(SSP_InitStruct->SSP_SlaveOutput == SSP_SlaveOutput_Disable)
    {
      /* Slave output disabled */
      SSPx->CR1 |= SSP_SlaveOutput_Disable;
    }
    else
    {
      /* Slave output enabled */
      SSPx->CR1 &= SSP_SlaveOutput_Enable;
    }
  }
  else
  {
    /* Set the master mode */
    SSPx->CR1 &= SSP_Mode_Master;
    /* Clear clock rate SCR[7:0] bits */
    SSPx->CR0 &= SSP_ClockRate_Mask;
    /* Set the serial clock rate */
    SSPx->CR0 |= (SSP_InitStruct->SSP_ClockRate<<8);
    /* Clear clock prescaler CPSDVSR[7:0] bits */
    SSPx->PR &= SSP_ClockPrescaler_Mask;
    /* Set the serial clock prescaler */
    SSPx->PR |= SSP_InitStruct->SSP_ClockPrescaler;
  }

  /* Clear data size DSS[3:0] bits */
  SSPx->CR0 &= SSP_DataSize_Mask;
  /* Set the data size */
  SSPx->CR0 |= SSP_InitStruct->SSP_DataSize;
}
/*******************************************************************************
* Function Name  : SSP_StructInit
* Description    : Fills in a SSP_InitTypeDef structure with the reset value of
*                  each parameter.
* Input          : SSP_InitStruct : pointer to a SSP_InitTypeDef structure
                   which will be initialized.
* Output         : None
* Return         : None
*******************************************************************************/
void SSP_StructInit(SSP_InitTypeDef* SSP_InitStruct)
{
  /* Initialize the SSP_FrameFormat member */
  SSP_InitStruct->SSP_FrameFormat = SSP_FrameFormat_Motorola;

  /* Initialize the SSP_Mode member */
  SSP_InitStruct->SSP_Mode = SSP_Mode_Master;

  /* Initialize the SSP_CPOL member */
  SSP_InitStruct->SSP_CPOL = SSP_CPOL_Low;

  /* Initialize the SSP_CPHA member */
  SSP_InitStruct->SSP_CPHA = SSP_CPHA_1Edge;

  /* Initialize the SSP_DataSize member */
  SSP_InitStruct->SSP_DataSize = SSP_DataSize_8b;

  /* Initialize the SSP_SlaveOutput member */
  SSP_InitStruct->SSP_SlaveOutput = SSP_SlaveOutput_Enable;

  /* Initialize the SSP_ClockRate member */
  SSP_InitStruct->SSP_ClockRate = 0;

  /* Initialize the SSP_ClockPrescaler member */
  SSP_InitStruct->SSP_ClockPrescaler = 0;
}

/*******************************************************************************
* Function Name  : SSP_Cmd
* Description    : Enables or disables the specified SSP peripheral.
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
*                  - NewState: new state of the  SSPx peripheral. This parameter
*                    can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void SSP_Cmd(SSP_TypeDef* SSPx, FunctionalState NewState)
{
  if(NewState == ENABLE)
  {
    /* Enable the SSP peripheral */
    SSPx->CR1 |= SSP_Enable;
  }
  else
  {
    /* Disable the SSP peripheral */
    SSPx->CR1 &= SSP_Disable;
  }
}

/*******************************************************************************
* Function Name  : SSP_ITConfig
* Description    : Enables or disables the specified SSP interrupts.
* Input          : - SSPx: where x can be 0 or 1 to select the SSP peripheral.
*                  - SSP_IT: specifies the SSP interrupts sources to be enabled
*                    or disabled. This parameter can be any combination 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
*                  - NewState: new state of the specified SSP interrupts.
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None

⌨️ 快捷键说明

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