SPI Pin questions

Status
Not open for further replies.
Hello,

I am a novice and I apologize if my questions are trivial. I have Teensy 3.2 and I am trying to connect it with SPI to a
Adafruit 1.44" Color TFT LCD Display with MicroSD Card breakout(ST7735R) for display. (not currently interested in using the SD card)
https://www.adafruit.com/product/2088

I am looking at this web site for Pin connections and examples to wire it up.
https://www.pjrc.com/store/display_ili9341_touch.html

Regarding SPI terminology, I think this is true: DOUT is the same thing as MOSI ? and on the Adafruit TFT, it is the SI pin? :D

The Adafruit TFT has a RST pin. Which pin on the Teensy 3.2 would that correspond to ?
On the PRJC web link above, it has RESET going to +3.3V (next to pin 23) is that correct?
and if so, what is the pin number would I use for it? the adafruit example "graphicstest" says use "-1" for the pin?

I see "reset" on the bottom of the Teensy 3.2 but I'm not sure how to access and use that using a breadboard? is that the correct reset to use?
and if so, any practical suggestions on how to wire it up? If needed, I guess I could solder a wire lead to it but I'd like confirmation it is needed before doing that.

I currently have things wired like this:

Code:
TFT     Teensy 3.2 
Display     

Vin    Vin
3v3
Gnd    GND
SCK     14
SO
SI       7
TCS      9
RST     ??
D/C     20
CCS
Lite
 
Lets see if I can clear it up. In the Teensy 3.2 time frame Paul used DOUT/DIN/SCK compared to MOSI/MISO/SCK used in later processors.

By default, on Teensy LC, 3.2, 3.5, 3.6, and 4.0:
  • Pin 11 is MOSI or DOUT (this is used to send data to the device);
  • Pin 12 is MISO or DIN (this is used to read data for the device -- if you don't use the SD card, you don't need this);
  • Pin 13 is SCK (this is used a clock to tell the device the next bit is ready).

However, the 3.2, 3.5, 3.6 have a set of alternate pins. If you use these alternate pins, you have to change the code to tell the Teensy library to use these alternate pins. One primary reason for using these alternate pins is the digital audio output (I2S) used by the audio shield must use fixed pins that overlap with the standard SPI pins. So if you mount the audio shield, you need to use these pins instead of the standard ones. These alternate pins are:
  • Pin 7 is the alternate pin for MOSI or DOUT;
  • Pin 8 is the alternate pin for MISO or DIN (you don't have to change this pin since it doesn't conflict with I2S);
  • Pin 14/A0 is the alternate pin for SCK.

Now for the Teensy 4.0, Paul moved the I2S pins, so they don't conflict with the standard SPI pins. This means you need a different audio shield for the Teensy 4.0 than the Teensy 3.2, 3.5, or 3.6. The Teensy 4.0 does not have alternate pins for SPI.

Now those are the standard SPI pins. SPI is a shared bus system, where all devices on the bus share the 3 control pins (MISO, MOSI, and SCLK) and the 2 power pins (3.3v/VIN and ground). Each device has a unique CS or SS pin that when the pin is set LOW, it means the device is listening for the commands. If the CS/SS pin is high, it means the device is ignoring commands sent out (and possibly some other device is using the SPI bus).

A lot of SPI devices have additional pins, such as D/C (DC) and Reset.

The D/C pin is used to speed up the SPI protocol, in that it tells the device whether commands are being sent or data (otherwise, the Teensy would have to send some command to switch the state).

The reset pin is used to reset the device. It can be any digital pin. You just have to pick one that isn't being used by other devices on your system.

Some devices like your display might have other pins as well.
  • If the device has a SD card, there is a separate pin to control the SD card;
  • If the device is a TFT lcd (like your display), there might be a pin to control the backlight on the display. You can hook this up to a PWM pin and use analogWrite write a series of LOW/HIGH pulses that turns the backlight on/off at a rate that the human eye thinks it is being dimmed.

Now, some devices have a Teensy specific library that speeds up the device (such as ST7735_t3 in your case). The standard Adafruit library is implemented in a generic fashion, but the *_t3 libraries are specifically optimized for the Teensy. To use the optimization on the Teensy 3.2, 3.5, and 3.6, you need to use a restricted set of pins for both the CS/SS and D/C pins. Note, you can't use some pin combinations, of pins (such as 2 and 10):
  • Pin 2 or pin 10;
  • Pin 6 or pin 9;
  • Pin 15/A1;
  • Pin 20/A6 or pin 23/A9;
  • Pin 21/A7 or pin 22/A8.

The Teensy 4.0 does not have the special pins like the Teensy 3.2, 3.5, or 3.6 does (other than the standard pin 10).

Finally, there is the question of power. Some displays are power hungry and really need 5v of power, while others can use 3.3v or 5v. Note, if you choose 3.3v, the display must not use so much power that it exceeds the voltage that the Teensy 3.2's voltage regulator provides. If you use 5v power (VIN on Teensy), and the device provides input, you may need to verify that the input from the device is 3.3v (true for most devices).

