venksntu
Posts: 13
Joined: Thu Oct 04, 2012 6:34 pm

SPI between two RPi's

Wed Feb 13, 2013 3:59 am

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?

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: SPI between two RPi's

Wed Feb 13, 2013 6:33 am

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.

venksntu
Posts: 13
Joined: Thu Oct 04, 2012 6:34 pm

Re: SPI between two RPi's

Wed Feb 13, 2013 8:31 am

As both are masters can i connect MOSI(RPi1)-MISO(RPi2) n MOSI(RPi2)-MISO(RPi1) ?

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: SPI between two RPi's

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
--
Gordons projects: https://projects.drogon.net/

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: SPI between two RPi's

Wed Feb 13, 2013 9:02 am

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.

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: SPI between two RPi's

Wed Feb 13, 2013 9:08 am

[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.

venksntu
Posts: 13
Joined: Thu Oct 04, 2012 6:34 pm

Re: SPI between two RPi's

Thu Feb 14, 2013 4:10 am

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)

karlkiste
Posts: 184
Joined: Tue Jan 22, 2013 8:50 am
Location: berlin, germany

Re: SPI between two RPi's

Thu Feb 14, 2013 5:43 am

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)

venksntu
Posts: 13
Joined: Thu Oct 04, 2012 6:34 pm

Re: SPI between two RPi's

Thu Feb 14, 2013 6:06 am

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?

krishnaiah.vv
Posts: 19
Joined: Wed Jun 24, 2015 7:34 am

Re: SPI between two RPi's

Mon Jul 06, 2015 4:04 pm

Hi Venk,

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

BR, Krish

User avatar
DougieLawson
Posts: 35537
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: SPI between two RPi's

Mon Jul 06, 2015 4:07 pm

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".
Note: Having anything remotely humorous in your signature is completely banned on this forum. Wear a tinfoil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “General programming discussion”