DmaSpi icon indicating copy to clipboard operation
DmaSpi copied to clipboard

Support SPI slave

Open lanrat opened this issue 8 years ago • 6 comments

It would be useful if the Teensy could act as a SPI slave device when connecting to another micro-controller.

lanrat avatar Sep 27 '16 19:09 lanrat

I've thought about this a couple of times and also started a thread in the teensy forum, but there seemed to be little need.

What exactly would you like to do? Can you post an example protocol? What should happen if the master stopped SPI communication early?

crteensy avatar Sep 28 '16 19:09 crteensy

My use case is as follows. I have a proprietary microcontroller that reads data from sensors over SPI. I'd like the Teensy to be able to act as a sensor. The propitiatory microcontroller acts as the SPI master and the sensors are all slaves.

If the master stopped SPI communication before the slave finished transmitting then that slave device should stop and wait for the enable signal from the master before resuming sending data. This is not to say that the entire Teensy should wait, other operations should be able to continue and optionally poll the SPI library to see the status of the transfer.

Does that seem reasonable?

lanrat avatar Sep 29 '16 03:09 lanrat

Depends... You didn't go much into detail about the SPI protocol. Would it be a kind of "command and response" protocol or rather a very simple "read the same array again and again" protocol? I guess that is something that is open to be decided, but simple protocols require less work and lessons learned during the work might be useful later.

crteensy avatar Sep 29 '16 20:09 crteensy

I'm still working on reverse-engineering the protocol. from what I've learned so far it seems to be command and response.

I'd think that ideally the SPI library would be generic enough so that either model could be built on top of it.

lanrat avatar Sep 30 '16 22:09 lanrat

Sorry for the delay!

Well, a generic library is of course the thing to go for, but: even a simple command-response protocol might be hard to implement even with code tailored for that purpose, because the master might not leave enough time for the slave to prepare a response after the command was sent. This has a ton of implications for just about any part of the code and protocol details.

crteensy avatar Oct 04 '16 20:10 crteensy

hi guys, sorry to intrude, this “issue” caught my eye.

Teensy does have a spi slave/master communication library now, you may check the forums for it

tonton81 avatar Apr 10 '18 13:04 tonton81