我在使用SPI时,总是出现OVR标志。有谁碰到过这种情况吧,下面是部分代码: //------------------SPI 初始化部分---------------- /* 1st phase: SPI1 Master and SPI2 Slave */ /* SPI1 Config -------------------------------------------------------------*/ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_Init(SPI1, &SPI_InitStructure); /* Enable SPI1 */ SPI_Cmd(SPI1, ENABLE);
//实际工作部分,我直接连接了SPI1的MISO和MOSI引脚,实现SPI1的自环测试
GPIO_ResetBits(GPIOB,GPIO_Pin_15); //对外的cs选择,暂时无效了
/* Wait for SPI1 Tx buffer empty */ while(SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE)==RESET); //发送数据 SPI_SendData(SPI1,0x81); //接收并丢弃收到的数据 if(SPI_GetFlagStatus(SPI1,SPI_FLAG_RXNE) == SET) SPI_ReceiveData(SPI1);
while(SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE)==RESET); SPI_SendData(SPI1,0x00); //一旦发送完毕,就出现SPI_FLAG_OVR标志, if(SPI_GetFlagStatus(SPI1,SPI_FLAG_RXNE) == SET) SPI_ReceiveData(SPI1); while(SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE)==RESET); SPI_SendData(SPI1,0x3C); GPIO_SetBits(GPIOB,GPIO_Pin_15);
|