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

Radio Transmitter/Receiver example

Your served radio tramsmitter/receiver example using PCA 10000 USB dongle, PCA 10001 evaluation kit. It's just only one byte data communication. It works well. If I communication multi-byte data with one packet, what did I fixed source code in "main.c" , "Radio_config.c"?

  • Hi.

    If you want a very quick fix without changing to much, set "PACKET_STATIC_LENGTH" in radio_config.h to your desired number of bytes on air.

    Here's some more information, and how to configure your length manually:

    When the length field is used (LFLEN > 0) you can set the content of the length field through the first byte of the packet buffer. The payload itself will start on the second byte. If S0LEN > 0 or S1LEN > 0 you will have to set these fields through the packet buffer as well, each field (S0, Length or S1) will occupy one byte of the packet buffer when enabled.

    The S0 and S1 fields are only there to allow status or padding bits before or after the length field, and they are completely optional if you are defining your own protocol.

    Below is a small example to show you how the length field can be used:

    uint8_t packet_buf[33];
    NRF_RADIO->PACKETPTR = packet_buf;
    NRF_RADIO->PCNF0 = 8 << RADIO_PCNF0_LFLEN_Pos;
    NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) |                                   (RADIO_PCNF1_ENDIAN_Big       << RADIO_PCNF1_ENDIAN_Pos)  |                                   
    (3   << RADIO_PCNF1_BALEN_Pos)   |                     
                                      (0   << RADIO_PCNF1_STATLEN_Pos) |                     
                                      (32 << RADIO_PCNF1_MAXLEN_Pos);
     
    // Send a 20 byte payload
    packet_buf[0] = 20;
    packet_buf[1] = USERDATA[0];
    packet_buf[2] = USERDATA[1];
    .
    .
    packet_buf[20] = USERDATA[19];
    

    Best regards Håkon

  • To clean things up, I'd be happy if you could evaluate the answer you have received and accept it if you feel it's sufficient. If not, it might be useful to expand your question a little and provide further information.

  • sir,

    i am using Radio Transmitter example .i am able to send data successfully.but i observed current as 9.7mA constantly.

    please help me to reduce power consumption.

    here is  SDK: examples/Radio/transmitter 

    PCA  10040e NRF52810

    void radio_config()
    {
      // Radio config
        NRF_RADIO->TXPOWER   = (RADIO_TXPOWER_TXPOWER_0dBm << RADIO_TXPOWER_TXPOWER_Pos);
        NRF_RADIO->FREQUENCY = 40UL;  
        NRF_RADIO->MODE      = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
        
           update_radio_addresses(NRF_ESB_ADDR_UPDATE_MASK_BASE0);
           update_radio_addresses(NRF_ESB_ADDR_UPDATE_MASK_BASE1);
           update_radio_addresses(NRF_ESB_ADDR_UPDATE_MASK_PREFIX);
        
        NRF_RADIO->TXADDRESS   = 0x00UL;  // Set device address 0 to use when transmitting
        NRF_RADIO->RXADDRESSES = 0x01UL;  // Enable device address 0 to use to select which addresses to receive
    
        NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) |
                           (0 << RADIO_PCNF0_LFLEN_Pos) |
                           (1 << RADIO_PCNF0_S1LEN_Pos) ;
    
    NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled    << RADIO_PCNF1_WHITEEN_Pos) |
                           (RADIO_PCNF1_ENDIAN_Big          << RADIO_PCNF1_ENDIAN_Pos)  |
                           ((m_esb_addr.addr_length - 1)    << RADIO_PCNF1_BALEN_Pos)   |
                           (10             << RADIO_PCNF1_STATLEN_Pos) |
                           (32             << RADIO_PCNF1_MAXLEN_Pos);
    
    NRF_RADIO->SHORTS   = RADIO_SHORTS_READY_START_Msk  | RADIO_SHORTS_END_DISABLE_Msk | \
                          RADIO_SHORTS_DISABLED_TXEN_Msk;
    NRF_RADIO->INTENSET = RADIO_INTENSET_DISABLED_Msk | RADIO_INTENSET_READY_Msk;
    }
    
    
    void send_packet()
    {
        NRF_RADIO->PACKETPTR = (uint32_t)&packet;
        NRF_RADIO->EVENTS_READY = 0U;
        NRF_RADIO->TASKS_TXEN   = 1;
    
        while (NRF_RADIO->EVENTS_READY == 0U)
        {
            // wait
        }
        NRF_RADIO->EVENTS_END  = 0U;
        NRF_RADIO->TASKS_START = 1U;
    
        while (NRF_RADIO->EVENTS_END == 0U)
        {
            // wait
        }
    
        NRF_RADIO->EVENTS_DISABLED = 0U;
        // Disable radio
        NRF_RADIO->TASKS_DISABLE = 1U;
    
        while (NRF_RADIO->EVENTS_DISABLED == 0U)
        {
            // wait
        }
          
    }
    
    

Related