Ethernet works great, but unfortunately the default VSPI module is no longer exposed for me to use with the nRF24.
So I have two questions;
How do I properly specify a (non default) SPI I want to use to the RF24 library? Is there a RF24 library constructor?
The MOSI pin 13 (from the HSPI module) is also unavailable, so how do I properly specify alternative pins for SPI?
My program is long, but I copied the relevant parts of my proposed solution. I am waiting for Hardware to arrive, so I am trying to get a head of the debugging. I imagine someone will look at this and know right away where I am wrong or missing something. Any help/guidance is appreciated!
#include <SPI.h>
#include "RF24.h"
/* SPI MOSI MISO SCLK CS
* VSPI GPIO 23 GPIO 19 GPIO 18 GPIO 5
* HSPI GPIO 13 GPIO 12 GPIO 14 GPIO 15*/
// Define ALTERNATE_PINS to use non-standard GPIO pins for SPI bus
#define VSPI_MISO 12
#define VSPI_MOSI 16 // instead of 13
#define VSPI_SCLK 14
#define VSPI_SS 15
void setup(void) {
//alternatively route through GPIO pins of your choice
SPI.begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, SS
nRF24_setup(); //all the necessary nRF stuff...
// initialize the transceiver on the SPI bus
// Will this grab to the SPI.begin from above?
// Do I need to pass a parameter to radio.begin()?
// Is there somewhere else to specify which SPI module I intent to use?
while (!radio.begin());
…
} //setup
It might be that one may have to use the ESP32's SPI API to communicate with the device. I write that because I do not know how well the Arduino ESP32's core will utilize the ESP32's pin matrix reprograming.
Thanks for your reply. I looked at the ESP32 article. I also found this: "...SPI.begin(14, 12, 13, 15); before radio.begin(); ... "
This seems to be the approach I took. It looks like adding the pin numbers to the SPI.begin constructor will change the pins on the default SPI (VSPI) device?
There are two overloads of the begin() function that take pointers to a 'SPIClass' object. See RF24.h:
/**
* Same as begin(), but allows specifying a non-default SPI bus to use.
*
* @note This function assumes the `SPI::begin()` method was called before to
* calling this function.
*
* @warning This function is for the Arduino platforms only
*
* @param spiBus A pointer or reference to an instantiated SPI bus object.
* The `_SPI` datatype is a "wrapped" definition that will represent
* various SPI implementations based on the specified platform.
* @see Review the [Arduino support page](md_docs_arduino.html).
*
* @return same result as begin()
*/
bool begin(_SPI* spiBus);
/**
* Same as begin(), but allows dynamically specifying a SPI bus, CE pin,
* and CSN pin to use.
*
* @note This function assumes the `SPI::begin()` method was called before to
* calling this function.
*
* @warning This function is for the Arduino platforms only
*
* @param spiBus A pointer or reference to an instantiated SPI bus object.
* The `_SPI` datatype is a "wrapped" definition that will represent
* various SPI implementations based on the specified platform.
* @param _cepin The pin attached to Chip Enable on the RF module
* @param _cspin The pin attached to Chip Select (often labeled CSN) on the radio module.
* - For the Arduino Due board, the [Arduino Due extended SPI feature](https://www.arduino.cc/en/Reference/DueExtendedSPI)
* is not supported. This means that the Due's pins 4, 10, or 52 are not mandated options (can use any digital output pin) for the radio's CSN pin.
*
* @see Review the [Arduino support page](md_docs_arduino.html).
*
* @return same result as begin()
*/
bool begin(_SPI* spiBus, uint16_t _cepin, uint16_t _cspin);
Thanks! I saw something along these lines, but wasn't sure if I was understanding it correctly. So it looks like I could do something like the following code below?
I got info about SPIClass from the SPI_Multiple_Buses example... Does this look like I am understanding radio.begin() correctly?
#include <SPI.h>
#include "RF24.h"
// Define ALTERNATE_PINS to use non-standard GPIO pins for SPI bus
#define VSPI_MISO 12
#define VSPI_MOSI 16 // instead of 13
#define VSPI_SCLK 14
#define VSPI_SS 15
#define CE 4
#define CSN 5
RF24 radio(CE,CSN); // Instantiate an object for the nRF24L01 transceiver
//uninitalised pointers to SPI objects
SPIClass * custom_spi = NULL;
void setup() {
//initialise instances of the SPIClass attached to VSPI
custom_spi = new SPIClass(VSPI);
//alternatively route through GPIO pins of your choice
custom_spi->begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, SS
radio.begin(custom_spi,CE,CSN);
// radio.begin();
//... additional radio setup...
}