10001|1

2

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

STM32的SPI配置好之后,连续发送数据,结果SCK无输出 [复制链接]

void SPI2_Configuration(void)
{
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);  
    GPIO_InitTypeDef GPIO_InitStructure;
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15;//SCK,SI
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;//SO
    GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPU ;   
    GPIO_Init(GPIOB, &GPIO_InitStructure);
   
    SPI_InitTypeDef  SPI_InitStructure;   
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE);     
    SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;   //双工模式
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;   //SPI主模式
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;   //8bit数据
    SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;     //CLK空闲时为低电平
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;     //第一个上升沿采样
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;     //片选用软件控制????????????
    SPI_InitStructure.SPI_BaudRatePrescaler =SPI_BaudRatePrescaler_64;   //SPI频率
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;   //高位在前
    SPI_InitStructure.SPI_CRCPolynomial = 7;     //crc7,stm32spi带硬件ecc
    SPI_Init(SPI2, &SPI_InitStructure);
    SPI_Cmd(SPI2, ENABLE);
  
}
此帖出自stm32/stm8论坛

最新回复

SPI_InitTypeDef  SPI_InitStructure;  这句怎么在中间呢,编译不过去吧 /**   ******************************************************************************   * @file    SPI/CRC/main.c   * @author  MCD Application Team   * @version V3.5.0   * @date    08-April-2011   * @brief   Main program body   ******************************************************************************   * @attention   *   * THE PRESENT FIRMWARE 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 FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.   *   * © COPYRIGHT 2011 STMicroelectronics   ******************************************************************************   */ /* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h" /** @addtogroup STM32F10x_StdPeriph_Examples   * @{   */ /** @addtogroup SPI_CRC   * @{   */ /* Private typedef -----------------------------------------------------------*/ typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; /* Private define ------------------------------------------------------------*/ #define BufferSize  32 /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ SPI_InitTypeDef  SPI_InitStructure; uint16_t SPI1_Buffer_Tx[BufferSize] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C,                                   0x0D0E, 0x0F10, 0x1112, 0x1314, 0x1516, 0x1718,                                   0x191A, 0x1B1C, 0x1D1E, 0x1F20, 0x2122, 0x2324,                                   0x2526, 0x2728, 0x292A, 0x2B2C, 0x2D2E, 0x2F30,                                   0x3132, 0x3334, 0x3536, 0x3738, 0x393A, 0x3B3C,                                   0x3D3E, 0x3F40}; uint16_t SPI2_Buffer_Tx[BufferSize] = {0x5152, 0x5354, 0x5556, 0x5758, 0x595A, 0x5B5C,                                   0x5D5E, 0x5F60, 0x6162, 0x6364, 0x6566, 0x6768,                                   0x696A, 0x6B6C, 0x6D6E, 0x6F70, 0x7172, 0x7374,                                   0x7576, 0x7778, 0x797A, 0x7B7C, 0x7D7E, 0x7F80,                                   0x8182, 0x8384, 0x8586, 0x8788, 0x898A, 0x8B8C,                                   0x8D8E, 0x8F90}; uint16_t SPI1_Buffer_Rx[BufferSize], SPI2_Buffer_Rx[BufferSize]; uint32_t TxIdx = 0, RxIdx = 0; __IO uint16_t CRC1Value = 0, CRC2Value = 0; volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED; /* Private functions ---------------------------------------------------------*/ void RCC_Configuration(void); void GPIO_Configuration(void); TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength); /**   * @brief  Main program   * @param  None   * @retval None   */ int main(void) {   /*!< At this stage the microcontroller clock setting is already configured,        this is done through SystemInit() function which is called from startup        file (startup_stm32f10x_xx.s) before to branch to application main.        To reconfigure the default setting of SystemInit() function, refer to        system_stm32f10x.c file      */               /* System clocks configuration ---------------------------------------------*/   RCC_Configuration();   /* GPIO configuration ------------------------------------------------------*/   GPIO_Configuration();   /* SPI1 configuration ------------------------------------------------------*/   SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;   SPI_InitStructure.SPI_Mode = SPI_Mode_Master;   SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;   SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;   SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;   SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;   SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;   SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;   SPI_InitStructure.SPI_CRCPolynomial = 7;   SPI_Init(SPI1, &SPI_InitStructure);   /* SPI2 configuration ------------------------------------------------------*/   SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;   SPI_Init(SPI2, &SPI_InitStructure);   /* Enable SPI1 CRC calculation */   SPI_CalculateCRC(SPI1, ENABLE);   /* Enable SPI2 CRC calculation */   SPI_CalculateCRC(SPI2, ENABLE);   /* Enable SPI1 */   SPI_Cmd(SPI1, ENABLE);   /* Enable SPI2 */   SPI_Cmd(SPI2, ENABLE);   /* Transfer procedure */   while (TxIdx < BufferSize - 1)   {     /* Wait for SPI1 Tx buffer empty */     while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);     /* Send SPI2 data */     SPI_I2S_SendData(SPI2, SPI2_Buffer_Tx[TxIdx]);     /* Send SPI1 data */     SPI_I2S_SendData(SPI1, SPI1_Buffer_Tx[TxIdx++]);     /* Wait for SPI2 data reception */     while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);     /* Read SPI2 received data */     SPI2_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI2);     /* Wait for SPI1 data reception */     while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);     /* Read SPI1 received data */     SPI1_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI1);   }   /* Wait for SPI1 Tx buffer empty */   while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);   /* Wait for SPI2 Tx buffer empty */   while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);   /* Send last SPI2_Buffer_Tx data */   SPI_I2S_SendData(SPI2, SPI2_Buffer_Tx[TxIdx]);   /* Enable SPI2 CRC transmission */   SPI_TransmitCRC(SPI2);   /* Send last SPI1_Buffer_Tx data */   SPI_I2S_SendData(SPI1, SPI1_Buffer_Tx[TxIdx]);   /* Enable SPI1 CRC transmission */   SPI_TransmitCRC(SPI1);   /* Wait for SPI1 last data reception */   while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);   /* Read SPI1 last received data */   SPI1_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI1);   /* Wait for SPI2 last data reception */   while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);   /* Read SPI2 last received data */   SPI2_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI2);   /* Wait for SPI1 data reception: CRC transmitted by SPI2 */   while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);   /* Wait for SPI2 data reception: CRC transmitted by SPI1 */   while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);   /* Check the received data with the send ones */   TransferStatus1 = Buffercmp(SPI2_Buffer_Rx, SPI1_Buffer_Tx, BufferSize);   TransferStatus2 = Buffercmp(SPI1_Buffer_Rx, SPI2_Buffer_Tx, BufferSize);   /* TransferStatus1, TransferStatus2 = PASSED, if the data transmitted and received      are correct */   /* TransferStatus1, TransferStatus2 = FAILED, if the data transmitted and received      are different */   /* Test on the SPI1 CRC Error flag */   if ((SPI_I2S_GetFlagStatus(SPI1, SPI_FLAG_CRCERR)) == SET)   {     TransferStatus2 = FAILED;   }   /* Test on the SPI2 CRC Error flag */   if ((SPI_I2S_GetFlagStatus(SPI2, SPI_FLAG_CRCERR)) == SET)   {     TransferStatus1 = FAILED;   }   /* Read SPI1 received CRC value */   CRC1Value = SPI_I2S_ReceiveData(SPI1);   /* Read SPI2 received CRC value */   CRC2Value = SPI_I2S_ReceiveData(SPI2);   while (1)   {} } /**   * @brief  Configures the different system clocks.   * @param  None   * @retval None   */ void RCC_Configuration(void) {   /* PCLK2 = HCLK/2 */   RCC_PCLK2Config(RCC_HCLK_Div2);   /* Enable peripheral clocks --------------------------------------------------*/   /* GPIOA, GPIOB and SPI1 clock enable */   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |                          RCC_APB2Periph_SPI1, ENABLE);   /* SPI2 Periph clock enable */   RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); } /**   * @brief  Configures the different GPIO ports.   * @param  None   * @retval None   */ void GPIO_Configuration(void) {   GPIO_InitTypeDef GPIO_InitStructure;   /* Configure SPI1 pins: SCK, MISO and MOSI ---------------------------------*/   /* Confugure SCK and MOSI pins as Alternate Function Push Pull */   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;   GPIO_Init(GPIOA, &GPIO_InitStructure);   /* Confugure MISO pin as Input Floating  */   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   GPIO_Init(GPIOA, &GPIO_InitStructure);      /* Configure SPI2 pins: SCK, MISO and MOSI ---------------------------------*/   /* Confugure SCK and MOSI pins as Input Floating */   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15;   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   GPIO_Init(GPIOB, &GPIO_InitStructure);   /* Confugure MISO pin as Alternate Function Push Pull */   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;   GPIO_Init(GPIOB, &GPIO_InitStructure); } /**   * @brief  Compares two buffers.   * @param  pBuffer1, pBuffer2: buffers to be compared.   * @param  BufferLength: buffer's length   * @retval PASSED: pBuffer1 identical to pBuffer2   *         FAILED: pBuffer1 differs from pBuffer2   */ TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength) {   while (BufferLength--)   {     if (*pBuffer1 != *pBuffer2)     {       return FAILED;     }     pBuffer1++;     pBuffer2++;   }   return PASSED; } #ifdef  USE_FULL_ASSERT /**   * @brief  Reports the name of the source file and the source line number   *         where the assert_param error has occurred.   * @param  file: pointer to the source file name   * @param  line: assert_param error line source number   * @retval None   */ void assert_failed(uint8_t* file, uint32_t line) {   /* User can add his own implementation to report the file name and line number,      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */   /* Infinite loop */   while (1)   {} } #endif /**   * @}   */ /**   * @}   */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/  详情 回复 发表于 2013-5-6 16:15
点赞 关注
 

