CS on Teensy 3.2...more than 1?

Status
Not open for further replies.

nmarsaw

New member
I noticed there's multiple pins assigned as "CS" on the teensy 3.2. I'm guessing while there's one SPI bus, there's multiple CS in order to drive multiple slaves. Am I right?

If so, what is the best way to go about adding and additional CS in arduino code?

Thanks!
 
Yes, that's how SPI works. All the chips share MOSI, MISO, SCK. Each gets its own CS.

There are 2 ways to use CS pins.

The simplest way, used by most programs and libraries, is to simply use digitalWrite or digitalWriteFast. This has the advantage of allowing any digital pin (not limited to the 5 special ones) and it works with all Arduino compatible boards.

Those 5 pins can be controlled directly by the SPI port. But doing this requires very special code. In most cases the it offers little to no speed advantage over digitalWriteFast, but they are some special circumstances where the CS pin control allows for a massive speedup. The ILI9341_t3 library is a good example.


We print the 5 special pins on the card as a guideline. If you connect your CS signals to those pins, then either type of code will work.
 
Hard to say without knowing what you are trying to do.

That is, yes there are multiple SPI hardware CS pins on the Teensy 3.2...

That is the following pins can be Hardware chip select pins: 10, 2, 9, 6, 20, 23, 21, 22, 15

But in the majority of libraries it does not mater and you can use any digital IO pin for the CS pin. As most libraries simply do pinMode/digitalWrite to set/clear the CS pin...

However the T3.x board SPI hardware has the ability to encode how to change SPI hardware pins as part of their hardware registers, which can really speed things up. This includes libraries like: ili9341_t3 library.

There are some complications of using these hardware pins as they actually get encoded as a mask as part of the PUSHR instruction and some of these pins map to the same bit, so your program can only use one of them as hardware CS pin... The groupings are (10, 2), (9, 6), (20, 23), (21, 22), 15

The other way that hardware CS pin are used/needed is if you are trying to run SPI as a slave device. In which case you need to use a hardware CS pin and if I remember correctly it must be of the first grouping (10, 2).
 
Thanks guys, this answered my question. I was confused because for the pinout listed on the website all are labeled "CS", no numbers or identifiers, and because of that I wasn't sure how they were distributed.
 
Status
Not open for further replies.
Back
Top