nrf24L01接收端只觸發(fā)一次中斷解決辦法
曲曲折折一個(gè)月,終于找到具體原因了,中途雖然能接收到數(shù)據(jù),但是總是感覺心里有個(gè)梗,不爽。。。
Nrf24L01接收端接收不到數(shù)據(jù)、接收數(shù)據(jù)不穩(wěn)定、中斷只觸發(fā)一次等等,都可能是這個(gè)原因。
我們都知道,接收端接收到數(shù)據(jù),處理完數(shù)據(jù)后要清空接收反沖區(qū)。FLUSH_RX:清空RX FIFO寄存器
NRF2_SPI_WriteReg(FLUSH_RX,0xFF);??//清除RX?FIFO寄存器
但是關(guān)鍵的一點(diǎn)就是清空RX FIFO寄存器的時(shí)間。
官方數(shù)據(jù)手冊(cè)中有一句話,F(xiàn)lush RX FIFO, used in RX mode Should not be executed during transmission of acknowledge, that is, acknowledge package will not be completed.在傳輸應(yīng)答信號(hào)過程中不應(yīng)執(zhí)行此指令,也就是說,若傳輸應(yīng)答信號(hào)過程中執(zhí)行此指令的話將使得應(yīng)答信號(hào)不能被完整傳輸。當(dāng)接收端的應(yīng)答信號(hào)不能返回到發(fā)送端的時(shí)候,就會(huì)一直處于發(fā)送模式,所以再也無法觸發(fā)接收中斷了。
解決辦法:
當(dāng)觸發(fā)接收中斷的時(shí)候,不立馬清空RX FIFO,而延時(shí)一段時(shí)間,在讀取接收數(shù)據(jù)和清空RX FIFO;
詳細(xì)注解代碼:
void?EXTI9_5_IRQHandler(void)???????????????????//觸發(fā)中斷服務(wù)函數(shù)?? {?? ????u8?state;?? ????u8?rxbuf[32];???????????????????????????????//接收緩沖區(qū)?? ????Delay_ms(1);????????????????????????????????//重要,延時(shí)等待AKC發(fā)送完成,再處理數(shù)據(jù),時(shí)間自行調(diào)試和把握?? ????if(EXTI_GetITStatus(EXTI_Line7)?!=?RESET)???????????????????//確保是否產(chǎn)生了EXTI?Line中斷?? ????{?? ????????NRF2_CE_LOW();???????????????????????????????????????????//24l01進(jìn)入待機(jī)狀態(tài),讀取數(shù)據(jù)的時(shí)候CE要拉低?? ????????state=NRF2_SPI_ReadReg(STATUS);??????????????????????????/*讀取status寄存器的值??*/?? ????????NRF2_SPI_ReadBuf(RD_RX_PLOAD,rxbuf,RX_PLOAD_WIDTH);??????//讀取數(shù)據(jù)?到rxbuf中?? ????????...??????????????????????????????????????????????????????//數(shù)據(jù)處理代碼?? ????????NRF2_SPI_WriteReg(NRF_WRITE_REG+STATUS,state);???????????/*清除24L01接收中斷標(biāo)志*/?? ????????NRF2_SPI_WriteReg(FLUSH_RX,0xFF);????????????????????????//清除RX?FIFO寄存器?? ????????NRF2_CE_HIGH();??????????????????????????????????????????//24l01回到接收模式?? ????????EXTI_ClearITPendingBit(EXTI_Line7);??????????????????????//清除stm32中斷標(biāo)志位?? ????} }
以上只是我自己碰到的問題的解決辦法,每個(gè)人可能不一樣。無線這種看不見摸不著的真能調(diào)到你懷疑人生,分享出來能救一個(gè)是一個(gè),畢竟勝造七級(jí)浮屠。