回复
举报

4008

帖子

0

TA的资源

版主

沙发
 
SPI_InitTypeDef  SPI_InitStructure;  这句怎么在中间呢,编译不过去吧

/**
  ******************************************************************************
  * @file    SPI/CRC/main.c
  * @author  MCD Application Team
  * @version V3.5.0
  * @date    08-April-2011
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE 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 FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  *

© COPYRIGHT 2011 STMicroelectronics


  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"

/** @addtogroup STM32F10x_StdPeriph_Examples
  * @{
  */

/** @addtogroup SPI_CRC
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;

/* Private define ------------------------------------------------------------*/
#define BufferSize  32

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
SPI_InitTypeDef  SPI_InitStructure;
uint16_t SPI1_Buffer_Tx[BufferSize] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090A, 0x0B0C,
                                  0x0D0E, 0x0F10, 0x1112, 0x1314, 0x1516, 0x1718,
                                  0x191A, 0x1B1C, 0x1D1E, 0x1F20, 0x2122, 0x2324,
                                  0x2526, 0x2728, 0x292A, 0x2B2C, 0x2D2E, 0x2F30,
                                  0x3132, 0x3334, 0x3536, 0x3738, 0x393A, 0x3B3C,
                                  0x3D3E, 0x3F40};
uint16_t SPI2_Buffer_Tx[BufferSize] = {0x5152, 0x5354, 0x5556, 0x5758, 0x595A, 0x5B5C,
                                  0x5D5E, 0x5F60, 0x6162, 0x6364, 0x6566, 0x6768,
                                  0x696A, 0x6B6C, 0x6D6E, 0x6F70, 0x7172, 0x7374,
                                  0x7576, 0x7778, 0x797A, 0x7B7C, 0x7D7E, 0x7F80,
                                  0x8182, 0x8384, 0x8586, 0x8788, 0x898A, 0x8B8C,
                                  0x8D8E, 0x8F90};
