stm32nrf为什么接收不到数据的问题!
#include "nrf24l01.h"
#include "sys.h"
#include "delay.h"
#define uchar unsigned char
#define uint unsigned int
uchar TX_DATA[4];
uint8_t NRF24L01_RXDATA[RX_PLOAD_WIDTH];//nrf24l01?óê?μ?μ?êy?Y
uint8_t NRF24L01_TXDATA[RX_PLOAD_WIDTH];//nrf24l01Dèòa·¢?íμ?êy?Y
u8 TX_ADDRESS[TX_ADR_WIDTH]= {0xE1,0xE2,0xE3,0xE4,0xE5}; //±?μ?μ??·
u8 RX_ADDRESS[RX_ADR_WIDTH]= {0xE1,0xE2,0xE3,0xE4,0xE5}; //?óê?μ??·
/*
*****************************************************************
* D′??′??÷
*****************************************************************
*/
uint8_t NRF_Write_Reg(uint8_t reg, uint8_t value)
{
uint8_t status;
SPI_CSN_L(); /* ??í¨?÷?t */
status = Spi_RW(reg); /* D′??′??÷μ??· */
Spi_RW(value); /* D′êy?Y */
SPI_CSN_H(); /* ???1???÷?t */
return status;
}
/*
*****************************************************************
* ?á??′??÷
*****************************************************************
*/
uint8_t NRF_Read_Reg(uint8_t reg)
{
uint8_t reg_val;
SPI_CSN_L(); /* ??í¨?÷?t */
Spi_RW(reg); /* D′??′??÷μ??· */
reg_val = Spi_RW(0); /* ?áè?????′??÷·μ??êy?Y */
SPI_CSN_H(); /* ???1???÷?t */
return reg_val;
}
/*
*****************************************************************
*
* D′?o3???
*
*****************************************************************
*/
uint8_t NRF_Write_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars)
{
uint8_t i;
uint8_t status;
SPI_CSN_L(); /* ??í¨?÷?t */
status = Spi_RW(reg); /* D′??′??÷μ??· */
for(i=0; i<uchars; i++)
{
Spi_RW(pBuf[i]); /* D′êy?Y */
}
SPI_CSN_H(); /* ???1???÷?t */
return status;
}
/*
*****************************************************************
* ?á?o3???
*****************************************************************
*/
uint8_t NRF_Read_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars)
{
uint8_t i;
uint8_t status;
SPI_CSN_L(); /* ??í¨?÷?t */
status = Spi_RW(reg); /* D′??′??÷μ??· */
for(i=0; i<uchars; i++)
{
pBuf[i] = Spi_RW(0); /* ?áè?·μ??êy?Y */
}
SPI_CSN_H(); /* ???1???÷?t */
return status;
}
/*
*****************************************************************
* D′êy?Y°ü
*****************************************************************
*/
void NRF_TxPacket(uint8_t * tx_buf, uint8_t len)
{
SPI_CE_L(); //StandBy I?£ê?
NRF_Write_Buf(WR_TX_PLOAD, tx_buf, len); // ×°??êy?Y
SPI_CE_H(); //????CE£??¤·¢êy?Y·¢?í
}
void NRF_TxPacket_AP(uint8_t * tx_buf, uint8_t len)
{
SPI_CE_L(); //StandBy I?£ê?
NRF_Write_Buf(0xa8, tx_buf, len); // ×°??êy?Y
SPI_CE_H(); //????CE
}
u8 Nrf24l01_Check(void)
{
u8 buf1[5];
u8 i;
/*D′è?5??×??úμ?μ??·. */
NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,5);
/*?á3?D′è?μ?μ??· */
NRF_Read_Buf(TX_ADDR,buf1,5);
/*±è??*/
for(i=0;i<5;i++)
{
if(buf1[i]!=TX_ADDRESS[i])
break;
}
if(i==5)
return SUCCESS ; //MCUó?NRF3é1|á??ó
else
return ERROR ; //MCUó?NRF2??y3£á??ó
}
void Nrf24l01_Init(u8 model)
{
SPI_CE_L();
NRF_Write_Buf(NRF_WRITE_REG+RX_ADDR_P0,RX_ADDRESS,RX_ADR_WIDTH); //D′RX?úμ?μ??·
NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,TX_ADR_WIDTH); //D′TX?úμ?μ??·
NRF_Write_Reg(NRF_WRITE_REG+EN_AA,0x00); //ê1?üí¨μà0μ?×??ˉó|′e
NRF_Write_Reg(NRF_WRITE_REG+EN_RXADDR,0x01); //ê1?üí¨μà0μ??óê?μ??·
NRF_Write_Reg(NRF_WRITE_REG+SETUP_RETR,0x00); //éè??×??ˉ??·¢????ê±??:500us;×?′ó×??ˉ??·¢′?êy:10′?
NRF_Write_Reg(NRF_WRITE_REG+RF_CH,40); //éè??RFí¨μà?aCHANAL
NRF_Write_Reg(NRF_WRITE_REG+RF_SETUP,0x0f); //éè??TX·¢é?2?êy,0db??ò?,2Mbps,μí??éù??ò??a??
if(model==1) //RX
{
NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //????í¨μà0μ?óDD§êy?Y?í?è
NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQê?·¢íê3é?D???a??,16??CRC,?÷?óê?
}
else if(model==2) //TX
{
NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //????í¨μà0μ?óDD§êy?Y?í?è
NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQê?·¢íê3é?D???a??,16??CRC,?÷·¢?í
}
else if(model==3) //RX2
{
NRF_Write_Reg(FLUSH_TX,0xff);
NRF_Write_Reg(FLUSH_RX,0xff);
NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQê?·¢íê3é?D???a??,16??CRC,?÷?óê?
Spi_RW(0x50);
Spi_RW(0x73);
NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01);
NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06);
}
else //TX2
{
NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQê?·¢íê3é?D???a??,16??CRC,?÷·¢?í
NRF_Write_Reg(FLUSH_TX,0xff);
NRF_Write_Reg(FLUSH_RX,0xff);
Spi_RW(0x50);
Spi_RW(0x73);
NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01);
NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06);
}
SPI_CE_H();
}
u8 NRF24L01_RxPacket(u8 *rxbuf)
{
u8 state,flag;
state=NRF_Read_Reg(NRF_READ_REG+NRFRegSTATUS);
NRF_Write_Reg(NRF_WRITE_REG+NRFRegSTATUS,state);
if(NRFRegSTATUS&RX_DR) // ?D??ê?·??óê?μ?êy?Y
{
NRF_Read_Buf(RD_RX_PLOAD ,rxbuf,RX_PLOAD_WIDTH);// ′óRXFIFO?áè?êy?Y ?óê?4???′?é£?oóò??????áê???
NRF_Write_Reg(FLUSH_RX,0xff);//ó?óú????FIFO £?£?1??ü£?£?2?è??á3???òa??2?μ?μ?oó1?£?£?£?′ó?ò??×?£?
flag=1;
return flag;
}
}
u8 rx_buf[32];
extern unsigned char TX_DATA[4];
u8 NRF_Get_State(void)
{
u8 status;
status=NRF_Read_Reg(NRF_READ_REG + NRFRegSTATUS);
return status;
}
u8 NRF_Get_FIFOState(void)
{
u8 FIFO_status;
FIFO_status=NRF_Read_Reg(NRF_READ_REG + FIFO_STATUS);
return FIFO_status;
}
int main()
{
u8 sta,Flag;
u8 FIFO_sta;
RCC_Init(); // ê±?ó????
Timer3_Init(); //?¨ê±?÷33?ê??ˉ
USART1_Init(); // USART13?ê??ˉ
Spi3_Init();
Nrf24l01_Init(MODEL_RX);
GPIO_Config();
while(1)
{
NRF24L01_RxPacket(rx_buf);
sta=NRF_Get_State();
FIFO_sta=NRF_Get_FIFOState();
if (sta==0x40 || Flag==NRF24L01_RxPacket(rx_buf))
{
GPIO_SetBits(GPIOD, GPIO_Pin_13);
Delay_ms(500);
GPIO_ResetBits(GPIOD, GPIO_Pin_13);
Delay_ms(500);
}
if(rx_buf[0]==2||rx_buf[1]==1||rx_buf[2]==15)
{
GPIO_ResetBits(GPIOG, GPIO_Pin_14);
Delay_ms(500);
GPIO_SetBits(GPIOG, GPIO_Pin_14);
Delay_ms(500);
}
}
}
下面是发送程序,statue的值为0x2e,fifostatus的值为0x11
#include "nrf24l01.h"
#include "sys.h"
#include "delay.h"
#include "RCC_config.h"
#define uchar unsigned char
#define uint unsigned int
uchar TX_DATA[4];
uint8_t NRF24L01_RXDATA[RX_PLOAD_WIDTH];//nrf24l01?óê?μ?μ?êy?Y
uint8_t NRF24L01_TXDATA[RX_PLOAD_WIDTH];//nrf24l01Dèòa·¢?íμ?êy?Y
u8 TX_ADDRESS[TX_ADR_WIDTH]= {0xE1,0xE2,0xE3,0xE4,0xE5}; //±?μ?μ??·
u8 RX_ADDRESS[RX_ADR_WIDTH]= {0xE1,0xE2,0xE3,0xE4,0xE5}; //?óê?μ??·
/*
*****************************************************************
* D′??′??÷
*****************************************************************
*/
uint8_t NRF_Write_Reg(uint8_t reg, uint8_t value)
{
uint8_t status;
SPI_CSN_L(); /* ??í¨?÷?t */
status = Spi_RW(reg); /* D′??′??÷μ??· */
Spi_RW(value); /* D′êy?Y */
SPI_CSN_H(); /* ???1???÷?t */
return status;
}
/*
*****************************************************************
* ?á??′??÷
*****************************************************************
*/
uint8_t NRF_Read_Reg(uint8_t reg)
{
uint8_t reg_val;
SPI_CSN_L(); /* ??í¨?÷?t */
Spi_RW(reg); /* D′??′??÷μ??· */
reg_val = Spi_RW(0); /* ?áè?????′??÷·μ??êy?Y */
SPI_CSN_H(); /* ???1???÷?t */
return reg_val;
}
/*
*****************************************************************
*
* D′?o3???
*
*****************************************************************
*/
uint8_t NRF_Write_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars)
{
uint8_t i;
uint8_t status;
SPI_CSN_L(); /* ??í¨?÷?t */
status = Spi_RW(reg); /* D′??′??÷μ??· */
for(i=0; i<uchars; i++)
{
Spi_RW(pBuf[i]); /* D′êy?Y */
}
SPI_CSN_H(); /* ???1???÷?t */
return status;
}
/*
*****************************************************************
* ?á?o3???
*****************************************************************
*/
uint8_t NRF_Read_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars)
{
uint8_t i;
uint8_t status;
SPI_CSN_L(); /* ??í¨?÷?t */
status = Spi_RW(reg); /* D′??′??÷μ??· */
for(i=0; i<uchars; i++)
{
pBuf[i] = Spi_RW(0); /* ?áè?·μ??êy?Y */
}
SPI_CSN_H(); /* ???1???÷?t */
return status;
}
/*
*****************************************************************
* D′êy?Y°ü
*****************************************************************
*/
void NRF_TxPacket(uint8_t * tx_buf, uint8_t len)
{
SPI_CE_L(); //StandBy I?£ê?
NRF_Write_Buf(WR_TX_PLOAD, tx_buf, len); // ×°??êy?Y
SPI_CE_H(); //????CE£??¤·¢êy?Y·¢?í
}
void NRF_TxPacket_AP(uint8_t * tx_buf, uint8_t len)
{
SPI_CE_L(); //StandBy I?£ê?
NRF_Write_Buf(0xa8, tx_buf, len); // ×°??êy?Y
SPI_CE_H(); //????CE
}
u8 Nrf24l01_Check(void)
{
u8 buf1[5];
u8 i;
/*D′è?5??×??úμ?μ??·. */
NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,5);
/*?á3?D′è?μ?μ??· */
NRF_Read_Buf(TX_ADDR,buf1,5);
/*±è??*/
for(i=0;i<5;i++)
{
if(buf1[i]!=TX_ADDRESS[i])
break;
}
if(i==5)
return SUCCESS ; //MCUó?NRF3é1|á??ó
else
return ERROR ; //MCUó?NRF2??y3£á??ó
}
void Nrf24l01_Init(u8 model)
{
SPI_CE_L();
NRF_Write_Buf(NRF_WRITE_REG+RX_ADDR_P0,TX_ADDRESS,RX_ADR_WIDTH); //D′RX?úμ?μ??·
NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,TX_ADR_WIDTH); //D′TX?úμ?μ??·
NRF_Write_Reg(NRF_WRITE_REG+EN_AA,0x00); //ê1?üí¨μà0μ?×??ˉó|′e
NRF_Write_Reg(NRF_WRITE_REG+EN_RXADDR,0x00); //ê1?üí¨μà0μ??óê?μ??·
NRF_Write_Reg(NRF_WRITE_REG+SETUP_RETR,0x00); //éè??×??ˉ??·¢????ê±??:500us;×?′ó×??ˉ??·¢′?êy:10′?
NRF_Write_Reg(NRF_WRITE_REG+RF_CH,40); //éè??RFí¨μà?aCHANAL
NRF_Write_Reg(NRF_WRITE_REG+RF_SETUP,0x0f); //éè??TX·¢é?2?êy,0db??ò?,2Mbps,μí??éù??ò??a??
if(model==1) //RX
{
NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //????í¨μà0μ?óDD§êy?Y?í?è
NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQê?·¢íê3é?D???a??,16??CRC,?÷?óê?
}
else if(model==2) //TX
{
NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //????í¨μà0μ?óDD§êy?Y?í?è
NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQê?·¢íê3é?D???a??,16??CRC,?÷·¢?í
}
else if(model==3) //RX2
{
NRF_Write_Reg(FLUSH_TX,0xff);
NRF_Write_Reg(FLUSH_RX,0xff);
NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQê?·¢íê3é?D???a??,16??CRC,?÷?óê?
Spi_RW(0x50);
Spi_RW(0x73);
NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01);
NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06);
}
else //TX2
{
NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQê?·¢íê3é?D???a??,16??CRC,?÷·¢?í
NRF_Write_Reg(FLUSH_TX,0xff);
NRF_Write_Reg(FLUSH_RX,0xff);
Spi_RW(0x50);
Spi_RW(0x73);
NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01);
NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06);
}
SPI_CE_H();
}
u8 NRF24L01_RxPacket(u8 *rxbuf)
{
u8 state,flag;
state=NRF_Read_Reg(NRF_READ_REG+NRFRegSTATUS);
NRF_Write_Reg(NRF_WRITE_REG+NRFRegSTATUS,state);
if(NRFRegSTATUS&RX_DR) // ?D??ê?·??óê?μ?êy?Y
{
NRF_Read_Buf(RD_RX_PLOAD ,rxbuf,RX_PLOAD_WIDTH);// ′óRXFIFO?áè?êy?Y ?óê?4???′?é£?oóò??????áê???
NRF_Write_Reg(FLUSH_RX,0xff);//ó?óú????FIFO £?£?1??ü£?£?2?è??á3???òa??2?μ?μ?oó1?£?£?£?′ó?ò??×?£?
flag=1;
return flag;
}
return 0;
}
u8 rx_buf[32];
u8 send[32]={2,1,15,3,6,4,7,8,9,0};
extern unsigned char TX_DATA[4];
u8 NRF_Get_State(void)
{
u8 status;
status=NRF_Read_Reg(NRF_READ_REG + NRFRegSTATUS);
return status;
}
u8 NRF_Get_FIFOState(void)
{
u8 FIFO_status;
FIFO_status=NRF_Read_Reg(NRF_READ_REG + FIFO_STATUS);
return FIFO_status;
}
int main()
{
u8 sta;
u8 FIFO_sta;
RCC_Init(); // ê±?ó????
Timer3_Init(); //?¨ê±?÷33?ê??ˉ
USART1_Init(); // USART13?ê??ˉ
GPIO_Config();
Spi2_Init();
Nrf24l01_Init(MODEL_TX);
while(1)
{
while (1)
{
if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == Bit_RESET)
{
NRF_TxPacket(send,10);
GPIO_ResetBits(GPIOF, GPIO_Pin_7); /* μ?ááLED0 */
Delay_ms(500);
Delay_ms(500);
break;
}
}
while (1)
{
if ((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == Bit_SET))
{
GPIO_SetBits(GPIOF, GPIO_Pin_7); /* 1?±?LED0 */
break;
}
}
sta=NRF_Get_State();
FIFO_sta=NRF_Get_FIFOState();
if (sta==0x2e)
{
GPIO_ResetBits(GPIOF, GPIO_Pin_8);
Delay_ms(500);
GPIO_SetBits(GPIOF, GPIO_Pin_8);
Delay_ms(500);
GPIO_ResetBits(GPIOF, GPIO_Pin_9);
Delay_ms(500);
GPIO_SetBits(GPIOF, GPIO_Pin_9);
Delay_ms(500);
}
if (FIFO_sta==0x11)
{
int i;
for (i=0;i<100;i++)
{
GPIO_ResetBits(GPIOF, GPIO_Pin_6);
Delay_ms(100);
GPIO_SetBits(GPIOF, GPIO_Pin_6);
Delay_ms(100);
}
}
这是后面的
uint8_t NRF_Write_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars)
{
uint8_t i;
uint8_t status;
SPI_CSN_L(); /* ??í¨?÷?t */
status = Spi_RW(reg); /* D′??′??÷μ??· */
for(i=0; i<uchars; i++)
{
Spi_RW(pBuf[i]); /* D′êy?Y */
}
SPI_CSN_H(); /* ???1???÷?t */
return status;
}
/*
*****************************************************************
* ?á?o3???
*****************************************************************
*/
uint8_t NRF_Read_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars)
{
uint8_t i;
uint8_t status;
SPI_CSN_L(); /* ??í¨?÷?t */
status = Spi_RW(reg); /* D′??′??÷μ??· */
for(i=0; i<uchars; i++)
{
pBuf[i] = Spi_RW(0); /* ?áè?·μ??êy?Y */
}
SPI_CSN_H(); /* ???1???÷?t */
return status;
}
/*
*****************************************************************
* D′êy?Y°ü
*****************************************************************
*/
void NRF_TxPacket(uint8_t * tx_buf, uint8_t len)
{
SPI_CE_L(); //StandBy I?£ê?
NRF_Write_Buf(WR_TX_PLOAD, tx_buf, len); // ×°??êy?Y
SPI_CE_H(); //????CE£??¤·¢êy?Y·¢?í
}
void NRF_TxPacket_AP(uint8_t * tx_buf, uint8_t len)
{
SPI_CE_L(); //StandBy I?£ê?
NRF_Write_Buf(0xa8, tx_buf, len); // ×°??êy?Y
SPI_CE_H(); //????CE
}
u8 Nrf24l01_Check(void)
{
u8 buf1[5];
u8 i;
/*D′è?5??×??úμ?μ??·. */
NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,5);
/*?á3?D′è?μ?μ??· */
NRF_Read_Buf(TX_ADDR,buf1,5);
/*±è??*/
for(i=0;i<5;i++)
{
if(buf1[i]!=TX_ADDRESS[i])
break;
}
if(i==5)
return SUCCESS ; //MCUó?NRF3é1|á??ó
else
return ERROR ; //MCUó?NRF2??y3£á??ó
}
void Nrf24l01_Init(u8 model)
{
SPI_CE_L();
NRF_Write_Buf(NRF_WRITE_REG+RX_ADDR_P0,RX_ADDRESS,RX_ADR_WIDTH); //D′RX?úμ?μ??·
NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,TX_ADR_WIDTH); //D′TX?úμ?μ??·
NRF_Write_Reg(NRF_WRITE_REG+EN_AA,0x00); //ê1?üí¨μà0μ?×??ˉó|′e
NRF_Write_Reg(NRF_WRITE_REG+EN_RXADDR,0x01); //ê1?üí¨μà0μ??óê?μ??·
NRF_Write_Reg(NRF_WRITE_REG+SETUP_RETR,0x00); //éè??×??ˉ??·¢????ê±??:500us;×?′ó×??ˉ??·¢′?êy:10′?
NRF_Write_Reg(NRF_WRITE_REG+RF_CH,40); //éè??RFí¨μà?aCHANAL
NRF_Write_Reg(NRF_WRITE_REG+RF_SETUP,0x0f); //éè??TX·¢é?2?êy,0db??ò?,2Mbps,μí??éù??ò??a??
if(model==1) //RX
{
NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //????í¨μà0μ?óDD§êy?Y?í?è
NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQê?·¢íê3é?D???a??,16??CRC,?÷?óê?
}
else if(model==2) //TX
{
NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //????í¨μà0μ?óDD§êy?Y?í?è
NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQê?·¢íê3é?D???a??,16??CRC,?÷·¢?í
}
else if(model==3) //RX2
{
NRF_Write_Reg(FLUSH_TX,0xff);
NRF_Write_Reg(FLUSH_RX,0xff);
NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQê?·¢íê3é?D???a??,16??CRC,?÷?óê?
Spi_RW(0x50);
Spi_RW(0x73);
NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01);
NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06);
}
else //TX2
{
NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQê?·¢íê3é?D???a??,16??CRC,?÷·¢?í
NRF_Write_Reg(FLUSH_TX,0xff);
NRF_Write_Reg(FLUSH_RX,0xff);
Spi_RW(0x50);
Spi_RW(0x73);
NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01);
NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06);
}
SPI_CE_H();
}
u8 NRF24L01_RxPacket(u8 *rxbuf)
{
u8 state,flag;
state=NRF_Read_Reg(NRF_READ_REG+NRFRegSTATUS);
NRF_Write_Reg(NRF_WRITE_REG+NRFRegSTATUS,state);
if(NRFRegSTATUS&RX_DR) // ?D??ê?·??óê?μ?êy?Y
{
NRF_Read_Buf(RD_RX_PLOAD ,rxbuf,RX_PLOAD_WIDTH);// ′óRXFIFO?áè?êy?Y ?óê?4???′?é£?oóò??????áê???
NRF_Write_Reg(FLUSH_RX,0xff);//ó?óú????FIFO £?£?1??ü£?£?2?è??á3???òa??2?μ?μ?oó1?£?£?£?′ó?ò??×?£?
flag=1;
return flag;
}
}
额,代码还长,看起来真的是有心无力啊!小编保重~