/**
*    文件: NRF24L01-Receiver.ino      by 零知实验室(www.lingzhilab.com)
*    -^^- 零知开源，让电子制作变得更简单！ -^^-
*    时间: 2018/10/19 15:11
*    说明: 
**/

#include <SPI.h>
#include "nRF24L01_STM32.h"
#include "RF24_STM32.h"

//使用 SPI-1; CE:9, CSN:10
RF24 radio(9,10);

//地址
//byte address[][6] = {"1Node","2Node"}; 

const uint64_t address[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };


void setup(){
   
  Serial.begin(9600);
  delay(1000);
 
  Serial.println("RF24L01 Receiver");
  
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);

  radio.begin();

  // 配置
  radio.setRetries(15,15); //失败请求的时间和次数0~15，setRetries(delay,count);延时：delay*250us, 次数：count
  radio.setChannel(0x4c);//通道:0~125
  radio.setPALevel(RF24_PA_LOW);

  //地址
  radio.openWritingPipe(address[1]);
  radio.openReadingPipe(1,address[0]);


  //开始监听
  radio.startListening();

  //NRF的配置信息，用于调试
  radio.printDetails();
}

void loop(){
  
  unsigned long time_buff = 0;//接收到的数据
 
  //接收到信息
  if ( radio.available() ) 
  {                          
	  radio.read( &time_buff, sizeof(time_buff));   
															
	  Serial.print("Received: "); 
	  Serial.println(time_buff);

  }
  
}


