Multiple masters for SPI RAM 23K512LCV

Hi all,

I have a SPI RAM 23K512LCV connected to my arduino mega through SPI pins.
The arduino continuously writes data to the SPI RAM.

Now, I want to have the second arduino board, which aslo I want to connect to the same SPI ram through SPI pins.

I wonder if it is possible to write to SPI RAM from first arduino, and read from SPI RAM by the second arduino at the same time (I mean writing and reading to same RAM address at the same time)?

Is this possible? Has anyone done that kind of thing before?

Thanks in advance.

Is this possible? Has anyone done that kind of thing before?

No. There is the theoretical possibility to let the one Arduino at a time on the SPI bus while the other is completely disconnected (by hardware) but I guess this is way out of the scope and budget of your project.

Hi pylon,

Did I understand you correctly, that if we have two arduinos physically connected to the same SPI RAM, then this is not gonna work even if only one arduino will make requests of read/write at a time?

Yes, you have to buffer the control signals from each Arduino so that when one Arduino is driving the control signals the other Arduino is not try to drive them to their low, inactive state (like holding SCK LOW).
MISO can be common going back to each, that's it tho.

I would suggest using the SS line as a Reserve line also, to check and see if the shared SpiRam is currently being used by the other Arduino. Also, use an additional shared line as a secondary Reserve pin.
In this way, one Reserve line can be polled then Reserving, before Reserving the second Reserve line (also the SS line). This way the 2 Reserve lines can be used to avoid racing conditions - from competing over Reserving the SpiRam chip.

Ex:

// Both Reserve Pins need External High Impedence Resistors , of course //
#define  RSV1PIN  9
#define  RSV2SSPIN  10
void  ReserveSpiRam()
{
  for(i=1; i<=3; i++)
  {
    // Abort - already Reserved / being used : //
    if(DigitalRead(RSV1PIN) == 0  ||  DigitalRead(RSV2SSPIN) == 0)
      return(0);
  }

  // Try reserving the First Reserve Pin now : //
  DigitalDir(RSV1PIN,OUTPUT);
  DigitalWrite(RSV1PIN,0);

  for(i=1; i<=3; i++)
  {
    // Abort - already Reserved / being used : //
    if(DigitalRead(RSV2SSPIN) == 0)
    {
      DigitalDir(RSV1PIN,INPUT);
      return(0);
    }
  }

  // Success ! - now reserve the Reserve 2 / SS Pin - and use the SpiRam : //
  DigitalDir(RSV1PIN,OUTPUT);
  DigitalWrite(RSV1PIN,0);

  return(1);
}

jlsilicon:
I would suggest using the SS line as a Reserve line also, to check and see if the shared SpiRam is currently being used by the other Arduino. Also, use an additional shared line as a secondary Reserve pin.
In this way, one Reserve line can be polled then Reserving, before Reserving the second Reserve line (also the SS line). This way the 2 Reserve lines can be used to avoid racing conditions - from competing over Reserving the SpiRam chip.

As jlsilicon, use some hardware to enforce the sharing.

this is a circuit I use.

The software to use it is quite simple, SS1, and SS2 are the CS outputs, one from each Arduino. The Owner1 and Owner2 outputs are tested to check ownership of the the Shared SPI device.

The program flow is as follows:

!SS1 is asserted, !OWNER1 is tested, If !OWNER1 it not low, the Assertion failed, De-Assert !SS1 (set it High)
if !OWNER1 was low, continue with SPI transaction.

The same rules apply for !SS2, The D FlipFlop only toggles if BOTH !SS1 and !SS2 are high. So ownership of the shared SPI device does not change until it is released by both Selects.

The only problem I envision could be that if a multi CS transaction is need, and ownership changes.

Chuck.