|
如果你的沒調(diào)通可能下面幾個(gè)地方需要注意一下。
1.NRF24L01供電要穩(wěn)定。
2.SPI通訊必須要先測(cè)試好,可以先試著把接收地址寫進(jìn),在讀出來驗(yàn)證一下。
3.如果開了自動(dòng)應(yīng)答請(qǐng)注意,發(fā)送方的發(fā)送地址和第一通道接收地址是同為發(fā)送地址。
4.如果發(fā)送失敗,此時(shí)的發(fā)送fifo里面的數(shù)據(jù)是不會(huì)清空的,發(fā)送成功會(huì)自動(dòng)清空。
5.接收到數(shù)據(jù)后,接收FIFO需要清空。并且清除接收到數(shù)據(jù)的中斷標(biāo)志位。
- /*******************************************************************************
- * @brief SPI交換數(shù)據(jù)
- * @param None
- * @retval None
- ****************************************************************Author:Liming**/
- #ifdef HARD_SPI
- unsigned char SPI_RW(unsigned char byte) // 硬件SPI
- {
- SPDAT = byte; //觸發(fā)SPI發(fā)送
- while (!(SPSTAT & SPIF)); //等待SPI數(shù)據(jù)傳輸完成
- SPSTAT = SPIF | WCOL; //清除SPI狀態(tài)
-
- return SPDAT;
- }
- #else
- unsigned char SPI_RW(unsigned char byte) // 模擬SPI
- {
- unsigned char i;
- for(i=0;i<8;i++) // output 8-bit
- {
- SPI_MOSI = (byte & 0x80); // output 'uchar', MSB to MOSI
- byte = (byte << 1); // shift next bit into MSB..
- SPI_SCK = 1; // Set SCK high..
- byte |= SPI_MISO; // capture current MISO bit
- SPI_SCK = 0; // ..then set SCK low again
- }
- return(byte); // return read uchar
- }
- #endif
復(fù)制代碼 |
評(píng)分
-
查看全部評(píng)分
|