Go Down

Topic: Multiple SPI devices on single Uno: Ethernet shield + nrf2401 chips (Read 932 times) previous topic - next topic

arusr

Hello,
I had this plan on using a couple of Arduino Uno's as "field sensors", reporting sensor data back to a central Arduino Uno.  Each Uno would have a nrf2401+ chip.  The field Unos would send sensor data via the nrf2401+ chip wirelessly to the central Uno, which also has a nrf2401+.  In addition, the central Uno would have an ethernet shield and run a web server to serve the sensor data webpage.

However, the ethernet shield uses SPI, as does the nrf2401+ chips.  Is it difficult/possible to use two SPI devices on the same Uno?  The nrf2401+ uses a 4-pin SPI interface, so there a MOSI, MISO, SCK (clock), and SCN (is this the slave select?  same as "chip select?").  

I know SPI is suppose to be able to work with multiple devices.  But the field Unos are sending data at random intervals to the central Uno.  And the central Uno is receiving http requests at arbitrary times.  How does the central Uno make sure to "listen" to the right device (Ethernet shield or nrf2401) at the right time, since only one slave is selected at a time?  I can't monitor for http request at the same time that I'm monitoring for field device transmissions.  Or does the Ethernet shield buffer data until the master polls it?


Edit:  For reference, this is the nrf2401 chip:
http://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01P


Charly86

Hi arusr,

Excellent question, I'm not sure but it could work fine, as soon as you use 2 differents CS pins one for Ethernet and one for NRF24.

As NRF24 is buffering the incoming packet it should work even if you wait just "little" time because of processing network job. You can even use a interrupt to detect new packet on NRF (but don't do job in interrupt, just setup a flag that will help processing in main loop). But I do not know if ethernet shield use interrupt and which.

with NRF24 using no interrupt your main loop could be something like that
{
  do network stuff
  do nrf24 stuff
}

and if you use interrupt (check that it is not the same interrupt than the Ethernet shield if this one use it)
void loop
{
  do network stuff
if ( got_data)
  {
    do nrf stuff
   disable nrf interrupt
    got_data = false;
   enable nrf interupt
  }
}

void nrf_isr
{
got_data = true;
}



Ecxelent thread!
Im building some thing similar (identical), using Atiny84 as nodes.
Now im finalising debugging ethernet on central uno.
Im really eager to find out answer to those problems, although I havent encountered them yet.

I ll be watching this space. defo.

CrossRoads

Uno can have 17 different SPI devices, 3 pins go to each device- SCK, MOSI, MISO - leaving up to 17 free for chip select/slave select. Keep 2 back for Serial port for debugging, still leaves 15.
Libraries might need tweaking to support that. And if using shields, may have to do some cuts & jumpers to make sure pins are not conflicting.
Why not have the master poll the slaves for data?
Master: "#1, got data?"
#1: "No"
Master: "#x, got data?"
#x: "Yes, here it is"
Master: "#x, data received".

Then Master sends out via ethernet as needed. Can also be used to ensure each field device is still active.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

RPieter

Hello CrossRoads,

I am trying to get only 2 SPI devices to work on my UNO board, so if you say I can have 17, I should be able to get it to work, right? Can you please give me some advice on the part where you say the libraries need tweaking for that. Where do I start with that?

I have two shields, both using 10-13 for SPI communication. Now for 1 shield I want to change the SS/CS pin from 10 to another one. I will start by just putting 1 shield on the UNO and trying to get it working using another pin for SS/CS. The library files for my shield are in attachment of this message, I already found out that the SS/CS should be changed in the file "mcp_can_dfs.h". But after doing this, recompiling/flashing and connecting pin 10 of the shield to the new pin on which I address the SS/CS, nothing happens anymore. It is not working. I went a bit deeper into the topic and so I found the file "pins_arduino.h" in the root-folder of Arduino. There is also a definition for pin 10:   static const uint8_t SS   = 10;   I tried changing this to the desired pin number, BUT I could not save it, because the whole Arduino folder is Read-Only. Tried changing this but without any success.

Any tips on this topic?

Thanks, Pieter


Uno can have 17 different SPI devices, 3 pins go to each device- SCK, MOSI, MISO - leaving up to 17 free for chip select/slave select. Keep 2 back for Serial port for debugging, still leaves 15.
Libraries might need tweaking to support that. And if using shields, may have to do some cuts & jumpers to make sure pins are not conflicting.
Why not have the master poll the slaves for data?
Master: "#1, got data?"
#1: "No"
Master: "#x, got data?"
#x: "Yes, here it is"
Master: "#x, data received".

Then Master sends out via ethernet as needed. Can also be used to ensure each field device is still active.
Let's make it !

CrossRoads

On one of the shields, you will have to cut a trace from pin 10 to where-ever it connects and connect say pin 9 to that where-ever location instead.
As far as the software, that's not really my area of expertise,  I have not used the software for either shield and don't really know what is needed to change the SS used.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

RPieter


On one of the shields, you will have to cut a trace from pin 10 to where-ever it connects and connect say pin 9 to that where-ever location instead.
As far as the software, that's not really my area of expertise,  I have not used the software for either shield and don't really know what is needed to change the SS used.


Ok, thanks :)

I will look further into it on how to change the software for this.
Let's make it !

Go Up