need help porting TMRh20's RF24 library to ESP32


i trying drive nrf24l01+ esp32 can connect bunch of coin cell nrf24 nodes web.

i have done research have found few things using nrf24 esp32.

to have tmrh20's rf24 library compile, made following change library:

in nrfl01.h in commented out line:
code: [select]
//#define nop           0xff   
in rf24.cpp replaced
   
code: [select]
*buf++ = _spi.transfer(nop);
by
   
code: [select]
*buf++ = _spi.transfer(0xff);

in rf24_config.h

i added

   
code: [select]

    #elif defined (esp_h)
    #include <pgmspace.h>
    #define pripstr "%s"

just after line 135

those changes allow library compile no warnings.

i used lastest esp32 arduino core downloaded github repo latest version of rf24 library github.

i trying run getting started sketch library few modif:

   
code: [select]
/*
* getting started example sketch nrf24l01+ radios
* basic example of how send data 1 node another
* updated: dec 2014 tmrh20
*/

#include <spi.h>
#include "rf24.h"

/****************** user config ***************************/
/***      set radio radio number 0 or 1         ***/
bool radionumber = 0;

/* hardware configuration: set nrf24l01 radio on spi bus plus pins 7 & 8 */
rf24 radio(5,18); //ce, csn
/**********************************************************/

byte addresses[][6] = {"1node","2node"};

// used control whether node sending or receiving
bool role = 0;

void setup() {
  serial.begin(115200);
  serial.println(f("rf24/examples/gettingstarted"));
  serial.println(f("*** press 't' begin transmitting other node"));
  spi.begin();
  spi.setfrequency(2000000);
  spi.setbitorder(msbfirst);
  spi.setdatamode(0);
  if (radio.begin()) { serial.println("ok!"); }
  else{ serial.println("too bad!"); }
  delay(5000);
  // set pa level low prevent power supply related issues since a
// getting_started sketch, , likelihood of close proximity of devices. rf24_pa_max default.
  radio.setpalevel(rf24_pa_low);
 
  // open writing , reading pipe on each radio, opposite addresses
  if(radionumber){
radio.openwritingpipe(addresses[1]);
radio.openreadingpipe(1,addresses[0]);
  }else{
radio.openwritingpipe(addresses[0]);
radio.openreadingpipe(1,addresses[1]);
  }
 
  // start radio listening data
  radio.startlistening();
}
                void loop(){}
   

i have tried playing different spi parameters no success. lowered frequency 2mbs , try set spi in mode 0, msbfirst no success.


on hardware side use:
- doit esp32 devkit v1
- nrf24 adapter (the 1 power regulator , cap)
- basic module

i tried swapping cable, module, adapter no success.

i power dev board through usb , external beefy regulated power supply. have large cap (470uf) between (gnd , 3.3v).


the connection follow:
 ce->gpio18
csn -> gpio05
miso -> gpio12
mosi -> gpio13
clk-> gpio14
irq-> unconnected


my guess there problem spi communication protocol. radio.begin() fails....

 i running out of idea , new esp32 (although have experience using nrf24 atmega), appreciated!

code: [select]

    #elif defined (esp_h)

i'm sure works think intent of code more obvious , maybe less fragile if used esp32 macro instead of include guard macro. consider former more of public api , latter not guaranteed stable.


Arduino Forum > Using Arduino > Microcontrollers > need help porting TMRh20's RF24 library to ESP32


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???