I am developing a device with Ethernet shield (with Wiznet W5100) and NRF24L01+. I need to use Soft SPI due to a bug in the Wiznet chip. Next I am developing a different device with NRF24L01+ only. I want to use hardware SPI (besides other things it already contains a socket for NRF24L01+ connected to the default Arduino SPI pins).
It is very inconvenient to enable/disable #define SOFTSPI
in RF24_config.h
every time I want to work on the other device.
Is there a way how to choose the SPI type used by RF24 library in the application?
My current solution is to make a copy of RF24 to RF24_SoftSpi and RF24Network to RF24Network_SoftSpi. I enabled SOFTSPI in "_SoftSpi" versions (+ renamed all files, fixed includes and #ifndef statements in headers to avoid ambiguous errors).
Then in an application I just include RF24_SoftSpi instead of RF24 and RF24Network_SoftSpi instead of RF24Network to use software SPI.
With this workaround it is difficult to make updates to "_SoftSpi" libraries when a new feature is released.
Do you know of any better solution?
-
This might help; itead.cc/wiki/IBoardMikael Patel– Mikael Patel2016年12月05日 22:20:25 +00:00Commented Dec 5, 2016 at 22:20
1 Answer 1
Using this RF24 library set, I am able to use or not softspi by doing #define SOFTSPI on my sketch, there's no need to define it on the RF24_config.h, you should be able to define it on your own sketch.
EDIT:
Arduino 1.6.5
#include <SPI.h>
#include "RF24.h"
#include "printf.h"
#define SOFTSPI //Define pins RF24_config.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(8,9);
....
....
void setup() { ... }
void loop() { ... }
-
thank you for your answer. Would you be so kind and add an example into your answer including Arduino IDE version you use?Michal Foksa– Michal Foksa2015年11月22日 19:28:55 +00:00Commented Nov 22, 2015 at 19:28
-
See edited answer aboveCarlcox89– Carlcox892015年11月23日 20:56:47 +00:00Commented Nov 23, 2015 at 20:56
-
#define
directive does not have any impact on library build. Libraries are compiled separately and do not take any directive from sketch into account. Verify your sketch with and without the#define SOFTSPI
directive. Size of the result will not change, but it should by approx 2kb.Michal Foksa– Michal Foksa2015年11月25日 08:55:12 +00:00Commented Nov 25, 2015 at 8:55 -
This solution does not work unless proven otherwiseMichal Foksa– Michal Foksa2016年05月10日 09:44:06 +00:00Commented May 10, 2016 at 9:44
-
2Try defining Soft SPI before including the RF24 related headers.sekdiy– sekdiy2016年06月10日 06:29:18 +00:00Commented Jun 10, 2016 at 6:29