SPI - Using SD card and touch screen on TFT Display

Hi,

i’m using Arduino DUE with this display: http://www.buydisplay.com/default/7-inch-arduino-touch-screen-shield-ssd1963-library-for-mega-due

The libraries provided by the seller are an old version of UTFT and UTouch, which uses Software SPI. There isn’t a library to load pictures from SD, and i decided to use the original UTFT_SdRaw. This library uses hardware SPI, so i soldered the jumpers on the screen to use it, and i modified the pin numbers inside the two libraries.

This is the screen schematics: http://www.buydisplay.com/arduino/ER-AS-SSD1963—Arduino-Schematic-Diagram.PDF

Using hardware SPI and thoose libraries, i can use the touch screen OR the SD card succesfully. The problem appears when i try to use them toegether: the SD works, but the touchscreen stops working, the functions getX and getY return always -1.

This is the sketch, i used an example adding the SD card initialization:

// PLEASE READ: i soldered the jumper on the display to use HARDWARE SPI.
// The touchscreen and the sd card work separately, but not in the same sketch

#include <UTFT.h>
#include <UTouch.h>
#include <SdFat.h>

#define SD_CHIP_SELECT  47
#define TOUCH_CHIP_SELECT  42
#define LCD_CHIP_SELECT  40

// Istanze LCD e Touch
UTFT LCD(SSD1963_800480, 38, 39, LCD_CHIP_SELECT, 41);
UTouch  Touch(76, TOUCH_CHIP_SELECT, 75, 74, 46);

SdFat sd;

extern uint8_t SmallFont[];

void setup() {

  Serial.begin(9600);

  // -------------------LCD--------------------------
  LCD.InitLCD();
  pinMode(8, OUTPUT);    //Accendo la
  digitalWrite(8, HIGH); //Retroilluminazione
  LCD.clrScr();          //Clear LCD
  LCD.setFont(SmallFont);//Set font
  // ---------------------------------------------------

  // -------------------SD----------------------------                                            // If i use sd.begin, the touch screen
  bool mysd = 0;                                                                             // stops working
  while (!mysd) {
    if (!sd.begin(SD_CHIP_SELECT, SPI_HALF_SPEED)) {
      Serial.println(F("SD failed."));
      Serial.println(F("Retry...."));
    } else {
      mysd = 1;
      Serial.println(F("SD initialized."));
    }
  }
  // ----------------------------------------------------

  // -------------------Touch------------------------
  Touch.InitTouch();
  Touch.setPrecision(PREC_MEDIUM);
  // ----------------------------------------------------

}

void loop() {

  long x, y;
  LCD.setColor(255, 255, 255);
  LCD.print("* www.buydiplay.com  Resistive touchscreen test.Please touch the screen!", CENTER, 1);

  while (Touch.dataAvailable() == true) {
    Touch.read();
    x = Touch.getX();
    y = Touch.getY();
    LCD.drawPixel (x, y);
    Serial.print(x);
    Serial.print("\t");
    Serial.println(y);
  }

}

I think it’s a SPI problem, i tried to enable/disable the CS pins with digitalWrite (SPI active low), but it didn’t work.
Does anybody used this display? Any ideas?

Thanks

ZeroG

Are you aware you can configure different configurations for the Due SPI bus?

That being said, there are some SD cards that are not capable of sharing the SPI bus due to the inability to release the MISO line. The manufacturer of these cards is Catalex. The older cards suffer from this malady. The newer cards are not.

Hi SurferTim,

Are you aware you can configure different configurations for the Due SPI bus?

Are you talking about this? Arduino - DueExtendedSPI
I took a look inside the libraries and i realized that all the SPI parameters are the same for SD and touch screen (except for chip select pins of course). The speed is the same, too.
I’m using a SanDisk Ultra 8 GB (SD HC).

I should have been more specific. It is the SD card module that has the problem. Here is a link to the module and the schematic. Note on the schematic, the MISO buffer Output Enable is connected permanently to GND. That keeps the MISO line active all the time. The newest of these modules (just released recently) have the Output Enable connected to the CS. http://blogsmayan.blogspot.com/p/interfacing-sd-card.html

Hi,

SurferTim: It is the SD card module that has the problem. Here is a link to the module and the schematic. Note on the schematic, the MISO buffer Output Enable is connected permanently to GND. That keeps the MISO line active all the time.

I studied the shield schematics, and i realized that the DOUT (SDO) pin of SD card is connected to all the other SDO pins (touchscreen, LCD, font chip etc), and they're all connected to 3.3V through a resistor (pullup) and to the MISO of Arduino DUE. SDO isn't connected to the level shifter, so there isn't an output enable. Do you think there's something else wrong in the schematics?

http://www.buydisplay.com/arduino/ER-AS-SSD1963%E2%80%94Arduino-Schematic-Diagram.PDF