double up on SPI library

Hi Guys hope someone can shed some light on this subject.

I have a UNO that i want to connect to a Data radio and SD card

problem is both the SD card and data Radio works on SPI bus. I know you can use two devices on the smae SPI bus but im not fimilar with the Shift out functions. i wantted to you if it was possible if i created my own clown of the SPI.h file and changed the pin outs to lets say. 7,8,9 and inlcuded into my program under name

#include SPI2.h

will that work ? seems alot easier then trying to figure out master and slaves on the same line.

all thoughts and comments are welcome

I know you can use two devices on the smae SPI bus but im not fimilar with the Shift out functions.

This is like saying "I know that you can use two devices on the same bus, but I don't like chocolate pudding". The two phrases have absolutely nothing in common.

i wantted to you if it was possible if i created my own clown of the SPI.h file and changed the pin outs to lets say. 7,8,9 and inlcuded into my program under name

#include SPI2.h

Sure, you could do that. Wouldn't work. SPI is hardware based. It is a hardware function of pins 11, 12 and 13. You can't create a header file to rewire the internals of the chip. Well, not and have it actually work, anyway.

seems alot easier then trying to figure out master and slaves on the same line.

I don't see how setting the appropriate slave select pins HIGH and LOW is that difficult. Create a function, useRadio() to set the two slave select pins one way, and create a function, useCard() to set them the other way.

Rustie0125:
will that work ? seems alot easier then trying to figure out master and slaves on the same line.

I don't follow this bit. To control two devices with SPI you do something like:

digitalWrite (8, LOW);  // select first device
SPI.transfer (42);
digitalWrite (8, HIGH);  // deselect first device

digitalWrite (7, LOW);  // select second device
SPI.transfer (666);   // :-)
digitalWrite (7, HIGH);  // deselect second device

In what way is writing an entire new library easier than this? Plus, the hardware doesn't support it.

Hi Nick wasnt planning on rewriting the new library only copy and past and change pin layouts in that library . I have been reading up on how to use two devices now on one bus , and I agree its straight forward . im just a bit sceptically of how to make it work , my two SPI devices is a SD card and a Data radio that has to send information from the SD card which means I need to talk to both at the same time ...? or am i mistaken

how must I go about it ?

Thanx in advance

Hi Paul

Yes thank you for you comment , I didnt know SPI was hardware based only thought might work as softwareSerial library.

I assume the best way forward is to setup the functions like you called them. then Read from the SD card save to buffer switch to Radio program and read from buffer to transmit yes?

then Read from the SD card save to buffer switch to Radio program and read from buffer to transmit yes?

Yes.


Rob

Rustie0125:
which means I need to talk to both at the same time ...? or am i mistaken

how must I go about it ?

Basically as I showed above. Access one device, and then the other. That is close enough to being "at the same time".