This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unable to get the radio to receive. Not sure if Receive or transmit is wrong.

I have two NRF52832 boards. I cannot get the SDK to compile so I'm going at it barebones style.

Transmitter Board code:

volatile uint8_t packet[56];

void init_radio(void)
{

  NRF_CLOCK->TASKS_HFCLKSTART = 1; /* Start the HFCLK from crystal oscillator. */
  while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
  NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
  
  NRF_RADIO->POWER = 1; /* Turn the radio on */
  
  NRF_RADIO->MODE = RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos; 
  
  NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_LFLEN_Pos) | /* No S0, S1, or Length fields. 16-bit preamble */
                     (0 << RADIO_PCNF0_S0LEN_Pos) |
                     (0 << RADIO_PCNF0_S1LEN_Pos) | 
                     (RADIO_PCNF0_S1INCL_Automatic << RADIO_PCNF0_S1INCL_Pos) |
                     (RADIO_PCNF0_PLEN_16bit << RADIO_PCNF0_PLEN_Pos); 
  NRF_RADIO->PCNF1 =  (56 << RADIO_PCNF1_MAXLEN_Pos) | /* Packet Length */
                      (56 << RADIO_PCNF1_STATLEN_Pos) | /* Static Length Parameter in number of Bytes */
                      (2  << RADIO_PCNF1_BALEN_Pos) | /* Base Address Length in number of Bytes */
                      (RADIO_PCNF1_ENDIAN_Little << RADIO_PCNF1_ENDIAN_Pos) | /* Little Endian */
                      (RADIO_PCNF1_WHITEEN_Enabled << RADIO_PCNF1_WHITEEN_Pos); /* Enable Packet whitening? */

  NRF_RADIO->DATAWHITEIV = 0x55; /* Init whitening value*/

  NRF_RADIO->BASE0   = 0x0000BABE; /* Configure Base0 */
  NRF_RADIO->PREFIX0 = 0x41 << RADIO_PREFIX0_AP0_Pos; /* Configure Address prefix */

  NRF_RADIO->TXADDRESS = 0 << RADIO_TXADDRESS_TXADDRESS_Pos; /* Use logical  address 0 (BASE0 + PREFIX byte 0)*/

  NRF_RADIO->CRCCNF = (RADIO_CRCCNF_LEN_Two << RADIO_CRCCNF_LEN_Pos) | /* Initialize CRC (two bytes) */
                      (RADIO_CRCCNF_SKIPADDR_Skip << RADIO_CRCCNF_SKIPADDR_Pos);
  NRF_RADIO->CRCPOLY = 0x0000AAAA;
  NRF_RADIO->CRCINIT = 0x12345678;

  NRF_RADIO->MODECNF0 = (RADIO_MODECNF0_DTX_B0 << RADIO_MODECNF0_DTX_Pos) | /* Enable fast rampup, new in nRF52 */
                        (RADIO_MODECNF0_RU_Fast << RADIO_MODECNF0_RU_Pos);
                        
  NRF_RADIO->TXPOWER = RADIO_TXPOWER_TXPOWER_0dBm << RADIO_TXPOWER_TXPOWER_Pos; /* 4dBm output power, sending packets at 2400MHz */
  NRF_RADIO->FREQUENCY = 0 << RADIO_FREQUENCY_FREQUENCY_Pos;
  
  NRF_RADIO->PACKETPTR = (uint32_t)&packet[0]; /* Configure address of the packet and logic address to use */
  
  NRF_RADIO->SHORTS = (RADIO_SHORTS_READY_START_Enabled << RADIO_SHORTS_READY_START_Pos) | /* Configure shortcuts to start as soon as READY event is received, and disable radio as soon as packet is sent. */
                      (RADIO_SHORTS_END_DISABLE_Enabled << RADIO_SHORTS_END_DISABLE_Pos);

}

void transmit_radio(void)
{
  NRF_RADIO->PACKETPTR = (uint32_t)&packet[0]; /* Configure address of the packet and logic address to use */
  NRF_RADIO->TASKS_TXEN = 1;
  while(NRF_RADIO->EVENTS_DISABLED == 0);
  NRF_RADIO->EVENTS_DISABLED = 0;
}

