Teensy 4.1 - Using the audio shield with other SPI devices

Status
Not open for further replies.
I have my audio shield connected to my Teensy 4.1 and it works. Now I want to be able to run multiple MCP3208 chips along side it, up to five of them if possible. I noticed that the shield already uses the first set of SPI pins. Is it possible to use the other CS pins and run other devices as slaves on the same SPI bus as the audio shield? I can use the SPI1 set of pins but there's only two CS1 pins for that. I'd like to be able to use the remaining two CS pins, and the two CS1 pins for a total of four SPI devices, along side the audio shield. Is it possible to use GPIO for chip selection? If that's the case then that makes this a lot easier.
 
You should be able to use the main SPI Object (pins 11-13) with other devices as well. It is only used for the built in SDCard(CS 10) and optional memory (CS 6),
Both of these CS pins have built in Pull-up resistors on the board, so if you don't connect anything to them on the Audio board, they simply won't do anything

I don't believe that any library for MCP3208 do anything special for chip selects, so my guess is any digital pin should work. On T4.1 of course you also have the option to use SPI1 which have easy to get to pin, or SPI2 which is not so easy to get to...
 
Thanks for the response. That sounds good. However I only see SPI and SPI1 pin groups on the pinout diagram. Just out of curiosity where are these SPI2 pins? In any case, I don't need super fast reading times for this as it's only for potentiometers, so I can probably get away with just using SPI1 and use as many pins as I need for selection. One more question: What's the difference between the designated CS pins and using GPIO? Why are the CS pins specifically marked if there's no real behavior difference? Is it just to enforce a common standard?
 
Last edited:
SPI2 pins are not as easy to get to on T4.1...
Here is an image of my own Excel page - with extended card like view, which I have posted several times.
T4.1-Cardlike.jpg

You will see that the SPI2 pins show up in two different places (sort of three but...).
First off they are on the SDCard area. I have played around before with an SDCard breakout, where for example I have run a small display using these pins.

The second place are the bottom memory chips area. There are pads for two chips, which have the identical signals on them except each one has their own chip select.
Note in this case Chip select is for a different type of SPI: FlexSPI (used by memory system...) and the LPSPI (what we think of as SPI)...

As for our mention of SPI CS pins. The majority of libraries do not make use of the hardware specifics of the CS pins, including the SPI library. Most sketches and libraries simply do something like digitalWrite(CS_PIN, LOW); <Do there spi stuff>; digitalWrite(CS_PIN, HIGH);...
So in these case makes no difference.

However there are some libraries, especially for T3.x that DO make use of the hardware CS pins. Example ILI9341_t3 library, which on a T3.x you can encode the state of up to 4 CS pins for each transfer by encoding this data when you use the PUSHR register to add stuff to the SPI queue. This for example allows us to encode the state of the DC (Data, Command) signal on the queue and as such the hardware takes care of switching the state of this signal at just the right time. Otherwise your code has to wait until it knows the last of the bits associated with the old state of this signal is, before it can change the state and then push the next data on the queue to be output. So these libraries can make much usage of the SPI speeds (i.e. less gaps of output).

Also if you have code that for example tries to use SPI as a slave device instead of being the master, than the hardware requires us to use a CS pin in CS mode that the system monitors to know when an SPI operation is happening...
 
Status
Not open for further replies.
Back
Top