SPI Chip Selects (Teensy 3.1 vs 3.2)

Status
Not open for further replies.

benscammell

Well-known member
Does anyone (Paul) know why the SPI CS on D2, D6, D22, D23 have disappeared in the move from 3.1 to 3.2.

I figured they would be the same as the uC is the same.

Thanks, Ben
 
Sorry Ben can you be more specific. Maybe some examples.
The processors and pinouts are exactly the same in both models. The Libraries are also exactly the same for both
 
Image from https://www.pjrc.com/teensy/teensy31.html

Screen Shot 2016-02-10 at 21.10.32.jpg

See on the 3.1, D2, D6, D22 & D23 are designated as SPI chip select (slave select)... but on the 3.2 they are not.
 
there might be a specific reason why it was noted as CS on these diagrams, but I find that most SPI libraries simply call digitalWrite() or digitalWriteFast() on the CS pin, making pretty much any digital output pin suitable for CS. I use pins 0, 2, 3 and 6 simultaneously to control an SD card, an OLED module, a 16 pin DAC and a GPIO expander chip.

Are you running into any problems with CS pins?
 
Last edited:
Before I answer this, please understand most SPI-based programs and libraries create their chip select signals using normal digital outputs. For those, you can use any digital pin. For example, the SD library uses normal digital output. You can use SD.begin(4) to use pin 4, and it works fine even though pin 4 isn't labeled as CS on the card. This is true for all SPI-based libraries designed for regular Arduino boards which don't have special Teensy-specific optimizations.

Those pins labeled CS have special hardware which can automatically create the CS signal. But it doesn't happen automatically unless special Teensy-specific code enables it, so it's only sort-of automatic. You'd think automatic CS signals would be faster, and indeed in some very special cases they are, but for normal libraries the extra overhead to enable the automatic signal works out to be about the same as just controlling a digital pin through a pointer (the common speedup technique used in many Arduino libs). Hardware CS might even be slightly slower in some cases, depending on arcane details of how the compiler generates code with constants and how the flash memory cache works inside the chip.

Only a few very special libraries actually use those special CS pins. The optimized display libs, ILI9341_t3, ST7735 and TFT_ILI9163C are the main ones. So does Ethernet. Pretty much everything else uses the pins as normal digital outputs.

Does anyone (Paul) know why the SPI CS on D2, D6, D22, D23 have disappeared in the move from 3.1 to 3.2.

This was done to simplify the pinout card.

The main problem is there really are only 5 of those special signals inside the chip. Four of the 5 can route to 2 different pins.

CS on pin 10 is the same as CS on pin 2.

CS on pin 9 is the same as CS on pin 6.

CS on pin 20 is the same as CS on pin 23.

CS on pin 21 is the same as CS on pin 22.

The original Teensy 3.0 card has these labeled CS0, CS1, CS2, CS3, CS4. The numbers confused a lot of people, since the convention Arduino and other uses, which we follow for everything else, uses the number to mean which port is belongs to. So this implies 5 different SPI ports.

The early Teensy 3.1 cards dropped the numbers. That was actually a big improvement, but as libraries like ST7735 were developed, this became a problem. If you use Ethernet which takes over pin 10 for CS, then you must not use pin 2 for either of the control signals your display needs.

I considered many alternate naming styles. All were complex, especially with Teensy-LC and anticipated future Teensy boards having more than one SPI port. Already this stuff is pretty confusing, so the decision was made to simply drop the labels from pins 2, 6, 22 and 23. That's not a perfect solution either, since those 4 pins do have the ability to output 4 of the 5 special signals. Ultimately, I felt a simpler, easier to understand card was best for the vast majority of people.
 
Not getting ST7735 to work with Teensy 3.1 using Teensy-specific Adafruit_ST7735 lib.

I have an UNO, using an Adafruit_GFX font to write numbers to the ST7735 display, but the refresh rate is too slow. I also have a Teensy 3.1 that I connected to the display, using the pins exactly as outlined in
https://www.pjrc.com/teensy/td_libs_ST7735.html

I'm new at this, so I'm trying to follow the instructions as exactly as possible. I deleted the Adafruit_ST7735 library and installed Teensy specific Adafruit_ST7735 library in its place. I then copied the text of the sketch from the above URL and pasted into a blank sketch in the Arduino IDE v1.67.

It won't compile, Exit Status 1. I have copied the entire error message and pasted it below. From what little I know, shouldn't the libraries be included before SPI pins are declared? I tried that change, but that didn't help. I don't have the display with a joystick but hoped that code wouldn't hurt if joystick was not present. Would appreciate any assistance.
Thanks.

Arduino: 1.6.7 (Windows 8.1), TD: 1.27, Board: "Teensy 3.2 / 3.1, Serial, 72 MHz, US English"

