Arduino with SPI two device

Hello All !

  • Arduino connect SPI with 2 device
  • Mrf (send and recieve)
  • RFID reader ( read)

SS1 (mrf) -> D10
SS2 (RFID) -> D9

  • After enable SS1 and SS2 . I send data. I have something to question.
  • If enable SS1 and enable SS2 on same time . Have problem ? Because I think, Each of these device have difference function.
    This something wrong or true ?

Because my problem : RFID send key tag to Arduino, after Arduino send data to Mrf . But 2 device even SPI connect

Activate only one at a time. Only one slave select should be LOW. All others should be HIGH.

So, when enable SS1, I should disable SS2.

  • write port SS1 LOW and write port SS2 HIGH, when I use mrf and the other way.

But,in function void setup() , I must set up SPI for mrf and RFID reader. So, in function void loop() I set SS1 LOW and SS2 HIGH. Have problem ?

I disable, then enable. Like this:

digitalWrite(SS1,LOW);
SPI.transfer(ss1byte);
digitalWrite(SS1,HIGH);

digitalWrite(SS2,LOW);
SPI.transfer(ss2byte);
digitalWrite(SS2,HIGH);

My code

#include <SPI.h>
#include <mrf24j.h>
#include <RFID.h>

const int pin_reset = 6;
const int pin_cs = 10; // default CS pin on ATmega8/168/328
const int pin_interrupt = 2; // default interrupt pin on ATmega8/168/328
// Set pin Mrf

#define SS_PIN 4
#define RST_PIN 9

RFID rfid(SS_PIN, RST_PIN); // Set SPI for RFID

Mrf24j mrf(pin_reset, pin_cs, pin_interrupt); // Set SPI for mrf

long last_time;
long tx_interval = 1000;

void setup() {

mrf.reset();
mrf.init();

mrf.set_pan(0xcafe);
// This is our address
mrf.address16_write(0x6001);
attachInterrupt(0, interrupt_routine, CHANGE); // interrupt 0 equivalent to pin 2(INT0) on ATmega8/168/328
last_time = millis();
interrupts();
}

void interrupt_routine() {
mrf.interrupt_handler(); // mrf24 object interrupt routine
}

void loop() {

// My loop

}
}

I set up function SPI, and in loop,

digitalWrite(SS1,LOW);
SPI.transfer(ss1byte);
digitalWrite(SS1,HIGH);

digitalWrite(SS2,LOW);
SPI.transfer(ss2byte);
digitalWrite(SS2,HIGH);

That Ok ?