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.

  • Hello sir,

    Print details for the following Receiver Code :

        #include <SPI.h>
        #include "printf.h"
    
        #include <nRF24L01.h>
        #include <RF24.h>
    #define CE 18
    #define CSN 19
    RF24 radio(CE, CSN);
    unsigned char values;
    const byte rxAddr[5] = {0xC0,0x01,0x23,0x45,0x67};
    
    void setup()
    {
      Serial.begin(9600);
      printf_begin();
      radio.begin();
      radio.setPALevel(RF24_PA_MAX);
      radio.setDataRate(RF24_1MBPS);
      radio.setChannel(7);
      radio.openReadingPipe(0, rxAddr);
      radio.startListening();
    }
    
    void loop()
    {
      if (radio.available())
      {
        char text;
        radio.read(&text, 1);
        Serial.print("####### Data Received :");
        Serial.print(text);
        Serial.println(" #######");
        radio.printDetails() ;
      }
    }
    

    Receiver Prints:

    ####### Data Received :A #######
    STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
    RX_ADDR_P0-1	 = 0x67452301c0 0xc2c2c2c2c2
    RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6
    TX_ADDR		 = 0xe7e7e7e7e7
    RX_PW_P0-6	 = 0x01 0x00 0x00 0x00 0x00 0x00
    EN_AA		 = 0x3f
    EN_RXADDR	 = 0x03
    RF_CH		 = 0x07
    RF_SETUP	 = 0x07
    CONFIG		 = 0x0f
    DYNPD/FEATURE	 = 0x00 0x00
    Data Rate	 = 1MBPS
    Model		 = nRF24L01+
    CRC Length	 = 16 bits
    PA Power	 = PA_MAX
    ####### Data Received :A #######
    STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
    RX_ADDR_P0-1	 = 0x67452301c0 0xc2c2c2c2c2
    RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6
    TX_ADDR		 = 0xe7e7e7e7e7
    RX_PW_P0-6	 = 0x01 0x00 0x00 0x00 0x00 0x00
    EN_AA		 = 0x3f
    EN_RXADDR	 = 0x03
    RF_CH		 = 0x07
    RF_SETUP	 = 0x07
    CONFIG		 = 0x0f
    DYNPD/FEATURE	 = 0x00 0x00
    Data Rate	 = 1MBPS
    Model		 = nRF24L01+
    CRC Length	 = 16 bits
    PA Power	 = PA_MAX
    

    Transmitter Code:

     #include <SPI.h>
        #include "printf.h"
    
        #include <nRF24L01.h>
        #include <RF24.h>
        #define CE 18
        #define CSN 19
        RF24 radio(CE, CSN);
        char values;
        const byte rxAddr[5] = {0xC0,0x01,0x23,0x45,0x67};
    
        void setup()
        {
          Serial.begin(9600);
          printf_begin();
          radio.begin();
          radio.setPALevel(RF24_PA_MAX);
          radio.setDataRate(RF24_1MBPS);
          radio.setChannel(7);
          radio.openWritingPipe(rxAddr);
          radio.stopListening();
    
        }
    
    void loop()
    {
      values = 'A';
             radio.write(&values,1);
             Serial.print("####### Data Transmitted :");
        Serial.print(values);
        Serial.println(" #######");
             radio.printDetails() ;
             delay(2000);
          }
    

    Transmitter Prints:

    ####### Data Transmitted :A #######
    STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
    RX_ADDR_P0-1	 = 0x67452301c0 0xc2c2c2c2c2
    RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6
    TX_ADDR		 = 0x67452301c0
    RX_PW_P0-6	 = 0x01 0x00 0x00 0x00 0x00 0x00
    EN_AA		 = 0x3f
    EN_RXADDR	 = 0x03
    RF_CH		 = 0x07
    RF_SETUP	 = 0x07
    CONFIG		 = 0x0e
    DYNPD/FEATURE	 = 0x00 0x00
    Data Rate	 = 1MBPS
    Model		 = nRF24L01+
    CRC Length	 = 16 bits
    PA Power	 = PA_MAX
    ####### Data Transmitted :A #######
    STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
    RX_ADDR_P0-1	 = 0x67452301c0 0xc2c2c2c2c2
    RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6
    TX_ADDR		 = 0x67452301c0
    RX_PW_P0-6	 = 0x01 0x00 0x00 0x00 0x00 0x00
    EN_AA		 = 0x3f
    EN_RXADDR	 = 0x03
    RF_CH		 = 0x07
    RF_SETUP	 = 0x07
    CONFIG		 = 0x0e
    DYNPD/FEATURE	 = 0x00 0x00
    Data Rate	 = 1MBPS
    Model		 = nRF24L01+
    CRC Length	 = 16 bits
    PA Power	 = PA_MAX
    

    Hope this will help, sir please help i am unable to communicate with nrf51 for along.

    Thanks and Regards Pallavi

  • This is working since you can see we have sent A and received A on receiver end.

  • Hi Pallavi

    I still don't understand why you couldn't get it to work with dynamic payload length enabled. I have been able to do that with both an nRF24L01+ and an nRF24L01 module, without any issues (the main difference is I used address 0xE7E7E7E7E7).

    That being said, I do see an issue when using the configuration you included above (dynamic payload length disabled). In this mode I see that the nRF51 receives the packet in the debugger, but for some reason the CRC fails and the packet is discarded.

    I will have to do some more research to figure out why the packet is discarded in this case, and I will get back to you when I know more.

    Best regards

  • hello sir, i have also tried with your configurations i.e address 0xe7e7e7 and enabling dynamic payload length, it works fine with both the arduino+nrf24l01. but will not work with nrf51822.the code i have used on nrf51822 side is esb_prx from the pro[pritary_rf folder:

    Transmitter code is,

    #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    #include "printf.h"  
    #define CE 18
    #define CSN 19
    RF24 radio(CE, CSN);
    
    
    int x=0;
    //const byte rxAddr[6] = "00001";
    const byte txAddr[5] = {0xE7,0xE7,0xE7,0xE7,0xE7};
    char values;
    void setup()
    {
      Serial.begin(9600);
        printf_begin();
    
      radio.begin();
     //radio.setPALevel(RF24_PA_MAX);
      radio.setDataRate(RF24_2MBPS);
     // radio.setChannel(7);
    //  radio.setRetries(15,15);
     radio.setCRCLength(RF24_CRC_16);
    //radio.enableAckPayload();
    radio.enableDynamicPayloads();
    radio.openWritingPipe(txAddr);
    radio.stopListening();
    }
    
    void loop()
    {
    values = 'A';
             radio.write(&values,1);
             Serial.print("####### Data Transmitted :");
        Serial.print(values);
        Serial.println(" #######");
             radio.printDetails() ;
             delay(2000);
    
    }
    
    transmitter print details are:
    
    
    .####### Data Transmitted :A #######
    .STATUS.. = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
    .RX_ADDR_P0-1. = 0xe7e7e7e7e7 0xc2c2c2c2c2
    .RX_ADDR_P2-5. = 0xc3 0xc4 0xc5 0xc6
    .TX_ADDR.. = 0xe7e7e7e7e7
    .RX_PW_P0-6. = 0x20 0x00 0x00 0x00 0x00 0x00
    .EN_AA.. = 0x3f
    .EN_RXADDR. = 0x03
    .RF_CH.. = 0x4c
    .RF_SETUP. = 0x0f
    .CONFIG.. = 0x0e
    .DYNPD/FEATURE. = 0x3f 0x04
    .Data Rate. = 2MBPS
    .Model.. = nRF24L01+
    .CRC Length. = 16 bits
    .PA Power. = PA_MAX
    
    
    the receiver code is,
    
    #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    #include "printf.h"  
    #define CE 18
    #define CSN 19
    RF24 radio(CE, CSN);
    
    
    int x=0;
    //const byte rxAddr[6] = "00001";
    const byte rxAddr[5] = {0xE7,0xE7,0xE7,0xE7,0xE7};
    char values;
    void setup()
    {
      Serial.begin(9600);
        printf_begin();
    
      radio.begin();
     //radio.setPALevel(RF24_PA_MAX);
      radio.setDataRate(RF24_2MBPS);
     // radio.setChannel(7);
    //  radio.setRetries(15,15);
     radio.setCRCLength(RF24_CRC_16);
    //radio.enableAckPayload();
    radio.enableDynamicPayloads();
     radio.openReadingPipe(0, rxAddr);
      radio.startListening();
    }
    
    void loop()
    {
     char text;
        radio.read(&text, 1);
        Serial.print("####### Data Received :");
        Serial.print(text);
        Serial.println(" #######");
        radio.printDetails() ;
    }
    
    print detauils of receiver are as
    
    ####### Data Received :A #######
    .STATUS.. = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
    .RX_ADDR_P0-1. = 0xe7e7e7e7e7 0xc2c2c2c2c2
    .RX_ADDR_P2-5. = 0xc3 0xc4 0xc5 0xc6
    .TX_ADDR.. = 0xe7e7e7e7e7
    .RX_PW_P0-6. = 0x20 0x00 0x00 0x00 0x00 0x00
    .EN_AA.. = 0x3f
    .EN_RXADDR. = 0x03
    .RF_CH.. = 0x4c
    .RF_SETUP. = 0x0f
    .CONFIG.. = 0x0f
    .DYNPD/FEATURE. = 0x3f 0x04
    .Data Rate. = 2MBPS
    .Model.. = nRF24L01+
    .CRC Length. = 16 bits
    .PA Power. = PA_MAX
    

    sir please go through this and match the settings now with your code and because i had changed my address anabled dynamic payload. after that it doesnt work.

    and the code i previously given that code i am trying to compatible it with code from the peripheral folder the code is radio.thats why you told that it is bit different but now i have posted both the codes go please refer these codes and tell me actually what is going wrong with nrf51822.both codes i.e radio and esb_prx for nrf51822 is not working.and if you had done this then can you share the code with me i.e code from arduino side and code from nrf51822 side. i dont have any issue with the specification .my intension is just that to make communication between nrf51822 and arduino+nrf24l01.

    waiting for your reply.

    Pallavi

  • 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

Related