Page 1 of 1

SPI between two RPi's

Posted: Wed Feb 13, 2013 3:59 am
by venksntu
I connected with 3(MOSI,MISO,CLK)wires between two RPi for SPI. Is a CS needed in between two RPi. In one RPi i connected MOSI to MISO to measure maximum speed and i able to achieve nearly 3MB/s when i measure between two RPi(MOSI-MOSI,MISO-MISO) i got only 6KB/s. I'm transmitting equal no. of bytes at same time. why it slows down?

Re: SPI between two RPi's

Posted: Wed Feb 13, 2013 6:33 am
by karlkiste
SPI and I2C both require a master device and one or more slave devices. In certain setups, multiple master devices can be possible.

As far as I know, the Pi can only act as a master, so a direct connection between two Pis isn't possible, not with SPI anyway.

MOSI is always an output, MISO is always an input. So if you connect MOSI to MOSI of two Pis, the outputs work against each other and can be damaged!

To transfer data, you can use a multi-master-setup (more common with I2C) using an external memory chip, or just use the UART. Bit-banging an SPI slave would be possible, but slow.

Re: SPI between two RPi's

Posted: Wed Feb 13, 2013 8:31 am
by venksntu
As both are masters can i connect MOSI(RPi1)-MISO(RPi2) n MOSI(RPi2)-MISO(RPi1) ?

Re: SPI between two RPi's

Posted: Wed Feb 13, 2013 9:00 am
venksntu wrote:As both are masters can i connect MOSI(RPi1)-MISO(RPi2) n MOSI(RPi2)-MISO(RPi1) ?
No. As both will driver their clocks, and read data is synchronised on the clock of the master, so if you don't connect the clocks the recieving one will be out of sync.

If you want to pass data at high speed between 2 Pi's I'd suggest using Ethernet. (or serial for slower speeds)

-Gordon

Re: SPI between two RPi's

Posted: Wed Feb 13, 2013 9:02 am
by karlkiste
venksntu wrote:As both are masters can i connect MOSI(RPi1)-MISO(RPi2) n MOSI(RPi2)-MISO(RPi1) ?
You can do that without danger of damaging anything - and without the possibility to transmit data ;-)

The master is the one who generates the clock signal, and a slave inputs and outputs data at the edges of this clock signal.

Two connected masters will both generate a clock signal and not listen to the other master's clock. So no sync, so no data.

Re: SPI between two RPi's

Posted: Wed Feb 13, 2013 9:08 am
by karlkiste
[email protected] wrote: (or serial for slower speeds)
"Slower speeds" are up to 1 megabit. The uart itself can easily do 4MBit and more, but the CPU will struggle to even store the data on a ramdisk in time. If you're employing hardware handshake (rts/cts), you may transmit 4MBit via uart without a problem.

Re: SPI between two RPi's

Posted: Thu Feb 14, 2013 4:10 am
by venksntu
karlkiste wrote:So no sync, so no data.
i did tat pairing and im able to receive @101KB/s(maximum).

UART in the sense? configuring TX,RX pins or USB to USB(ttyusb0)

Re: SPI between two RPi's

Posted: Thu Feb 14, 2013 5:43 am
by karlkiste
venksntu wrote:
karlkiste wrote:So no sync, so no data.
i did tat pairing and im able to receive @101KB/s(maximum).
Did you check the data? It may well be that you did receive something, and if you've been transmitting /dev/zero you might even "see" "correct" data. Transfer real data, and check for integrity.

The SPI master cannot know if there's a slave sending "0000000", or if there's no slave present. The master will receive, even if noone's sending.
UART in the sense? configuring TX,RX pins or USB to USB(ttyusb0)
The USB port is a USB-Host. Same problem like with SPI: You can't simply connect a Host to another Host. There are "USB-Null-modem-cables" which can directly connect two hosts, but they usually require drivers to setup something like a network.

The easy ways to connect two pis together are:

- Network (if using model B)
- UART (connect RX(pi1) to TX(pi2) and vice versa)

Re: SPI between two RPi's

Posted: Thu Feb 14, 2013 6:06 am
by venksntu
overall i'm receiving 2.21MB/s, real data 132KB/s and only junk data 2.01MB/s.

when i displayed the receive bytes, i found the bytes being bounce back which i sent to another RPI. why is it so?

Re: SPI between two RPi's

Posted: Mon Jul 06, 2015 4:04 pm
by krishnaiah.vv
Hi Venk,

Did u already find a solution for SPI communication between two PIs?

BR, Krish

Re: SPI between two RPi's

Posted: Mon Jul 06, 2015 4:07 pm
by DougieLawson
Don't hold your breath waiting for an answer. The last respondent on this thread hasn't visited the forum since "Thu 13 Jun 2013, 00:24".