C:\Users\BishtonMP\Documents\Arduino\G_Test_Teensy\G_Test_Teensy.ino: In function 'void setup()':
C:\Users\BishtonMP\Documents\Arduino\G_Test_Teensy\G_Test_Teensy.ino:100:397: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST7735_WHITE);
^
C:\Users\BishtonMP\Documents\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp: In member function 'void Adafruit_ST7735::writecommand(uint8_t)':
C:\Users\BishtonMP\Documents\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:201:3: error: 'SPI0' was not declared in this scope
SPI0.PUSHR = c | (pcs_command << 16) | SPI_PUSHR_CTAS(0);
^
C:\Users\BishtonMP\Documents\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp: In member function 'void Adafruit_ST7735::writedata(uint8_t)':
C:\Users\BishtonMP\Documents\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:214:3: error: 'SPI0' was not declared in this scope
SPI0.PUSHR = c | (pcs_data << 16) | SPI_PUSHR_CTAS(0);
^
C:\Users\BishtonMP\Documents\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp: In member function 'void Adafruit_ST7735::writedata16(uint16_t)':
C:\Users\BishtonMP\Documents\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:227:3: error: 'SPI0' was not declared in this scope
SPI0.PUSHR = d | (pcs_data << 16) | SPI_PUSHR_CTAS(1);
^
C:\Users\BishtonMP\Documents\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp: In member function 'void Adafruit_ST7735::setBitrate(uint32_t)':
C:\Users\BishtonMP\Documents\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:285:2: error: 'SPI0' was not declared in this scope
SPI0.MCR = SPI_MCR_MDIS | SPI_MCR_HALT;
^
C:\Users\BishtonMP\Documents\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp: In member function 'void Adafruit_ST7735::commonInit(const uint8_t*)':
C:\Users\BishtonMP\Documents\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:549:3: error: 'SPI0' was not declared in this scope
SPI0.MCR = SPI_MCR_MDIS | SPI_MCR_HALT;
^
exit status 1
Error compiling.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
 
p.s. I also noted that the Teensy specific Adafruit_ST7735 library does not have any fonts in it. I need cleaner fonts than included in the system fonts. Can I copy the fonts library from the Adafruit library to the same location in the Teensy library?
 
Thanks for the quick reply. I replaced SPI0 with KINETISK_SPI0 in Adafruit_7735.cpp. The program compiled, but I only got a white background. The serial monitor displayed program progress, so I know it's running. I'll double check my pin connections tomorrow.

In the meantime, shouldn't this be corrected in the Teensy-specific Adafruit_7735 library?
And also, does anyone know if the 7735 fonts work with the Teensy mods?
 
Suggestions for getting the Teensy-specific Adafruit_ST7735 to work?

I checked all of the pins and they are correct. The screen works using the following pins connected to an UNO or a Teensy if I use the Adafruit_7735 library and graphicstest sketch. It does not work when I use the Teensy-specific Adafruit_7735 library and the graphicstest sketch. Even after I replaced all references to SPI0 with KENETIC_SPI0 in the Teensy-specific Adafruit_ST7735.cpp as suggested above. I have listed the pinouts below. I have two questions.
- Any suggestions for how I can get this to work?
- Does anyone know whether the fonts in the Adafruit_GFX library will work with the Teensy-specific Adafruit_ST7735 library?
Thanks, Michael

Teensy_Pinouts.png
 
Looks like you've got an old copy of Adafruit_ST7735. It's certainly not the copy that comes with Teensyduino 1.27 or 1.28-beta1.

Maybe Arduino is printing messages about duplicate libraries?

First, I'd suggest installing 1.28-beta1. In the libraries install step, make sure you're letting the installer give you the known-good copy. Then pay close attention to those messages about duplicate libraries. Delete or move the bad copy, so Arduino uses the good one that comes with Teensyduino.

- Does anyone know whether the fonts in the Adafruit_GFX library will work with the Teensy-specific Adafruit_ST7735 library?

They should. If not, please post a bug report. Make absolutely certain you're really using the copies from 1.28-beta1, and make sure your message has everything needed to exactly recreate the problem. Don't leave anything, like the font file or sketch code to guesswork! Please, make sure everything in your message can be copied to Arduino and run to exactly recreate the problem.
 
Thanks, Paul, for taking the time and concern to respond. I really appreciate it. I like the size and power of the Teensy 3.1. I also have an UNO, ESP12E (with WiFi from DoIT.am) and Adafruit Feather Huzzay (with WiFi, which I can't get to work with the display, and Adafruit can't fix).

You must stay very busy reading/skimming a lot of forum posts. Though I have a reasonable amount of programming experience, I am new at Arduino stuff, so I'm going to ask you to go a little slower and simpler in your responses, and consider some comments from me, please.

- "Looks like you've got an old copy of Adafruit_ST7735"
I downloaded the Teensy-specific Adafruit_ST7735 library from your URL: https://www.pjrc.com/teensy/td_libs_ST7735.html If the download URL on that page had been up to date, I would have downloaded the latest stable Teensy-specific Adafruit_ST7735 library.

- "Maybe Arduino is printing messages about duplicate libraries?"
I submitted a complete error message with a post above your response. My sketch dump did not mention duplicate libraries.

- "First, I'd suggest installing 1.28-beta1..."
As I mentioned earlier, I have four microcontrollers and may explore more. I did not install any libraries when I installed the Teensy Loader because, when I looked at the library list, I thought I already had installed the libraries (like the Adafruit_ST7735) that I needed. This experience raises the following questions and concerns
- Is your Teensy loader URL (http://pjrc.com/teensy/loader.html) out of date, misleading, or incomplete, and should be updated?
- - Out of date, because it it doesn't include the latest revisions in the list.
- - Misleading to a new visitor, because it mentions Teensy 3.0 only, even though you are shipping a variety of microcontrollers, and this loader may be the generic loader for all of them. Can't tell.
- - Incomplete because I can't find any information up front that states which libraries are Teensy-specific and should be selected at install.
- If all of the libraries in the list are Teensy-specific, that is a problem. I'm trying to build a marketable product. If the developer (me) wants to simultaneously evaluate and compare more than one micro, side by side, as I am doing from one laptop, that creates a problem of swapping out libraries...

I have already moved out the Adafruit_ST7735 library. Now that I have the TeensyDuino loader installed, it isn't clear to me how I find and install the Teensy-specific Adafruit_ST7735 library. I can't find "Hardware/Tools."

I promise to provide complete error dumps.

Please consider the comments in the positive way it is intended.
Many thanks, Michael
 
Status
Not open for further replies.
Back
Top