This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

want nrf24l01 communication with nrf51822

hello,will you please tell me which code i have to use in the sdk 12.2.0 for rf communication with nrf51822 and nrf24l01 .and also tell me which settings i have to do for nrf24l01 side as a transmitter.so that i can receive data on nrf51822 side.

Parents
  • Hi Pallavi

    The ESB library in the nRF5 SDK v12.2.0 is designed to be backwards compatible with the nRF24L01/nRF24L01+, assuming you don't use the L01 device in legacy Shockburst mode (ACK's disabled).

    On the nRF5 side you can use the esb_ptx and esb_prx examples as a starting point: \nRF5_SDK_12.2.0\examples\proprietary_rf\

    For this to work you need the following settings on the nRF24L01 side:
    Default address (0xE7E7E7E7E7), with 5 byte address length
    16-bit CRC
    2Mbps bitrate
    Auto ACK and dynamic payload length enabled

    For all other settings you can use the default values.

    Edit: Added attachment.

    Best regards
    Torbjørn

  • Hi Pallavi

    I finally got my Arduino Uno board running, and hooked it up to an nRF24L01 module.
    For the longest time I couldn't get it to work, until I realized (by scoping the SPI lines) that the radio.write(..) function sends a 32 byte payload, regardless of what you set the length value to be. Apparently this is intended (the documentation mentions it), but it is a bit unusual.
    Once I corrected that I had no issues getting the Arduino + nRF24L01 to transmit to the nRF51822, by using a stripped down version of one of the radio examples.

    Arduino side:

    #include <SPI.h>
    #include "RF24.h"
    
    /* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
    RF24 radio(7,8);
    /**********************************************************/
    
    byte address[] = {0xE7,0xE7,0xE7,0xE7,0xE7,0};
    
    // Function that printf and related will use to print
    int serial_putchar(char c, FILE* f) {
       if (c == '\n') serial_putchar('\r', f);
       return Serial.write(c) == 1? 0 : 1;
    }
    
    FILE serial_stdout;
    
    void setup() {
      Serial.begin(115200);
    
           // Set up stdout
      fdev_setup_stream(&serial_stdout, serial_putchar, NULL, _FDEV_SETUP_WRITE);
      stdout = &serial_stdout;
      
      Serial.println(F("RF24/examples/GettingStarted"));
      Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));
      
      radio.begin();
    
      // Set the PA Level low to prevent power supply related issues since this is a
     // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
      radio.setPALevel(RF24_PA_LOW);
      
      radio.openWritingPipe(address);
      radio.openReadingPipe(0,address);
    
      radio.printDetails();
    }
    
    void loop() {
      Serial.println(F("Now sending"));
      
      unsigned long start_time = micros();                             // Take the time, and send it.  This will block until complete
      if (!radio.write( &start_time, sizeof(unsigned long))){
        Serial.println(F("failed"));
      }
      
      // Try again 1s later
      delay(1000);
    } // Loop
    

    nRF51822 ESB init:

    uint32_t esb_init( void )
    {
        uint32_t err_code;
        uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
        uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
        uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
        nrf_esb_config_t nrf_esb_config         = NRF_ESB_DEFAULT_CONFIG;
        nrf_esb_config.payload_length           = 32;
        nrf_esb_config.protocol                 = NRF_ESB_PROTOCOL_ESB;
        nrf_esb_config.bitrate                  = NRF_ESB_BITRATE_1MBPS;
        nrf_esb_config.crc                      = NRF_ESB_CRC_16BIT;
        nrf_esb_config.mode                     = NRF_ESB_MODE_PRX;
        nrf_esb_config.event_handler            = nrf_esb_event_handler;
        nrf_esb_config.selective_auto_ack       = false;
    
        err_code = nrf_esb_init(&nrf_esb_config);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_base_address_0(base_addr_0);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_base_address_1(base_addr_1);
        VERIFY_SUCCESS(err_code);
        
        err_code = nrf_esb_set_prefixes(addr_prefix, 8);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_rf_channel(76);
        VERIFY_SUCCESS(err_code);
        
        return err_code;
    }
    

    In other words, the critical aspect for me was to set the payload_length to 32 on the nRF51 side.

    Can you try those settings and see if it also works for you?

    Best regards

Reply
  • Hi Pallavi

    I finally got my Arduino Uno board running, and hooked it up to an nRF24L01 module.
    For the longest time I couldn't get it to work, until I realized (by scoping the SPI lines) that the radio.write(..) function sends a 32 byte payload, regardless of what you set the length value to be. Apparently this is intended (the documentation mentions it), but it is a bit unusual.
    Once I corrected that I had no issues getting the Arduino + nRF24L01 to transmit to the nRF51822, by using a stripped down version of one of the radio examples.

    Arduino side:

    #include <SPI.h>
    #include "RF24.h"
    
    /* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
    RF24 radio(7,8);
    /**********************************************************/
    
    byte address[] = {0xE7,0xE7,0xE7,0xE7,0xE7,0};
    
    // Function that printf and related will use to print
    int serial_putchar(char c, FILE* f) {
       if (c == '\n') serial_putchar('\r', f);
       return Serial.write(c) == 1? 0 : 1;
    }
    
    FILE serial_stdout;
    
    void setup() {
      Serial.begin(115200);
    
           // Set up stdout
      fdev_setup_stream(&serial_stdout, serial_putchar, NULL, _FDEV_SETUP_WRITE);
      stdout = &serial_stdout;
      
      Serial.println(F("RF24/examples/GettingStarted"));
      Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));
      
      radio.begin();
    
      // Set the PA Level low to prevent power supply related issues since this is a
     // getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
      radio.setPALevel(RF24_PA_LOW);
      
      radio.openWritingPipe(address);
      radio.openReadingPipe(0,address);
    
      radio.printDetails();
    }
    
    void loop() {
      Serial.println(F("Now sending"));
      
      unsigned long start_time = micros();                             // Take the time, and send it.  This will block until complete
      if (!radio.write( &start_time, sizeof(unsigned long))){
        Serial.println(F("failed"));
      }
      
      // Try again 1s later
      delay(1000);
    } // Loop
    

    nRF51822 ESB init:

    uint32_t esb_init( void )
    {
        uint32_t err_code;
        uint8_t base_addr_0[4] = {0xE7, 0xE7, 0xE7, 0xE7};
        uint8_t base_addr_1[4] = {0xC2, 0xC2, 0xC2, 0xC2};
        uint8_t addr_prefix[8] = {0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 };
        nrf_esb_config_t nrf_esb_config         = NRF_ESB_DEFAULT_CONFIG;
        nrf_esb_config.payload_length           = 32;
        nrf_esb_config.protocol                 = NRF_ESB_PROTOCOL_ESB;
        nrf_esb_config.bitrate                  = NRF_ESB_BITRATE_1MBPS;
        nrf_esb_config.crc                      = NRF_ESB_CRC_16BIT;
        nrf_esb_config.mode                     = NRF_ESB_MODE_PRX;
        nrf_esb_config.event_handler            = nrf_esb_event_handler;
        nrf_esb_config.selective_auto_ack       = false;
    
        err_code = nrf_esb_init(&nrf_esb_config);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_base_address_0(base_addr_0);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_base_address_1(base_addr_1);
        VERIFY_SUCCESS(err_code);
        
        err_code = nrf_esb_set_prefixes(addr_prefix, 8);
        VERIFY_SUCCESS(err_code);
    
        err_code = nrf_esb_set_rf_channel(76);
        VERIFY_SUCCESS(err_code);
        
        return err_code;
    }
    

    In other words, the critical aspect for me was to set the payload_length to 32 on the nRF51 side.

    Can you try those settings and see if it also works for you?

    Best regards

Children
No Data
Related