Using 2.8" TFT (ID 1480) with other SPI devices

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Using 2.8" TFT (ID 1480) with other SPI devices

Post by earthres »

I'm using a Feather M0 Express and FeatherWing RTC+SD card for a data logging project. I would also like to display output on an ID 1480 TFT. But both these devices require using pin 10 for the CS pin, right? I assume the SD card CS pin can't be changed because it's "hard wired" into the module, but can the TFT CS pin be changed? The TFT documentation seems to indicate that pin 10 must be used with the M0 Express which, if true, means that I can't use the FeatherWing and TFT on the same system? True?

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: Using 2.8" TFT (ID 1480) with other SPI devices

Post by earthres »

Oops, of course this a 2.2" TFT and not 2.8"!

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: Using 2.8" TFT (ID 1480) with other SPI devices

Post by earthres »

To put my question another way, if I include

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

what values do I have to assign to the 6 parameters to use "software" SPI for a TFT display and keep hardware SPI for a data logging shield? I understand that software SPI is slower than hardware SPI, but that's an issue to be dealt with if it comes up for my application, which doesn't require fast graphics.

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Using 2.8" TFT (ID 1480) with other SPI devices

Post by adafruit_support_mike »

For software SPI, you can use any GPIO pins you want.

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: Using 2.8" TFT (ID 1480) with other SPI devices

Post by earthres »

OK, but I still have questions. I have a data logging shield on an UNO. If I change just the TFT DC and CS pins from 9,10 to 6,7 and leave the MOSI and CLK pins at 11,13, the TFT still works normally. A SD test sketch recognizes the SD card, but if I then try to run a sketch that writes data to the SD card, nothing will get written.

Does this mean I have to change the MOSI and CLK pins for the TFT too? Will writes to the SD card then work OK but the TFT will write very slowly? Would it be better to keep the "normal" pins for the TFT and use software SPI for the SD card, with reassigned pins, or will this just not work??

Yes, I know I could just try this, but I don't want to screw up any of the hardware!

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: Using 2.8" TFT (ID 1480) with other SPI devices

Post by earthres »

Well, I temporarily forgot the SD card pins on the data logging shield are "hard wired" and (presumably?) can't be changed. So, will also moving the TFT MOSI and SCK pins in addition to the DC and CS pins to let both the TFT and SD cards work on the same system? Do I have to reassign the TFT's MISO pin too, even if its not being used?

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Using 2.8" TFT (ID 1480) with other SPI devices

Post by adafruit_support_mike »

If the second display you want to use doesn't need MISO, you can ignore it.

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: Using 2.8" TFT (ID 1480) with other SPI devices

Post by earthres »

OK. I appreciate the help with this. Please correct me if anything I say here is wrong.

Unlike I2C devices, you can't use the same pins for more than one SPI device. So, yes, if you're using a TFT (or some other SPI device) in a system that also has a data logging shield, with its fixed hardware SPI pin assignments, you have to reassign the TFT pins to implement software SPI. If you're not accessing bitmap files from the SD card, only four pins need to be defined. Here's some code that shows how to do this. Compared to using hardware SPI pins, software SPI is pretty slow -- it may take two or three seconds to fill a large rectangle with color, for example -- but this wasn't critical for my application.

Code: Select all

#include <Adafruit_ILI9341.h> // TFT display
// pins for software SPI, slow but usable, other pins will also work
#define TFT_SCK 4
#define TFT_MOSI 5
#define TFT_DC 6
#define TFT_CS 7
// pins required for hardware SPI
//#define TFT_DC 9
//#define TFT_CS 10
//#define TFT_MOSI 11
//#define TFT_SCK 13 
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCK);

User avatar
michaelmeissner
 
Posts: 1819
Joined: Wed Aug 29, 2012 12:40 am

Re: Using 2.8" TFT (ID 1480) with other SPI devices

Post by michaelmeissner »

You can often times put multiple devices on the same SPI bus. You keep the 3 SPI pins (MISO, MOSI, and SCLK) and the power pins (ground and VIN) the same for all devices, but the CS, DC, reset, and other pins would be different.

However there are some gotchas:
  • Some device drivers have special optimizations for certain pins being CS or DC. For example, the Teensy 3.2/3.5/3.6 processors have some special pins and some of the Teensy specific drivers use them which can speed up the display. If you have such a driver, you may need to limit the CS and DC pins to be these values.
  • Sometimes you need to add pull-up or pull-down resistors for the CS pins to enable faster switching (a pull-up resistor is a resistor in parallel to the data pin that has a resistor between the data pin and 3.3v, and a pull-down would have the resistor in parallel connecting to the ground pin).
  • Some MISO pins on devices do not have proper tri-state capability.
  • You need to protect the bus with SPI.beginTransaction and SPI.endTransaction calls. If you are using asynchronous SPI calls using DMA, you would need to make sure all of the DMA calls are finished before doing the SPI.endTransaction.
  • For more information about the previous 3 points, go to: https://www.pjrc.com/better-spi-bus-design-in-3-steps/.
There are some microprocessors that have multiple SPI buses (i.e. different pins for MISO, MOSI, and SCLK). You would need to check the processor page to see if it has different SPI buses, and you would need to check the device driver pages to see what changes are needed to use these alternate SPI buses.

Typically, instead of using SPI, you would use SPI1 for the second SPI bus, SPI2 for the third, etc. But different drivers have different ways of specifying this in the constructor, and a few might not have any way to change the SPI bus being used.

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: Using 2.8" TFT (ID 1480) with other SPI devices

Post by earthres »

OK. I will certainly try that. Right now, the only Arduinos for which I would try this would be a UNO, Nano, etc., or a Feather M0 Express. Will the "gotchas" you describe apply to either of these board types?

User avatar
michaelmeissner
 
Posts: 1819
Joined: Wed Aug 29, 2012 12:40 am

Re: Using 2.8" TFT (ID 1480) with other SPI devices

Post by michaelmeissner »

The first one won't apply (special fast pins). The other 3 are general things if you are sharing several devices on a single SPI bus.

User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

Re: Using 2.8" TFT (ID 1480) with other SPI devices

Post by earthres »

OK. It's true. the SPI 2.2" TFT and the SD card on a data logging module WILL work together on the same system, with the CS and DC pins reassigned for the TFT display -- I arbitrarily chose 7 and 6 for these two pins, replacing the 10 and 9 that are hard-wired for the SD card on the data logging module. This doesn't appear to slow the graphics on the TFT display.

#define TFT_DC 6
#define TFT_CS 7
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”