//此處注釋的方法與正在使用的方法除了一個是自減,一個是自增外完全一致,但是注釋的方法卻是錯誤的 static?uint8_t?FLASH_SPI_SendAReceiveByte(uint8_t?data) { //????SPITimeout?=?200; ????SPITimeout?=?0; ????while(SPI_I2S_GetFlagStatus(FLASH_SPIx,?SPI_I2S_FLAG_TXE)?==?RESET)//檢測上一個字節(jié)是否發(fā)送完成 ????{ //????????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)//檢測是否接受到一個字節(jié) ????{ //????????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文件中,大佬可以看看解答我的疑問
熱門產(chǎn)品 :
CH592: RISC-V內(nèi)核BLE5.4無線MCU