int main(void)
{
    init_radio();
    
    while(1)
    {
        /* Code to fill packet */
        transmit_radio();
        /* Code to zero packet before next fill */

Receiver Board code:

volatile uint8_t packet[56];

void init_radio(void)
{
  NRF_CLOCK->TASKS_HFCLKSTART = 1;  
  while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
  NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
  
  NRF_RADIO->POWER = 1; /* Turn the radio on */
  NRF_RADIO->MODE = RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos; 
  NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_LFLEN_Pos) | /* no S0, S1 or length fields. 8-bit preamble. */
                     (0 << RADIO_PCNF0_S0LEN_Pos) |
                     (0 << RADIO_PCNF0_S1LEN_Pos) | 
                     (RADIO_PCNF0_S1INCL_Automatic << RADIO_PCNF0_S1INCL_Pos) |
                     (RADIO_PCNF0_PLEN_16bit << RADIO_PCNF0_PLEN_Pos); 
  NRF_RADIO->PCNF1 =  (56 << RADIO_PCNF0_LFLEN_Pos) | /* Packet Length */
                      (56 << RADIO_PCNF1_STATLEN_Pos) | /* Static Length Parameter in number of Bytes */
                      (2  << RADIO_PCNF1_BALEN_Pos) | /* Base Address Length in number of Bytes */
                      (RADIO_PCNF1_ENDIAN_Little << RADIO_PCNF1_ENDIAN_Pos) | /* Little Endian */
                      (RADIO_PCNF1_WHITEEN_Enabled << RADIO_PCNF1_WHITEEN_Pos); /* Enable Packet whitening? */
  NRF_RADIO->DATAWHITEIV = 0x55; /* Init whitening value */

  NRF_RADIO->BASE0 = 0x0000BABE; /* Configure BASE0 */
  NRF_RADIO->PREFIX0 = 0x41 << RADIO_PREFIX0_AP0_Pos; /* Configure Prefix0 */

  NRF_RADIO->RXADDRESSES = RADIO_RXADDRESSES_ADDR0_Enabled << RADIO_RXADDRESSES_ADDR0_Pos; /* Use Logical Address (BASE0 + PREFIX0 byte 0)*/
  
  NRF_RADIO->CRCCNF = (RADIO_CRCCNF_LEN_Two << RADIO_CRCCNF_LEN_Pos) | /* Initialize CRC (two bytes) */
                      (RADIO_CRCCNF_SKIPADDR_Skip << RADIO_CRCCNF_SKIPADDR_Pos);
  NRF_RADIO->CRCPOLY = 0x0000AAAA;
  NRF_RADIO->CRCINIT = 0x12345678;

  NRF_RADIO->MODECNF0 = (RADIO_MODECNF0_DTX_B0 << RADIO_MODECNF0_DTX_Pos) | /* Enable Fast Ramp Up */
                        (RADIO_MODECNF0_RU_Fast << RADIO_MODECNF0_RU_Pos);

  NRF_RADIO->DACNF = RADIO_DACNF_TXADD0_Msk | RADIO_DACNF_ENA0_Enabled;

  NRF_RADIO->FREQUENCY = 0 << RADIO_FREQUENCY_FREQUENCY_Pos; /* receiving/sending packets at 2400MHz */

  NRF_RADIO->PACKETPTR = (uint32_t)&packet[0]; /* Configure address of the packet and logic address to use */

  NRF_RADIO->SHORTS = (RADIO_SHORTS_READY_START_Enabled << RADIO_SHORTS_READY_START_Pos) | /* Configure shortcuts to start as soon as READY event is received, and disable radio as soon as packet is received. */
                      (RADIO_SHORTS_END_DISABLE_Enabled << RADIO_SHORTS_END_DISABLE_Pos);

}

void radio_receive(void)
{
  NRF_RADIO->PACKETPTR = (uint32_t)&packet[0]; /* Configure address of the packet and logic address to use */
  NRF_RADIO->TASKS_RXEN = 1;
  while(NRF_RADIO->EVENTS_DISABLED == 0);
  NRF_RADIO->EVENTS_DISABLED = 0;  
}

int main(void)
{
  
  init_radio();
  
  while(1)
  {
    radio_receive();
    if(NRF_RADIO->EVENTS_CRCOK == 1)
    {
      
      NRF_RADIO->EVENTS_CRCOK = 0;
      /* code to empty packet fr use */
    }
  }
}

The receiver board never gets into the portion of code that operates on the received packet. e.g. NRF_RADIO->EVENTS_CRCOK never = 1.

I am not sure if it's the receiver or the transmitter. Any help is appreciated.

Thanks for your time.

Parents Reply Children
No Data
Related