Go Down

Topic: Ethernet ENC28J60 coexisting with NRF24L01 on SPI (Read 84 times) previous topic - next topic

vqvq


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:
1. Initialize RF24, listen and read data
2. 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"
3. Initialize Ethercard, send data to web
4. Completely close Ethercard. Again, in https://www.aelius.com/njh/ethercard/class_ether_card.html#a9e68ccd9046d3013ce36dbfb50442253 I can see "EtherCard::begin" but nothing like "EtherCard::end"
5. 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

pylon

Quote
I don't think the libraries can do this automatically, right?
I would expect them to do that. You just have to ensure the initial state is correct.

The two libraries you linked to are handling the CS pin internally. Ethercard does not allow you to specify the CS pin, the SS pin of the board is always used (10 for the UNO, 53 for the Mega).

Quote
However, when I connect both sketches together, it does not work.
You neither did post the code that produces the failure nor did you explain what "does not work" means. Do you get an error message? Does the code pretend to work correctly but the communication partner does receive anything?

Robin2

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?
I suspect the library will set its own PIN correctly but it has no means to know that there is another SPI device competing for attention so it might be wise to get your program to de-select one device before trying to communicate with the other device.

I did get an nRF24 working alongside an SD Card but I can't remember the details.

You may also need to check if the two devices use the same SPI settings. It may be necessary to do an SPI.begin() (or something like that) between changes of device.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up