void NRF_EnableRX(void)
{
  NRF_WriteRegister(NRF_STATUS, 0x7E);
  NRF_WriteRegister(NRF_CONFIG, 0x0F);
  NRF_SendCommand(NRF_FLUSH_RX, 0xFF);
  for (int i =0; i < 2; i++) {
    NRF_Delay();
  }
  NRF_CE_hi;
  for (int i =0; i < 2; i++) {
    NRF_Delay();
  }
  NRF_SendCommand(NRF_FLUSH_RX, 0xFF);
}
Beispiel #2
0
void
sender_enable()
{
	status = SENDER;
	NRF_CE_lo;
	NRF_WriteRegister(NRF_STATUS, 0x7E); // reset status register
        NRF_WriteRegister(NRF_CONFIG, 0x0E); // PRIM_RX LO & PWR_UP
        NRF_CE_hi;
        NRF_SendCommand(NRF_FLUSH_TX, 0xFF); // Flush TX

}
Beispiel #3
0
void
recv_setup()
{
    status = RECEIVER;
    //printf("enabling receiver");
    NRF_WriteRegister(NRF_STATUS, 0x7E); // reset status register
    NRF_SendCommand(NRF_FLUSH_RX, 0xFF);
    NRF_WriteRegister(NRF_CONFIG, 0x0F);
    NRF_CE_hi;
    NRF_Delay();
}
Beispiel #4
0
void
readPacket () {
	action = READING;
	NRF_WriteRegister(NRF_STATUS, 0x70);
        NRF_ReceivePayload(NRF_R_RX_PAYLOAD, NET_PACKET_SIZE, unReadData);
	printf("in readPacket: type: %d id: %d seq: %d time_to_live: %d\n",unReadData[0],unReadData[1],unReadData[2], unReadData[3]);
        int aux = process_for_routing (unReadData);
        NRF_SendCommand(NRF_FLUSH_RX, 0xFF);
	action = WAITING;
	if (aux == 0) {// we have a packet to forward
		if (unReadData[3] < 3) {
			unReadData[3]++;
			net_send_packet(unReadData);	
		}
	} else {
		if (unReadData[2] > last_seq) {
			dataToRead = 1;
			last_seq = unReadData[2];
		}
	}
}
Beispiel #5
0
void
net_init()
{
    uint8_t addr_array[5] = {0xE7, 0xE7, 0xE7, 0xE7, 0xE7};

    RXEN_hi; // enable amp

    NRF_CE_lo;
    NRF_WriteRegister(NRF_CONFIG, 0x3C); // Enable CRC and disable TX interrupts
    NRF_WriteRegister(NRF_EN_AA, 0x0); // Disable auto ACK
    NRF_WriteRegister(NRF_EN_RXADDR, 0x3F); // Receive Pipe 0 enabled
    NRF_WriteRegister(NRF_SETUP_RETR, 0); // Retransmits
    NRF_WriteRegister(NRF_SETUP_AW, 0x03); // Address Width  (5 bytes)
    NRF_WriteRegister(NRF_RF_SETUP, bandwidth | power); // set up
    NRF_WriteRegister(NRF_RF_CH, channel); // RF Channel
    NRF_WriteRegister(NRF_RX_PW_P0, 16); // RX Payload Width
    NRF_WriteRegister(NRF_FEATURE, 0x01);

    NRF_WriteRegisterMulti(NRF_TX_ADDR, 5, addr_array);
    NRF_WriteRegisterMulti(NRF_RX_ADDR_P0, 5, addr_array);
    NRF_WriteRegister(NRF_STATUS, 0x7E); // Clear Interrupts
    NRF_SendCommand(NRF_FLUSH_TX, 0xFF);
    NRF_WriteRegister(NRF_CONFIG, 0x0E);

    recv_setup();

    NRF_WriteRegister(NRF_STATUS, 0x70); // clear radio interrupts

    uint8_t status = NRF_ReadRegister(NRF_STATUS);

    if (status == 0x0E)
    {
    	printf("Radio is ready\n");
    }
    else
    {
        printf("Radio failed to initialize\n");
    }
}
void NRF_SetupTX(void)
{
  uint8_t addr_array[5];
  NRF_CE_lo;
  NRF_WriteRegister(NRF_CONFIG, 0x0C);
  //NRF_WriteRegister(NRF_EN_AA, 0x3F); // AutoAcknowledge
  NRF_WriteRegister(NRF_EN_AA, 0x3F);
  NRF_WriteRegister(NRF_EN_RXADDR, 0x3F); // Receive Pipe 0 enabled
  NRF_WriteRegister(NRF_SETUP_RETR, 15); // Retransmits
  NRF_WriteRegister(NRF_SETUP_AW, 0x03); // Address Width  (5 bytes)
  NRF_WriteRegister(NRF_RF_SETUP, 0x0F); // RF Setup
  //NRF_WriteRegister(NRF_RF_SETUP, 0x08);  // -28dB
  NRF_WriteRegister(NRF_RF_CH, NODE_CH); // RF Channel
  NRF_WriteRegister(NRF_RX_PW_P0, 32); // RX Payload Width
  NRF_WriteRegister(NRF_FEATURE, 0x01);

#if NODE_ID == 1
  addr_array[0] = 0xE7;
  addr_array[1] = 0xE7;
  addr_array[2] = 0xE7;
  addr_array[3] = 0xE7;
  addr_array[4] = 0xE7;
#else
  addr_array[0] = 0xC0 + NODE_ID;
  addr_array[1] = 0xC2;
  addr_array[2] = 0xC2;
  addr_array[3] = 0xC2;
  addr_array[4] = 0xC2;
#endif

  NRF_WriteRegisterMulti(NRF_TX_ADDR, 5, addr_array);
  NRF_WriteRegisterMulti(NRF_RX_ADDR_P0, 5, addr_array);
  //NRF_WriteRegister(NRF_RX_ADDR_P1, 2);
  NRF_WriteRegister(NRF_STATUS, 0x7E); // Clear Interrupts
  //NRF_WriteRegister(NRF_CONFIG, 0x0E); // Power Up, Transmitter
  NRF_SendCommand(NRF_FLUSH_TX, 0xFF);
  NRF_WriteRegister(NRF_CONFIG, 0x0E);
}
void NRF_WriteRegister(uint8_t reg, uint8_t data)
{
  NRF_SendCommand((reg | NRF_W_REGISTER), data);
}