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

Thread: Teensy SPI question

  1. #1
    Junior Member
    Join Date
    Oct 2016
    Posts
    11

    Teensy SPI question

    Hey all,

    I have a few questions about the SPI protocol & pins specifically on the Teensy. I've read through the SPI page on the site a few times, as well as other guides, but there are some things I still don't quite grasp.

    First off, the SPI page mentions that there are specific SPI pins, and that if you can't use those pins, you must use the alternate pins specified in that page (14, 7, 8). However, on the Teensy pinouts they show pins labeled as MOSI/MISO1, MOSI/MISO2, SCK1/SCK2. In the past I've seen this for UART (Tx1, Tx2, Rx1, Rx2) which meant you could connect multiple devices through UART. This seems to stand in contrast to what I'm gathering from the SPI page where it seems only the main SPI pins (13, 11, 12) or the alternates (14, 7, 8) can be used, rather than simply having two SPI devices connected.

    My second question is kind of a continuation of the first. In the SPI page, it mentions that some of the SPI Pins are used by the Audio Adapter, and therefore that would be a situation where you'd want to move them to their alternate positions. However, from the pinout of the audio adapter board, it still shows the alternate pins 7 & 14 would still be used by the audio adapter board. It would seem to me that switching the SPI pins to the alternate positions would still mess with the audio adapter.

    Any clarification or insight is greatly appreciated!

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,032
    SPI is meant to work like a bus. MOSI, MISO & SCK can connect to more than 2 chips. Which chip uses those 3 pins depends on which CS signal is active. So chip needs a dedicated CS signal, but the other 3 signals are shared among SPI chips.

    I2C works similarly, but without CS signals. Complex rules about the data patters allow SDA & SCL to be shared among many chips, as long as each chip's pre-assigned address is unique. Many I2C have one or more pins you connect to GND or VCC to configure which address they'll use, which is meant to give you options to use more chips on the same 2 signals.

  3. #3
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,685
    With the reference card the fainter text is alternate pins, XXX2 labels are for the second SPI interface which runs completely separate to the default one on pins 10/11/12/13 - however most libraries are not yet organised to allow you to switch to SPI2 from your code so you probably would need to edit the actual library to use them. In any case you can't mix main and alternate pins such clk1 and MISO2, just the pins within each SPI set.

    With the Audio shield, it uses pin 13, but is not using it as SPI clock so that is still available if you use the alternate pin.

  4. #4
    Junior Member
    Join Date
    Oct 2016
    Posts
    11
    Thank you both for your replies. I was mistakenly thinking that the Audio board was using those same SPI pins for SPI, but as I see now as you pointed out, 13 was being used for RX, and pin 11 for a clock signal.

    I haven't gotten SPI to work yet with the audio board (despite moving MOSI to 7 & SCK to pin 14), regardless of how I set the clock divider. The acting slave is an Uno, but seeing as I don't have much more information to provide at the time, I'll follow up once I take a look at the signals more closely.

  5. #5
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,685
    If you have access to a scope you this is fairly easy to look into, but if you don't have one may be worth writing some basic code on the uno side that polls a pin and if change happens writes the millis() value to an array at least 16 cells deep. Once array is full write out the values to serial or display. Then point the code at each SPI pin in turn and see what it does (without any SPI libraries in code). Clock should toggle at your target clock rate, data should be toggling at multiples of your clock rate and chip select should toggle for the duration of one data send.
    Last edited by GremlinWrangler; 01-16-2018 at 08:14 AM. Reason: Grammer

Posting Permissions

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