I have 2 working configurations:
A. Arduino Mega with NRF24L01, using <SPI.h>, <RF24.h> and <RF24Network.h>. It works as a base station receiving measurement data from NRF24 stations. Using pins 50, 51, 52 (SPI), 8 (CSN) and 7 (CE)
B. The same Mega with ENC28J60, using <EtherCard.h>. It properly connects to a web page and sends some data there. Again, using pins 50, 51, 52 (SPI), and 53 (CS=SS)
However, when I connect both sketches together, it does not work. TBH, I'm a little worried that I could burn some components so I did not do much testing of the combined setup.
The key condition for multiple SPI devices coexistence is met, NRF connects to pins 7 and 8 while ENC28 uses pin 53 for their SS. But I think that now I need to programmatically select which SPI device I want to talk to, do the actions needed, switch this SPI device off (setting SS high), selecting the other SPI device (SS low), work with it etc. I don't think the libraries can do this automatically, right?
Is it OK for the libraries if I directly change the SS pin values by my code? Or should I use some predefined library functions for such (de-)activation of selected device? In fact, looking at the libraries, I don't see any such de-(activation) function available. I expect that directly changing the SS pin may be too brutal for the libraries which may get in trouble while 'their' device is not listening. What is the correct procedure here?
Alternatively, I'm thinking of another option with the following sequence of events:
- Initialize RF24, listen and read data
- Completely close RF24. But how? In http://tmrh20.github.io/RF24/classRF24.html there is "bool RF24::begin(void)" available but I can't find anthing like "RF24::end"
- Initialize Ethercard, send data to web
- Completely close Ethercard. Again, in EtherCard: EtherCard Class Reference I can see "EtherCard::begin" but nothing like "EtherCard::end"
- Repeat 1-4
Obviously, in such scenario, the calls usually placed in the setup() would need to be called from loop() - would this be a problem? (I think not)
Any comments welcome
vqvq