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

📄 stm32f10x_spi.lst

📁 STM32利用正交编码器实现电机的控制
💻 LST
📖 第 1 页 / 共 3 页
字号:
    211          *******************************************************************************/
    212          void SPI_ITConfig(SPI_TypeDef* SPIx, u8 SPI_IT, FunctionalState NewState)
    213          {
    214            u16 itpos = 0, itmask = 0 ;
    215          
    216            /* Check the parameters */
    217            assert(IS_FUNCTIONAL_STATE(NewState));
    218            assert(IS_SPI_CONFIG_IT(SPI_IT));
    219          
    220            /* Get the SPI IT index */
    221            itpos = SPI_IT >> 4;
    222            /* Set the IT mask */
    223            itmask = (u16)((u16)1 << itpos);
    224          
    225            if (NewState != DISABLE)
    226            {
    227              /* Enable the selected SPI interrupt */
    228              SPIx->CR2 |= itmask;
    229            }
    230            else
    231            {
    232              /* Disable the selected SPI interrupt */
    233              SPIx->CR2 &= (u16)~itmask;
    234            }
    235          }
    236          
    237          /*******************************************************************************
    238          * Function Name  : SPI_DMACmd
    239          * Description    : Enables or disables the SPIx抯 DMA interface.
    240          * Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
    241          *                  - SPI_DMAReq: specifies the SPI DMA transfer request to be
    242          *                    enabled or disabled. 
    243          *                    This parameter can be any combination of the following values:
    244          *                       - SPI_DMAReq_Tx: Tx buffer DMA transfer request
    245          *                       - SPI_DMAReq_Rx: Rx buffer DMA transfer request
    246          *                  - NewState: new state of the selected SPI DMA transfer request.
    247          *                    This parameter can be: ENABLE or DISABLE.
    248          * Output         : None
    249          * Return         : None
    250          *******************************************************************************/
    251          void SPI_DMACmd(SPI_TypeDef* SPIx, u16 SPI_DMAReq, FunctionalState NewState)
    252          {
    253            /* Check the parameters */
    254            assert(IS_FUNCTIONAL_STATE(NewState));
    255            assert(IS_SPI_DMA_REQ(SPI_DMAReq));
    256          
    257            if (NewState != DISABLE)
    258            {
    259              /* Enable the selected SPI DMA requests */
    260              SPIx->CR2 |= SPI_DMAReq;
    261            }
    262            else
    263            {
    264              /* Disable the selected SPI DMA requests */
    265              SPIx->CR2 &= (u16)~SPI_DMAReq;
    266            }
    267          }
    268          
    269          /*******************************************************************************
    270          * Function Name  : SPI_SendData
    271          * Description    : Transmits a Data through the SPIx peripheral.
    272          * Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
    273          *                  - Data : Data to be transmitted..
    274          * Output         : None
    275          * Return         : None
    276          *******************************************************************************/
    277          void SPI_SendData(SPI_TypeDef* SPIx, u16 Data)
    278          {
    279            /* Write in the DR register the data to be sent */
    280            SPIx->DR = Data;
    281          }
    282          
    283          /*******************************************************************************
    284          * Function Name  : SPI_ReceiveData
    285          * Description    : Returns the most recent received data by the SPIx peripheral.
    286          * Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
    287          * Output         : None
    288          * Return         : The value of the received data.
    289          *******************************************************************************/
    290          u16 SPI_ReceiveData(SPI_TypeDef* SPIx)
    291          {
    292            /* Return the data in the DR register */
    293            return SPIx->DR;
    294          }
    295          
    296          /*******************************************************************************
    297          * Function Name  : SPI_NSSInternalSoftwareConfig
    298          * Description    : Configures internally by software the NSS pin for the selected 
    299          *                  SPI.
    300          * Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
    301          *                  - SPI_NSSInternalSoft: specifies the SPI NSS internal state.
    302          *                    This parameter can be one of the following values:
    303          *                       - SPI_NSSInternalSoft_Set: Set NSS pin internally
    304          *                       - SPI_NSSInternalSoft_Reset: Reset NSS pin internally
    305          * Output         : None
    306          * Return         : None
    307          *******************************************************************************/
    308          void SPI_NSSInternalSoftwareConfig(SPI_TypeDef* SPIx, u16 SPI_NSSInternalSoft)
    309          {
    310            /* Check the parameters */
    311            assert(IS_SPI_NSS_INTERNAL(SPI_NSSInternalSoft));
    312          
    313            if (SPI_NSSInternalSoft != SPI_NSSInternalSoft_Reset)
    314            {
    315              /* Set NSS pin internally by software */
    316              SPIx->CR1 |= SPI_NSSInternalSoft_Set;
    317            }
    318            else
    319            {
    320              /* Reset NSS pin internally by software */
    321              SPIx->CR1 &= SPI_NSSInternalSoft_Reset;
    322            }
    323          }
    324          
    325          /*******************************************************************************
    326          * Function Name  : SPI_SSOutputCmd
    327          * Description    : Enables or disables the SS output for the selected SPI.
    328          * Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
    329          *                  - NewState: new state of the SPIx SS output. 
    330          *                    This parameter can be: ENABLE or DISABLE.
    331          * Output         : None
    332          * Return         : None
    333          *******************************************************************************/
    334          void SPI_SSOutputCmd(SPI_TypeDef* SPIx, FunctionalState NewState)
    335          {
    336            /* Check the parameters */
    337            assert(IS_FUNCTIONAL_STATE(NewState));
    338          
    339            if (NewState != DISABLE)
    340            {
    341              /* Enable the selected SPI SS output */
    342              SPIx->CR2 |= CR2_SSOE_Set;
    343            }
    344            else
    345            {
    346              /* Disable the selected SPI SS output */
    347              SPIx->CR2 &= CR2_SSOE_Reset;
    348            }
    349          }
    350          
    351          /*******************************************************************************
    352          * Function Name  : SPI_DataSizeConfig
    353          * Description    : Configures the data size for the selected SPI.
    354          * Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
    355          *                  - SPI_DataSize: specifies the SPI data size.
    356          *                    This parameter can be one of the following values:
    357          *                       - SPI_DataSize_16b: Set data frame format to 16bit
    358          *                       - SPI_DataSize_8b: Set data frame format to 8bit
    359          * Output         : None
    360          * Return         : None
    361          *******************************************************************************/
    362          void SPI_DataSizeConfig(SPI_TypeDef* SPIx, u16 SPI_DataSize)
    363          {
    364            /* Check the parameters */
    365            assert(IS_SPI_DATASIZE(SPI_DataSize));
    366          
    367            /* Clear DFF bit */
    368            SPIx->CR1 &= (u16)~SPI_DataSize_16b;
    369            /* Set new DFF bit value */
    370            SPIx->CR1 |= SPI_DataSize;
    371          }
    372          
    373          /*******************************************************************************
    374          * Function Name  : SPI_TransmitCRC
    375          * Description    : Transmit the SPIx CRC value.
    376          * Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
    377          * Output         : None
    378          * Return         : None
    379          *******************************************************************************/
    380          void SPI_TransmitCRC(SPI_TypeDef* SPIx)
    381          {
    382            /* Enable the selected SPI CRC transmission */
    383            SPIx->CR1 |= CR1_CRCNext_Set;
    384          }
    385          
    386          /*******************************************************************************
    387          * Function Name  : SPI_CalculateCRC
    388          * Description    : Enables or disables the CRC value calculation of the
    389          *                  transfered bytes.
    390          * Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
    391          *                  - NewState: new state of the SPIx CRC value calculation.
    392          *                    This parameter can be: ENABLE or DISABLE.
    393          * Output         : None
    394          * Return         : None
    395          *******************************************************************************/
    396          void SPI_CalculateCRC(SPI_TypeDef* SPIx, FunctionalState NewState)
    397          {
    398            /* Check the parameters */
    399            assert(IS_FUNCTIONAL_STATE(NewState));
    400          
    401            if (NewState != DISABLE)
    402            {
    403              /* Enable the selected SPI CRC calculation */
    404              SPIx->CR1 |= CR1_CRCEN_Set;
    405            }
    406            else
    407            {
    408              /* Disable the selected SPI CRC calculation */
    409              SPIx->CR1 &= CR1_CRCEN_Reset;
    410            }
    411          }
    412          
    413          /*******************************************************************************
    414          * Function Name  : SPI_GetCRC
    415          * Description    : Returns the transmit or the receive CRC register value for
    416          *                  the specified SPI.
    417          * Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
    418          *                  - SPI_CRC: specifies the CRC register to be read.
    419          *                    This parameter can be one of the following values:
    420          *                       - SPI_CRC_Tx: Selects Tx CRC register
    421          *                       - SPI_CRC_Rx: Selects Rx CRC register
    422          * Output         : None
    423          * Return         : The selected CRC register value..
    424          *******************************************************************************/
    425          u16 SPI_GetCRC(SPI_TypeDef* SPIx, u8 SPI_CRC)
    426          {
    427            u16 crcreg = 0;
    428          
    429            /* Check the parameters */
    430            assert(IS_SPI_CRC(SPI_CRC));
    431          
    432            if (SPI_CRC != SPI_CRC_Rx)
    433            {
    434              /* Get the Tx CRC register */
    435              crcreg = SPIx->TXCRCR;
    436            }
    437            else
    438            {
    439              /* Get the Rx CRC register */
    440              crcreg = SPIx->RXCRCR;
    441            }
    442          
    443            /* Return the selected CRC register */
    444            return crcreg;
    445          }
    446          
    447          /*******************************************************************************
    448          * Function Name  : SPI_GetCRCPolynomial
    449          * Description    : Returns the CRC Polynomial register value for the specified SPI.
    450          * Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
    451          * Output         : None
    452          * Return         : The CRC Polynomial register value.
    453          *******************************************************************************/
    454          u16 SPI_GetCRCPolynomial(SPI_TypeDef* SPIx)
    455          {
    456            /* Return the CRC polynomial register */
    457            return SPIx->CRCPR;
    458          }
    459          
    460          /*******************************************************************************
    461          * Function Name  : SPI_BiDirectionalLineConfig
    462          * Description    : Selects the data transfer direction in bi-directional mode
    463          *                  for the specified SPI.
    464          * Input          : - SPIx: where x can be 1 or 2 to select the SPI peripheral.
    465          *                  - SPI_Direction: specifies the data transfer direction in

⌨️ 快捷键说明

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