我使用stm32f103ZET6控制外部flash芯片at45db161d。在读取flash内保存的数据的时候,有一定几率会出现在while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);死循环的状态。经测试好像数据量大的时候容易出现。我降低了通讯的速度,现象有所好转,但没有完全杜绝。请问还需要怎么处理。我的spi初始化如下:
/* Configure SPI2 pins: NSS, SCK, MISO and MOSI ---------------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* flash at45db161d select pin */
GPIO_InitStructure.GPIO_Pin= GPIO_Pin_14;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
NOSelect_SD();
/* flash SD select pin */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
NotSelect_Flash();
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//SPI_Direction_1Line_Tx;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;//SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;//SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;/* 72M/64=1.125M */
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
//SPI_I2S_DeInit(SPI2);
SPI_Init(SPI2, &SPI_InitStructure);
/* Enable SPI_MASTER */
SPI_Cmd(SPI2, ENABLE);
SPI_CalculateCRC(SPI2, DISABLE); |