中级会员
- 积分
- 361
- 金钱
- 361
- 注册时间
- 2015-12-26
- 在线时间
- 115 小时
|
发表于 2016-7-27 21:51:32
|
显示全部楼层
//发送数据
u8 NRF_SendPayload(const u8 ack,const u8 *addr,const u8 channel,const u8 *buf)
{
u16 i=1;
NRF_CE = 0;
NRF_WriteBuf(W_REGISTER+TX_ADDR, addr, MAC_LEN);//写TX节点地址
if(ack)
{
NRF_WriteBuf(W_REGISTER+RX_ADDR_P0, addr, MAC_LEN);//写通道0,RX地址
}
NRF_WriteReg(W_REGISTER+RF_CH, channel);//设置RF通信频率
NRF_WriteReg(FLUSH_TX, 0xff);//清发送FIFO
NRF_WriteBuf(W_TX_PAYLOAD, buf, PAYLOAD_LEN);
NRF_WriteReg(W_REGISTER+CONFIG, 0x0A);//RX_DR,TX_DS,MAX_RT中断使能,CRC:8,POWER_UP,发送模式
NRF_CE = 1;//设置CE为高启动发射,CE高电平持续时间最小为10us
NRF_DelayUs(10);
#ifdef DEBUG
TIM_MeasureStart();//开始计时
#endif
while(i++)
{
if(TranFinish_flag)
{
TranFinish_flag = 0;
#ifdef DEBUG
TIM_MeasureStop();//计算发送时间
printf("TranFinish\r\n");
#endif
return TRUE;
}
if(Timeout)
{
#ifdef DEBUG
printf("MAX_RT\r\n");
#endif
Timeout = 0;
NRF_WriteReg(FLUSH_TX, 0xff);//清发送FIFO
return FALSE;
}
}
#ifdef DEBUG
printf("TranTimeout\r\n");
#endif
NRF_WriteReg(W_REGISTER+STATUS, IRQ_ALL);//清除状态标志
NRF_WriteReg(FLUSH_RX, 0xff);//清接收FIFO
NRF_WriteReg(FLUSH_TX, 0xff);//清发送FIFO
return FALSE;
}
//接收模式
void NRF_RxMode(const u8 *addr,const u8 channel)
{
NRF_CE = 0;
NRF_WriteBuf(W_REGISTER+RX_ADDR_P0, addr, MAC_LEN);//写RX节点地址
NRF_WriteReg(W_REGISTER+RF_CH, channel);//设置RF通信频率
NRF_WriteReg(FLUSH_RX, 0xff);//清接收FIFO
NRF_WriteReg(W_REGISTER+CONFIG, 0x0B);//RX_DR,TX_DS,MAX_RT中断使能,CRC:8,POWER_UP,接收模式
NRF_CE = 1;//CE为高,进入接收模式
} |
|