I am trying to drive a nrf24l01+ with a ESP32 so that I can connect a bunch of coin cell nrf24 nodes to the web.
I have done some research but I have found very few things about using the nrf24 with the ESP32.
To have tmrh20's RF24 library compile, I made to following change to the library:
in nRFL01.h in commented out this line:
//#define NOP 0xFF
in RF24.cpp I replaced
*buf++ = _SPI.transfer(NOP);
by
*buf++ = _SPI.transfer(0xff);
in RF24_config.h
I added
#elif defined (ESP_H)
#include <pgmspace.h>
#define PRIPSTR "%s"
just after line 135
Those changes allow the library to compile with no warnings.
I used the lastest ESP32 arduino core downloaded from the github repo as well as the latest version of the RF24 library from github.
I am trying to run the getting started sketch from the library with a few modif:
/*
* Getting Started example sketch for nRF24L01+ radios
* This is a very basic example of how to send data from one node to another
* Updated: Dec 2014 by TMRh20
*/
#include <SPI.h>
#include "RF24.h"
/****************** User Config ***************************/
/*** Set this radio as radio number 0 or 1 ***/
bool radioNumber = 0;
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(5,18); //CE, CSN
/**********************************************************/
byte addresses[][6] = {"1Node","2Node"};
// Used to control whether this node is sending or receiving
bool role = 0;
void setup() {
Serial.begin(115200);
Serial.println(F("RF24/examples/GettingStarted"));
Serial.println(F("*** PRESS 'T' to begin transmitting to the 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 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);
// Open a writing and reading pipe on each radio, with opposite addresses
if(radioNumber){
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[0]);
}else{
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
}
// Start the radio listening for data
radio.startListening();
}
void loop(){}
I have tried playing with different SPI parameters with no success. I lowered the frequency to 2Mbs and try to set the SPI in mode 0, MSBFIRST with no success.
On the hardware side I use:
- DOIT ESP32 DEVKIT v1
- a nrf24 adapter (the one with the power regulator and cap)
- a basic module
I tried swapping the cable, module, adapter with no success.
I power the dev board through USB and with an external beefy regulated power supply. I have a large cap (470uF) between (GND and 3.3V).
The connection are as follow:
CE->GPIO18
CSN -> GPIO05
MISO -> GPIO12
MOSI -> GPIO13
CLK-> GPIO14
IRQ-> unconnected
My guess is there is a problem with the SPI communication protocol. The radio.begin() always fails....
I am running out of idea and I am fairly new with ESP32 (although I have some experience using nRF24 with atmega), Any help would be greatly appreciated!