不晓得怎么回事,一直发送失败,有没有nrf24l01的例子给我参考一下,或者大神帮我看看问题在哪
- u8 NRF_WriteReg(u8 reg,u8 val)
- {
- u8 temp;
- NRF24L01_CSN_0;
- temp=SPI3_SendReceiveByte(reg);
- SPI3_SendReceiveByte(val);
- NRF24L01_CSN_1;
- return temp;
- }
- u8 NRF_ReadReg(u8 reg)
- {
- u8 val;
- NRF24L01_CSN_0;
- SPI3_SendReceiveByte(reg);
- val=SPI3_SendReceiveByte(0xff);
- NRF24L01_CSN_1;
- return val;
- }
- u8 NRF_ReadBuf(u8 reg,u8 *buff,u8 num)
- {
- u8 i,val;
- NRF24L01_CSN_0;
- val=SPI3_SendReceiveByte(reg);
- for(i=0;i<num;i++)
- *buff++=SPI3_SendReceiveByte(0xff);
- NRF24L01_CSN_1;
- return val;
- }
- u8 NRF_WriteBuf(u8 reg,u8 *buff,u8 num)
- {
- u8 val,i;
- NRF24L01_CSN_0;
- val=SPI3_SendReceiveByte(reg);
- for(i=0;i<num;i++)
- SPI3_SendReceiveByte(*buff++);
- NRF24L01_CSN_1;
- return val;
- }
- u8 NRF_SendPacket(u8 *TxBuf)
- {
- u8 val;
- NRF24L01_CE_0;
- NRF_WriteBuf(WR_TX_PLOAD,TxBuf,TX_PLOAD_WIDTH);
- NRF24L01_CE_1;
- delay_ms(5);
- while(NRF24L01_IRQ!=0);
- val=NRF_ReadReg(STATUS);
- NRF_WriteReg(WRITE_REG,val);
- if(val&MAX_TX)
- {
- NRF_WriteReg(FLUSH_TX,0xff);
- return MAX_TX;
- }
- if(val&TX_OK)
- return TX_OK;
- return 0xff;
- }
复制代码
此帖出自
小平头技术问答
一周热门 更多>