Пример #1
0
static uint8_t CheckTx(void) {
  RPHY_PacketDesc packet;
  uint8_t res = ERR_OK;
  uint8_t TxDataBuffer[RPHY_BUFFER_SIZE];
  
  if (RMSG_GetTxMsg(TxDataBuffer, sizeof(TxDataBuffer))==ERR_OK) {
    RF1_StopRxTx();  /* CE low */
    TX_POWERUP();
    /* set up packet structure */
    packet.phyData = &TxDataBuffer[0];
    packet.flags = RPHY_BUF_FLAGS(packet.phyData);
    packet.phySize = sizeof(TxDataBuffer);
#if NRF24_DYNAMIC_PAYLOAD
    packet.rxtx = RPHY_BUF_PAYLOAD_START(packet.phyData);
#else
    packet.rxtx = &RPHY_BUF_SIZE(packet.phyData); /* we transmit the data size too */
#endif
    if (RADIO_isSniffing) {
      RPHY_SniffPacket(&packet, TRUE); /* sniff outgoing packet */
    }
#if NRF24_DYNAMIC_PAYLOAD
    RF1_TxPayload(packet.rxtx, RPHY_BUF_SIZE(packet.phyData)); /* send data, using dynamic payload size */
#else
    RF1_TxPayload(packet.rxtx, RPHY_PAYLOAD_SIZE); /* send data, using fixed payload size */
#endif
    return ERR_OK;
  } else {
    return ERR_NOTAVAIL; /* no data to send? */
  }
  return res;
}
Пример #2
0
void APP_Run(void) {
  static const uint8_t chRf[] = {2, 26,80};
  static const uint8_t chLe[] = {37,38,39};
  uint8_t i, L, ch = 0;
  uint8_t buf[32];

  nrf_cmd(0x20, 0x12);  //on, no crc, int on RX/TX done
  nrf_cmd(0x21, 0x00);  //no auto-acknowledge
  nrf_cmd(0x22, 0x00);  //no RX
  nrf_cmd(0x23, 0x02);  //5-byte address
  nrf_cmd(0x24, 0x00);  //no auto-retransmit
  nrf_cmd(0x26, 0x06);  //1MBps at 0dBm
  nrf_cmd(0x27, 0x3E);  //clear various flags
  nrf_cmd(0x3C, 0x00);  //no dynamic payloads
  nrf_cmd(0x3D, 0x00);  //no features
  nrf_cmd(0x31, 32);  //always RX 32 bytes
  nrf_cmd(0x22, 0x01);  //RX on pipe 0

  buf[0] = 0x30;      //set addresses
  buf[1] = swapbits(0x8E);
  buf[2] = swapbits(0x89);
  buf[3] = swapbits(0xBE);
  buf[4] = swapbits(0xD6);
#if 0
  nrf_manybytes(buf, 5);
#else
  RF1_WriteRegisterData(RF1_TX_ADDR, &buf[1], 4);
#endif
  buf[0] = 0x2A;
#if 0
  nrf_manybytes(buf, 5);
#else
  RF1_WriteRegisterData(RF1_RX_ADDR_P0, &buf[1], 4);
#endif

  while(1) {
      L = 0;
      buf[L++] = 0x40;  //PDU type, given address is random
      buf[L++] = 11;  //17 bytes of payload

      buf[L++] = MY_MAC_0;
      buf[L++] = MY_MAC_1;
      buf[L++] = MY_MAC_2;
      buf[L++] = MY_MAC_3;
      buf[L++] = MY_MAC_4;
      buf[L++] = MY_MAC_5;

      buf[L++] = 2;   //flags (LE-only, limited discovery mode)
      buf[L++] = 0x01;
      buf[L++] = 0x05;

      buf[L++] = 7;
      buf[L++] = 0x08;
      buf[L++] = 'n';
      buf[L++] = 'R';
      buf[L++] = 'F';
      buf[L++] = ' ';
      buf[L++] = 'L';
      buf[L++] = 'E';

      buf[L++] = 0x55;  //CRC start value: 0x555555
      buf[L++] = 0x55;
      buf[L++] = 0x55;

      if(++ch == sizeof(chRf)) { /* channel hopping */
        ch = 0;
      }

      //nrf_cmd(0x25, chRf[ch]);
      (void)RF1_SetChannel(chRf[ch]);

      //nrf_cmd(0x27, 0x6E);  //clear flags
      RF1_WriteRegister(RF1_STATUS, RF1_STATUS_RX_DR|RF1_STATUS_TX_DS|RF1_STATUS_RX_P_NO_RX_FIFO_EMPTY); /* clear flags */

      btLePacketEncode(buf, L, chLe[ch]);

      //nrf_simplebyte(0xE2); //Clear RX Fifo
      RF1_Write(RF1_FLUSH_RX); /* flush old data */

      //nrf_simplebyte(0xE1); //Clear TX Fifo
      //RF1_Write(RF1_FLUSH_TX); /* flush old data */ /* done in RF1_TxPayload() */


      RF1_TxPayload(buf, L);
#if 0
      cbi(PORTB, PIN_nCS);
      spi_byte(0xA0);
      for(i = 0 ; i < L ; i++) {
        spi_byte(buf[i]);
      }
      sbi(PORTB, PIN_nCS);
      nrf_cmd(0x20, 0x12);  //tx on
      sbi(PORTB, PIN_CE);  //do tx
      delay_ms(10);
      cbi(PORTB, PIN_CE); (in preparation of switching to RX quickly);
#endif
      LED1_Neg();
      WAIT1_Waitms(10);
  } /* for */
}