So assuming you don't have the audio shield, your pinout should be:
  • Display VIN: -> Teensy 3.3v or VIN;
  • Display 3.3v: -> not connected (the display has its own voltage regulator, and this provides 3.3v from the display VIN if you needed a 3.3v source);
  • Display GND: -> Connect it to the Teensy ground. On the 3.2, you want to use grounds connected to the ground pin next to pin 0, and not the analog ground pin next to the 3.3v pin;
  • Display SCK: -> Connect it to Teensy pin 13;
  • Display SO/MISO: -> Connect it to Teensy pin 12 if you use the SD card;
  • Display SI/MOSI: -> Connect it to Teensy pin 11;
  • Display TFT_CS: -> Connect it to the pin you are using for the display CS pin, such as pin 10;
  • Display RST/Reset: -> Connect to any digital pin, such as pin 8;
  • Display D/C: -> Connect it to the pin for D/C communication, such as pin 9;
  • Display Card CS/CCS: -> Connect this to a pin to use the SD card reader;
  • Display Lite: If you connect it, connect it to a pin that supports PWM such as pin 6.

Particularly if you are using multiple devices on a SPI bus, you may need to follow the suggestions in this article:

In particular, when I run a program that displays as fast as possible (uncanny eyes), I needed to add the pull-up resistors for the CS and D/C pins to run the displays at really fast speed.
 
awesome! thank you everyone! the example program is running nicely. its is now wired correctly.

I'm not using an audio shield. and I dont think I'll be daisy chaining in additional SPI devices....

After I understand coding for this better, I want like to implement I2C for a bunch of things. But one step at a time.

question: On the Teensy 3.2 "Welcome to Teensy 3.2" card, the default pins for SPI are solid black lettering and a gray font lettering.
Is the dark black for considered a primary SPI connection? and the grayed font set in case one would want additional SPI bus?


And yes, I stumbled upon the "uncanny eyes" project. :D It convinced me to try this display.
I wanted something small in size to fit in a 1U rack space and this one just fits.
and I should print out and hang a copy of the "SPI Data in/out naming clarity" info for future reference.

thank you everyone!
 
awesome! thank you everyone! the example program is running nicely. its is now wired correctly.

I'm not using an audio shield. and I dont think I'll be daisy chaining in additional SPI devices....

After I understand coding for this better, I want like to implement I2C for a bunch of things. But one step at a time.
Note, I2C devices on the Teensy may require pull-up resistors. If any of your I2C devices have pull-up resistors, you don't need to add others. If none of them have pull-up resistors, you will need to add them. You wire one 2.2K resistor between SDA & 3.3v, and another 2.2K resistor between SCL and 3.3v. This resistor is in parallel to the pins for the I2C devices. If you have complex I2C devices, you may need other values, but 2.2K is a good enough value for a lot of 3.3v systems like the Teensy.

question: On the Teensy 3.2 "Welcome to Teensy 3.2" card, the default pins for SPI are solid black lettering and a gray font lettering.
Is the dark black for considered a primary SPI connection? and the grayed font set in case one would want additional SPI bus?
Yes, the convention is stuff in the greyed out font is an alternate pin.

And yes, I stumbled upon the "uncanny eyes" project. :D It convinced me to try this display.
I wanted something small in size to fit in a 1U rack space and this one just fits.
and I should print out and hang a copy of the "SPI Data in/out naming clarity" info for future reference.

thank you everyone!

Evil cackle :) (I introduced several of the Teensy 4.0 testers to uncanny eyes).
 
Last edited:
Note, I2C devices on the Teensy may require pull-up resistors. If any of your I2C devices have pull-up resistors, you don't need to add others. If none of them have pull-up resistors, you will need to add them. You wire one 2.2K resistor between SDA & 3.3v, and another 2.2K resistor between SCL and 3.3v. This resistor is in parallel to the pins for the I2C devices. If you have complex I2C devices, you may need other values, but 2.2K is a good enough value for a lot of 3.3v systems like the Teensy.

I'm thinking of starting my I2C journey with an EEPROM and follow the examples on pjrc web page. and then graduate to using an MCP23017 to support several encoders and switches. I can see using several MCP23017 on different addresses to encompass all the switches and encoders id like to have inputting in this experiment.

thanks for the pointers, I'll be sure to stock up on some resistors when I order the EEPROM to just have on hand. I understand the MCP23017 has internal pull up resistors?
 
I'm thinking of starting my I2C journey with an EEPROM and follow the examples on pjrc web page. and then graduate to using an MCP23017 to support several encoders and switches. I can see using several MCP23017 on different addresses to encompass all the switches and encoders id like to have inputting in this experiment.

thanks for the pointers, I'll be sure to stock up on some resistors when I order the EEPROM to just have on hand. I understand the MCP23017 has internal pull up resistors?

If you buy the raw MCP23017 chips, probably not. If you buy them packaged up with a PCB, perhaps they will include the pull-up resistors, and perhaps not. If they include pull-up resistors, it likely will be 4.7k resistors to be friendly to 5v devices like the Arduino Uno.

Me, I tend to just add the resistors every time I lay out a Teensy onto a prototype board even if I have no immediate plans for doing I2C. Now, having too much resistance can mean you won't be able to use I2C at the highest speed, but for the stuff I do, it doesn't matter. If you have a complex I2C bus, you might need to adjust the resistors, and there are various calculators out there for those cases.
 
Status
Not open for further replies.
Back
Top