Two SPI on Arduino UNO?

Hello , I have problem because I want to connect two device to my arduino. First is wireless module RFM70 and graphic display ST7565R. Both are with SPI interface.

I am using DOGM128 library for display and code for RFM70 from here

RFM70
ST7565R

Make a second CS line on any digital pin:

Yes, you definitely need one CS line per device. One of them can be the SPI SS pin (which must be set as an output in any case), the others can be any free pin.

You have to be careful mixing different devices on the SPI bus, as they may have different settings for CPHA, CPOL and clock speed. If so then you have to reprogram the SPI registers everytime you switch from one library to the other (its even worse if a library uses an interrupt routine that talks SPI).

So if I want to choose one of the device I can do something like this?

...
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
...

When RFM70 CS pin is connect to arduino pin 2 if I choose it I disable ST7565R?

I can do something like this?

Not quite.
You drop the CE line just before you do a transfer and raise it straight after.
So you drop the appropriate CE line, not quite what you have shown.

Okey, I try change PIN_SS of st7565r but I have big problem. When I use deafult chip select pin (10) SCK is working normally when I changed PIN_SS to 5 SCK doesnt work(led diode stops blink).

I change values in dogm128.h in section #ifndef ADA_ST7565P_HW .

When I change only PIN_A0_DEFAULT to another I/O pin then it is working.

I connect rfm70 and st7565r and I wrote program:

#include <TouchScreen.h>
#include <Dogm.h>

//Wireless----------------------------------------------------
#include "RFM70.h"

RFM70class RFM70;
byte RFM70_buf[MAX_PACKET_LEN];  //RFM70 data buffer
unsigned long RFMSendTime = 0;   //next send time
int RFMSendSpeed=1;           //send packet every 1000 msec
//------------------------------------------------------------
int a0Pin = PIN_A0_DEFAULT;
Dogm dogm(7);

TouchScreen ts(3, 1, 0, 2);
int s,t = 0;              // s {10 - 100}  t {5 - 55}
int car_speed, car_turn = 0;  //car_speed {5 - 95 } car_turn {3 - 53}
int coords[2];


void setup(void){
 
  Serial.begin(9600);
  dogm.setContrast(10);
  //Wireless----------------------------------------------------
  RFM70.begin();
  RFM70.Initialize();
  RFMSendTime = millis();
  //------------------------------------------------------------
  pinMode(10, OUTPUT);
  pinMode(6, OUTPUT);
}

void read_speed(){
  if((coords[0] > 200) && (coords[0] < 800) && (coords[1] > 200) && (coords[1] < 815)) {
      Serial.print(", Speed:");
        s = constrain(map(coords[0], 200, 800, 10, 100), 10, 100);
        t = constrain(map(coords[1], 200, 800, 5, 55), 5, 55);
      Serial.print(s);
      Serial.print(":");
      Serial.println(t);
  }
}


void draw(){
    dogm.setHLine(20,110,30);  //speed
    dogm.setVLine(65,8,55);    // turn
    
    dogm.setVLine(120,0,63);  
    dogm.setHLine(0,119,5);
    dogm.setHLine(0,119,60);  
    
	//wykrywanie przeszkód
	/*if ( lewo == true ){
		dogm.setBox(0,61,119,63);  // góra , czyli przeszkoda po lewej   
	}
	
	if (przodek == true){
		dogm.setBox(121,0,127,63);  
	}
	
	if ( prawo == true ) {
		dogm.setBox(0,0,119,4);
	}  */
    
    dogm.setBox(115 - s,58-t,125 - s,64-t);

}
void loop(){
  
  DOG_PGM_P p;
  // zczytanie z panelu
  ts.read(coords);
  Serial.print(coords[0]);
  Serial.print(",");
  Serial.println(coords[1]);
  
  // komunikacja 
  
  [b]digitalWrite(10,LOW);[/b]
  dogm.start();
  do{
  digitalWrite(10,LOW);
    read_speed();
    draw();
    car_speed = 115 - s;   //car_speed {5 - 95 } car_turn {3 - 53}
    car_turn =  58 - t;
  [b]digitalWrite(10,HIGH);  [/b]
    
   [b] digitalWrite(6,LOW);[/b]
    rfmTask();
  
    if (millis() > RFMSendTime)                   //send packet
    {                                                    
      RFMSendTime = millis() + RFMSendSpeed; 
      RFM70_buf[0]=0X41;      
      RFM70_buf[1]=0X42;
      RFM70_buf[2]=0X43;
      RFM70_buf[3]=0X44;           
      RFM70.Send_Packet(WR_TX_PLOAD,RFM70_buf,3);  
    }
 [b] digitalWrite(6,HIGH);[/b]
  
  } while (dogm.next() );
  
  
}

void rfmTask()                //RFM70 event handler
{
  if (RFM70.RfmInterrupt())
  {
    if (RFM70.TxDataSentInterrupt())
    {
       Serial.println("Data sent OK");
       RFM70.SwitchToRxMode();
    }
    if (RFM70.TxDataSentErrorInterrupt())
    {
       Serial.println("Data sent error");
       RFM70.SwitchToRxMode();
    }
  }
}

On pin 10 i have chip select display, on pin 6 i have chip select RFM70. And only display working. I dont know what I doing wrong.

I don't see you setting pin 5 to be an output.

Why I must pin 5 be as output? I dont use this pin.

Sorry I thought that was your second enable line.

However you still need to put the pin low and high immediately before and after the data transfer, not just some time before and some time after like you have. It should embrace each transfer, not just down at the start of a number of transfers and up after the batch.

Also it looks like the RFM70.h library is using the default pins as well as your own. You might want to try moving both devices off pin 10, onto pins you do control.

You might want to try moving both devices off pin 10, onto pins you do control.

Bummer. This was my last hope, but didn't work for me.
Thanks

I have problem because I want to connect two device to my arduino. First is module mfrc522 and module SDCard.Both are with SPI interface. Please help me
I am using library MFRC522.h and SD libary in arduino. Thanks

nhuthuanphan:
I have problem because I want to connect two device to my arduino. First is module mfrc522 and module SDCard.Both are with SPI interface. Please help me
I am using library MFRC522.h and SD libary in arduino. Thanks

As you have posted your question here I presume you have carefully studied the earlier Replies in this Thread and tried the various suggestions.

You need to post the program that represents your best attempt, tell us what results you got and tell us what you want the program to do that is different.

...R