Davidelvig
Well-known member
I'd welcome clarification on use of multiple SPI devices on Teensy.
I am using Teensy 3.2 and 4 SPI devices, one of which employs 2 Chip Select pins for "command" vs "data" functions.
So, 4 SPI devices, and 5 CS pins.
I am using the standard SPI pins for SCLK (13), MOSI(11) and MISO(12).
Of note, perhaps, I use the "standard hardware SPI pin" (Teensy pin 10) for non-SPI purposes... in its TX2 role.
Also noting: Arduino documentation says that SPI.begin() "Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high."
Everything works now, but I've had a number of SPI initialization challenges in the project over the last year.
My questions:
Thanks!
I am using Teensy 3.2 and 4 SPI devices, one of which employs 2 Chip Select pins for "command" vs "data" functions.
So, 4 SPI devices, and 5 CS pins.
- My Synth library (for VLSI's VS1053) calls SPI.begin() in the synth class constructor - setting both CS pins to OUTPUT and HI (CS = Teensy pin 26; XCS = Teensy pin 31)
- The IMC library from SparkFun (ICM_20948) in a device "begin()" call explicitly says "// _spi->begin(); // Moved into user's sketch" (CS=Teensy pin 3)
- The SD library, into which I pass a pin number - and the Teensy-embedded SD.h (not the optimized version) seems to use the equivalent of SD.begin() (CS =20)
- The Adafruit_ST7789 library from AdaFruit for a TFT display (Adafruit's library uses 3 layers of SPI-initialization-related code to handle multiple display types) (CS=Teensy pin 29)
I am using the standard SPI pins for SCLK (13), MOSI(11) and MISO(12).
Of note, perhaps, I use the "standard hardware SPI pin" (Teensy pin 10) for non-SPI purposes... in its TX2 role.
Also noting: Arduino documentation says that SPI.begin() "Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high."
Everything works now, but I've had a number of SPI initialization challenges in the project over the last year.
My questions:
- What's the best practice for calling SPI.begin: when (in what code) - various libraries (object constructor or explicit ::begin() method); or one or more "modules" in the sketch?
- Can I safely call SPI.begin() multiple times?
- If SPI begin sets the default CS pin to HIGH, could that subvert my use of TX2 in any way? (It does not yet appear to cause issues.)
Thanks!