"CS labeled" Pin use for other than SPI

J-Ro

Member
Is it possible to use pins labeled as CS/CS1 (specifically looking at Teensy 4.1 pins 10, 38, 37, & 36) as Digital I/O unrelated to SPI if SPI is also in use?

I'm not using a library that uses the hardware optimized CS pins -- This was the closest info I could find searching the forum.
 
Yes, you can. I may be corrected on this, but I'm not aware of any SPI libraries for Teensy that control the chip selects through the SPI peripheral. They all just assign GPIO pin(s) as chip selects, and manipulate those using digitalWrite() and digitalWriteFast().
 
Yes, you can use those pins normally, even when SPI or SPI1 is in use.

Indeed today use of hardware CS control is rare. I believe some experimental copies of ILI9341 tried to use it, but because LPSPI can't control 2 pins and because Teensy 4.x is so fast anyway, the benefit wasn't great like we got with Teensy 3.x. The Ornament and Crime synth module might be the only project really using hardware CS, due to code I recently contributed. But that's a pretty special case for its DAC chip, and even there the same SPI port which controls a black and white OLED display uses digitalWrite().

In the (likely distant) future my hope is we'll greatly extend the SPI library to allow much better use of the powerful SPI hardware in modern chips like on Teensy 4.x. Or maybe Arduino will do so and we'll follow their API, but my guess is they're probably not too interested.

But even in this hypothetical (far) future of more libraries using powerful SPI features, you can still use those pins for normal I/O if the SPI port isn't using them. And with Teensy 4.0 & 4.1, even if SPI is controlling a pin, you can take away that control and regain normal access by calling pinMode(). That even applies to MOSI, MISO, SCK. When a peripheral has control of a pin, you can take away its control and put it back into GPIO control by calling pinMode().
 
Back
Top