uint16_t SPI1_Buffer_Rx[BufferSize], SPI2_Buffer_Rx[BufferSize];
uint32_t TxIdx = 0, RxIdx = 0;
__IO uint16_t CRC1Value = 0, CRC2Value = 0;
volatile TestStatus TransferStatus1 = FAILED, TransferStatus2 = FAILED;

/* Private functions ---------------------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength);

/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     
      
  /* System clocks configuration ---------------------------------------------*/
  RCC_Configuration();

  /* GPIO configuration ------------------------------------------------------*/
  GPIO_Configuration();

  /* SPI1 configuration ------------------------------------------------------*/
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPI1, &SPI_InitStructure);

  /* SPI2 configuration ------------------------------------------------------*/
  SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
  SPI_Init(SPI2, &SPI_InitStructure);

  /* Enable SPI1 CRC calculation */
  SPI_CalculateCRC(SPI1, ENABLE);
  /* Enable SPI2 CRC calculation */
  SPI_CalculateCRC(SPI2, ENABLE);

  /* Enable SPI1 */
  SPI_Cmd(SPI1, ENABLE);
  /* Enable SPI2 */
  SPI_Cmd(SPI2, ENABLE);

  /* Transfer procedure */
  while (TxIdx < BufferSize - 1)
  {
    /* Wait for SPI1 Tx buffer empty */
    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
    /* Send SPI2 data */
    SPI_I2S_SendData(SPI2, SPI2_Buffer_Tx[TxIdx]);
    /* Send SPI1 data */
    SPI_I2S_SendData(SPI1, SPI1_Buffer_Tx[TxIdx++]);
    /* Wait for SPI2 data reception */
    while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
    /* Read SPI2 received data */
    SPI2_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI2);
    /* Wait for SPI1 data reception */
    while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
    /* Read SPI1 received data */
    SPI1_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI1);
  }

  /* Wait for SPI1 Tx buffer empty */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
  /* Wait for SPI2 Tx buffer empty */
  while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);

  /* Send last SPI2_Buffer_Tx data */
  SPI_I2S_SendData(SPI2, SPI2_Buffer_Tx[TxIdx]);
  /* Enable SPI2 CRC transmission */
  SPI_TransmitCRC(SPI2);
  /* Send last SPI1_Buffer_Tx data */
  SPI_I2S_SendData(SPI1, SPI1_Buffer_Tx[TxIdx]);
  /* Enable SPI1 CRC transmission */
  SPI_TransmitCRC(SPI1);

  /* Wait for SPI1 last data reception */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
  /* Read SPI1 last received data */
  SPI1_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI1);

  /* Wait for SPI2 last data reception */
  while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
  /* Read SPI2 last received data */
  SPI2_Buffer_Rx[RxIdx] = SPI_I2S_ReceiveData(SPI2);

  /* Wait for SPI1 data reception: CRC transmitted by SPI2 */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
  /* Wait for SPI2 data reception: CRC transmitted by SPI1 */
  while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);

  /* Check the received data with the send ones */
  TransferStatus1 = Buffercmp(SPI2_Buffer_Rx, SPI1_Buffer_Tx, BufferSize);
  TransferStatus2 = Buffercmp(SPI1_Buffer_Rx, SPI2_Buffer_Tx, BufferSize);
  /* TransferStatus1, TransferStatus2 = PASSED, if the data transmitted and received
     are correct */
  /* TransferStatus1, TransferStatus2 = FAILED, if the data transmitted and received
     are different */

  /* Test on the SPI1 CRC Error flag */
  if ((SPI_I2S_GetFlagStatus(SPI1, SPI_FLAG_CRCERR)) == SET)
  {
    TransferStatus2 = FAILED;
  }

  /* Test on the SPI2 CRC Error flag */
  if ((SPI_I2S_GetFlagStatus(SPI2, SPI_FLAG_CRCERR)) == SET)
  {
    TransferStatus1 = FAILED;
  }

  /* Read SPI1 received CRC value */
  CRC1Value = SPI_I2S_ReceiveData(SPI1);
  /* Read SPI2 received CRC value */
  CRC2Value = SPI_I2S_ReceiveData(SPI2);

  while (1)
  {}
}

