Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Use Teensy 3.1 as Slave first, then Master second

  1. #1

    Use Teensy 3.1 as Slave first, then Master second

    Here's the general layout of what I'm trying to do.

    In LabView, I have an FPGA that sends a byte of information to my Teensy via SPI. The Teensy acts a slave in this case, the FPGA being the master.

    What I want to do next is take that byte (let's say it's 150 in decimal), and use it to test an "if" condition in order to light an LED. This "if" condition being built into the chip on the Teensy.

    This is where I want to introduce an SPI-incorporated single-channel digital pot (MCP4151). If the byte in decimal form being transferred is 150, I want to use the Teensy to send 150 to the digital pot to represent the wiper step. The MCP4151 has 0-255 steps, and it's a 50k ohm max. If the 150 gets there, my LED will light up to such a brightness.

    Before I try that second task I want to know if this is even possible? Using the Teensy first as a slave, then as a master. Or any other Arduino board for that matter (I will get the necessary board if need be).

    Thanks

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,248
    According to the Teensy SPI page, the SPI library only supports master mode. http://www.pjrc.com/teensy/td_libs_SPI.html.

    I did notice the following on github that talks about implementing SPI slave mode. Note, the code is 3 years old, and appears to have only been tested on the Teensy 3.0 (which was the only Teensy available at that time). You might contact the author to see if there is a newer version of the code: https://github.com/btmcmahan/Teensy-...Master---Slave.

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,414
    Others can probably answer this better than I can, but:

    In order to do what you are talking about sounds like directly, I believe you are talking about using SPI in a multi-master mode. Not sure if the Teensy can do this or not, also not sure if your host would like this or not.

    However, there may be another approach. If you purchase a Teensy LC (or one of the soon to be released 3.5 or 3.6), boards, they have multiple SPI busses on their chips.

    So for example using Teensy LC, connect the host up to the Teensy using the SPI object (default pins 11, 12, 13 plus CS) and connect your MCP4151 up to the Teensy using SPI1 object, default pins (0, 1, 20).

  4. #4
    Thank you both for the responses, and I think going with the Teensy LC with multiple SPI busses will be the most prudent. I guess so long as the code is distinct enough to separate the master-slave functionalities there shouldn't be any problems.

    There are function options for Teensy 3.1 that allow you to move the SPI to alternate pins but I don't know how reliable that is (e.g. SPI.setMOSI(pin) etc.). Just as a forethought.

  5. #5
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,248
    Quote Originally Posted by lennon-pledge View Post
    There are function options for Teensy 3.1 that allow you to move the SPI to alternate pins but I don't know how reliable that is (e.g. SPI.setMOSI(pin) etc.). Just as a forethought.
    The sound board uses the alternate pin functions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •