使用SPI的CRC校验的时候   每次都是发现同样的数据 0XAA 但是后面发生的SPI CRC校验值都是不一样的,这是什么原因  求指点 求讨论。 
 
int main(void) 
{ 
  unsigned char temp_data,p[3]; 
  SystemInit(); 
  RCC_Configuration(); 
 
  SPI2_Init(); 
 
  LED_GPIO_Config(); 
  LED1(OFF); 
   
  while (1) 
  { 
        SPI2_CS_LOW(); 
         
        while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); 
         
        SPI_I2S_SendData(SPI2, 0xAA);                                 
        SPI_TransmitCRC(SPI2); 
        while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET); 
        p[0]= SPI_I2S_ReceiveData(SPI2);                         
        while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET); 
        if ((SPI_I2S_GetFlagStatus(SPI2, SPI_FLAG_CRCERR)) == SET) 
        { 
                p[2]=1; 
        } 
        else         p[2]=0; 
        p[1] = SPI_I2S_ReceiveData(SPI2); 
        SPI2_CS_HIGH(); 
        Delay(0xff); 
  } 
} 
 
 
void SPI2_Init(void) 
{ 
  SPI_InitTypeDef  SPI_InitStructure; 
  GPIO_InitTypeDef GPIO_InitStructure; 
 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE); 
 
  /*!< SPI_FLASH_SPI Periph clock enable */ 
   
  /*!< AFIO Periph clock enable */ 
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); 
   
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); 
 
  /*!< Configure SPI_FLASH_SPI pins: SCK */ 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
  GPIO_Init(GPIOB, &GPIO_InitStructure); 
 
  /*!< Configure SPI_FLASH_SPI pins: MISO */ 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; 
  GPIO_Init(GPIOB, &GPIO_InitStructure); 
 
  /*!< Configure SPI_FLASH_SPI pins: MOSI */ 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; 
  GPIO_Init(GPIOB, &GPIO_InitStructure); 
 
  /*!< Configure SPI_FLASH_SPI_CS_PIN pin: SPI_FLASH Card CS pin */ 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; 
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 
  GPIO_Init(GPIOB, &GPIO_InitStructure); 
 
  /* Deselect the FLASH: Chip Select high */ 
  //SPI2_CS_HIGH(); 
 
  /* SPI2 configuration */ 
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; 
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master; 
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; 
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;        //CPOL=0 时钟悬空低 
  //SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; 
  //SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;            //CPHA=0 数据捕获第1个 
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; 
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; 
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; 
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; 
  SPI_InitStructure.SPI_CRCPolynomial = 7; 
 
// SPI_CR1|=(1<<13); 
 
  SPI_Init(SPI2, &SPI_InitStructure); 
// SPI_CalculateCRC(SPI1,ENABLE); 
  SPI_CalculateCRC(SPI2,ENABLE); 
  /* Enable SPI2  */ 
  SPI_Cmd(SPI2, ENABLE); 
 
} 
 |   
     
  
 |