/**
  * @brief  Configures the different system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
  /* PCLK2 = HCLK/2 */
  RCC_PCLK2Config(RCC_HCLK_Div2);

  /* Enable peripheral clocks --------------------------------------------------*/
  /* GPIOA, GPIOB and SPI1 clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_SPI1, ENABLE);

  /* SPI2 Periph clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
}

/**
  * @brief  Configures the different GPIO ports.
  * @param  None
  * @retval None
  */
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Configure SPI1 pins: SCK, MISO and MOSI ---------------------------------*/
  /* Confugure SCK and MOSI pins as Alternate Function Push Pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  /* Confugure MISO pin as Input Floating  */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  
  /* Configure SPI2 pins: SCK, MISO and MOSI ---------------------------------*/
  /* Confugure SCK and MOSI pins as Input Floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  /* Confugure MISO pin as Alternate Function Push Pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

}

/**
  * @brief  Compares two buffers.
  * @param  pBuffer1, pBuffer2: buffers to be compared.
  * @param  BufferLength: buffer's length
  * @retval PASSED: pBuffer1 identical to pBuffer2
  *         FAILED: pBuffer1 differs from pBuffer2
  */
TestStatus Buffercmp(uint16_t* pBuffer1, uint16_t* pBuffer2, uint16_t BufferLength)
{
  while (BufferLength--)
  {
    if (*pBuffer1 != *pBuffer2)
    {
      return FAILED;
    }

    pBuffer1++;
    pBuffer2++;
  }

  return PASSED;
}

#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {}
}

#endif

/**
  * @}
  */

/**
  * @}
  */

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
此帖出自stm32/stm8论坛
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表