//此处注释的方法与正在使用的方法除了一个是自减,一个是自增外完全一致,但是注释的方法却是错误的 static?uint8_t?FLASH_SPI_SendAReceiveByte(uint8_t?data) { //????SPITimeout?=?200; ????SPITimeout?=?0; ????while(SPI_I2S_GetFlagStatus(FLASH_SPIx,?SPI_I2S_FLAG_TXE)?==?RESET)//检测上一个字节是否发送完成 ????{ //????????SPITimeout--; //????????if(SPITimeout) //????????????return?SPI_TIMEOUT_UserCallback(0); ????????SPITimeout++; ????????if(SPITimeout?>?200) ????????????return?SPI_TIMEOUT_UserCallback(0); ????} ????SPI_I2S_SendData(FLASH_SPIx,?data); //????SPITimeout?=?200; ????SPITimeout?=?0; ????while(SPI_I2S_GetFlagStatus(FLASH_SPIx,?SPI_I2S_FLAG_RXNE)?==?RESET)//检测是否接受到一个字节 ????{ //????????SPITimeout--; //????????if(SPITimeout) //????????????return?SPI_TIMEOUT_UserCallback(1); ????????SPITimeout++; ????????if(SPITimeout?>?200) ????????????return?SPI_TIMEOUT_UserCallback(1); ????} ????return?SPI_I2S_ReceiveData(FLASH_SPIx); }
上面的代码,只要把while里面注释的代码换成非注释的,检测接受的while就会出问题,请大神解答
附上实验文件,上面的代码片段在code文件的flash_spi.c文件中,大佬可以看看解答我的疑问
热门产品 :
CH634: 4端口USB3.0 HUB控制器芯片