Pages: [1]   Go Down
Author Topic: Send to Master w/ Arduino as SPI Slave  (Read 905 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm trying to find a way to send data from an Arduino Nano to a Raspberry Pi over SPI (SPI because UART and USB on my Pi are both being used for other purposes, I know I could use a USB hub, but I don't have a means to power one in my situation). The main problem I've found is that in the case of the Pi the hardware is incapable of being a slave and in the case of the Arduino the SPI library doesn't support being a slave. I've read Nick Gammon's post on SPI as well (http://www.gammon.com.au/forum/?id=10892), but don't see a method on there for sending data from the slave (Arduino) to the master (Pi), only the other way around. Is this something that would be possible? If so would anyone be able to point me in the right direction?

To just throw an idea out there, from the previously mentioned article I do see a means of responding to a request from the master for data, could I possibly send a trigger from the Pi to the Arduino then reply with a constant stream of data? If this would even work it would require a loop inside the interrupt to repeatedly pull data from the sensors (some analog, some digital, some I2C), which I have a feeling is going to cause problems.

Any help is appreciated!
« Last Edit: February 09, 2013, 06:26:38 am by FergyA » Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19367
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In SPI the master provides the clock, so it has to initiate communication.

However during each SPI.transfer() call data always goes both ways. So you are always sending and receiving at the same time.

Quote
in the case of the Arduino the SPI library doesn't support being a slave

My post describes exactly how to make an SPI slave:

http://www.gammon.com.au/forum/?id=10892&reply=1#reply1
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, so I'm probably just confusing the heck out of myself then, pardon me I'm pretty new to electronics (I picked a doozy of a project to start with). So can I just shove data into the SPDR outside of an interrupt and have it send to the master? I really only need a unidirectional link and only being able to send when the master triggers the interrupt isn't going to work for my implementation. Especially since an interrupt coming from the Pi is likely to flood the Arduino with so many interrupts it locks up and I don't get any data off of my sensors (been there, done that).
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19367
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So can I just shove data into the SPDR outside of an interrupt and have it send to the master?

Absolutely not, because the master controls when data is sent. You may as well say "can I pick up the phone and talk into it, even before it rings?". Well you can, but no-one will hear.

Quote
Especially since an interrupt coming from the Pi is likely to flood the Arduino with so many interrupts it locks up and I don't get any data off of my sensors (been there, done that).

Why would that happen? Are you designing both ends of this?

Get the Pi to query the Arduino for something, and get a response back.

eg. Using code as if both ends were Arduinos because I don't know the Pi syntax:

Master:

Code:
SPI.transfer (1);    // give me temperature
byte lowTemp = SPI.transfer (0);  // receive low byte
byte highTemp = SPI.transfer (0);  // receive high byte

int temperature = (highTemp << 8) | lowTemp;

Repeat for other sensors.

The second and third transfer just send 0  (in effect, a no-op) because you have to transfer something, to get something back.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Pages: [1]   Go Up
Jump to: