Hi,
First of all, I have to be honest: i din't search all post on forum, so please forgive me if this is a double post.
I recently purchased two radio modules wich communicate with arduino via SPI.
Right now, I'd like to use a radio module together with arduino ethernet shield.
I've read that ethernet library uses spi library, but i can't figure how to control chipselect pins.
I mean, if I use Ethernet.begin() the output pins are "automagically" configured. So I suppose that if I use an Ethernet.stop() function - if any - the output pins are released and i could drive my radio module via spi and another chip select pin.
two questions:
I din't try yet the Ethernet.stop() fucntion, but it seems id doesn't exist. Is there a way to turn off the chip select pin in order to dirive another device via spi?
If Ethernet.stop() (or similar) exists, i can use it freely or I have to wait lots of ms (I know "lots of ms" sounds freaky) and I need to reconfigure my ethernet connection and get again the ip?
I mean, if I use Ethernet.begin() the output pins are "automagically" configured.
No. The SPI pins are, but not the chip select pin. That's why every single ethernet sample emphasizes the need to set pin 10 as an OUTPUT pin.
So I suppose that if I use an Ethernet.stop() function - if any - the output pins are released and i could drive my radio module via spi and another chip select pin.
You don't need to do that.
The ethernet functions take care to set the correct chip select pin to the correct state before they try to read/write the SPI pins. You simply need to assure that the code you write/library you use for the radios does the same thing.
I din't try yet the Ethernet.stop() fucntion, but it seems id doesn't exist.
It doesn't.
Is there a way to turn off the chip select pin in order to dirive another device via spi?
Yes. The pin simply needs to be set HIGH or LOW to enable or disable (or, is that disable and enable) reading/writing to that device. The ethernet library manages this for its chip select pin.
If Ethernet.stop() (or similar) exists, i can use it freely or I have to wait lots of ms (I know "lots of ms" sounds freaky) and I need to reconfigure my ethernet connection and get again the ip?
Be specific about the radios. A link to the devices you are using would be very helpful.
The ethernet and SD libraries take care of their own slave selects (D10 and D4). Your code should deal with your slave select only. If SS is the slave select for your device, then very simply this:
// enable this slave only
digitalWrite(SS,LOW);
// delay 1us after SS LOW
delayMicroseconds(1);
// transfer to that device
// may need multiple transfers here
rtnVal = SPI.transfer(0x00);
// disable this slave only
digitalWrite(SS,HIGH);
All SPI slave select pins should be OUTPUT and HIGH when leaving the setup() function.
This presumes all devices are SPI mode 0, MSB first, and 4MHz SCLK. These can be changed on the fly for each device, but you should always return them to those settings when finished.
this should disable the ethernet peripheral and I could write to my radio device.
edit: I noticed only now SurferTim's reply.
The devices I am using are low price modules I bougth in an electronic's exibition few weeks ago.
They are two nrf24l01 modules, but I didn' search for any ready-to-go library. I toughth that spi could have been enough.
similar to these ones http://blog.iteadstudio.com/2-4g-wireless-module-nrf24l01-module/ but mine have a less weel-engineered antenna.
It shows SPI mode 0, MSB first and capable of 5MHz. You may need to reduce the speed if the module has long leads connecting it to the Arduino. Keep the SPI bus leads as short as possible.
I'm almost certain there is library code around here for that device.
Yep, I already got datasheet.
My question is (was) about using it together with ethernet shield due to the Spi "arbitration".
Anyway, the suggestion on keeping short leads is a good one, I didn'think about that. Anyway, unless they are shorter of 60cm I think it shouldn't be a problem.. or am I wrong?
I'm pretty new to Arduino, I am used to a different kind of microcontroller coding so I have to change the entire approach.
I'm almost certain there is library code around here for that device.
No problem there. Any time you are not in a device SPI.transfer routine, ALL SPI slave selects should be HIGH. The w5100 library uses the same type function as above to transfer. The slave select is set LOW at the start of the function, the transfer happens, then the slave select is set HIGH before returning. Same with the SD library.
The Ethernet.begin() function has a small bug. It leaves the w5100 slave select (D10) LOW (active). After that function, you must set D10 HIGH.