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

Thread: Teensy3 Pinout Options and SPI Question.

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    18

    Teensy3 Pinout Options and SPI Question.

    Hi all,

    The Teensy3 pinout drawing shows a second copy of Serial1 signals and some SPI signals. I checked the MK20 datasheet and these are valid pin routing options. Is it possible to make use of them using the supplied libraries? For example, I would like to put SCK on pin D14.

    Also, the SPI pinout shows 5 chip selects. Does the Teensy3 SPI library make use of them? If so, how? Or do I have to manually manipulate them as per the standard Arduino SPI library?

    Paul

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,171
    TeensyDuino 1.16 has just been released and one of its new features is:
    SPI library can assign alternate Teensy3 pins: setMOSI, setMISO, setSCK.
    I haven't tried it yet but it looks like it'll do what you want.

    Pete

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,752
    Yes, the functions to change the 3 main pins are now in the SPI library.

    Quote Originally Posted by PaulG View Post
    Also, the SPI pinout shows 5 chip selects. Does the Teensy3 SPI library make use of them?
    No.


    If so, how? Or do I have to manually manipulate them as per the standard Arduino SPI library?
    Yes. The SPI library attempts to work just like it does on Arduino (even though the underlying hardware is vastly different).

  4. #4
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks guys,

    I will try this out.

    BTW, glad to see Teensyduino 1.16 is released - hopefully this will cure my Mac upload problems.

    Paul

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    OK, I located these functions in .../cores/teensy3/avr_emulation.h and can see how to call them. Should I call them before or after calling SPI.begin()?

    As an aside, where is the SPI library code located? I can't find it in the teensy3 folder.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,752
    Call them before SPI.begin().

    The SPI library code is in the libraries/API folder. On a Mac, control-click Arduino and use "show package contents", then dig in a few layers of folders until you find "libraries".

  7. #7
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks Paul.

    I found the SPI code, but i'm even more confused now. It appears to be for the AVR chips. How does it relate to the MK20 chip?

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,752
    Quote Originally Posted by PaulG View Post
    It appears to be for the AVR chips. How does it relate to the MK20 chip?
    The AVR's SPI registers are emulated by software. Look at hardware/teensy/cores/teensy3/avr_emulation.h

  9. #9
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks, found it.

    Wow, you've certainly put a lot of work into this. Why did you need to emulate the AVR SPI hardware? Could you not have just implemented the half dozen or so SPI API functions?

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,752
    Many important libraries have the AVR SPI registers hard-coded. Nearly all of Adafruit's libraries which access SPI do this.

  11. #11
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Understood. Thanks for taking the time to answer my questions.

Tags for this Thread

Posting Permissions

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