Go Down

Topic: Arduino DUE SPI 7"tft and sd card (Read 729 times) previous topic - next topic

slobban

Hello guys!

I bought following screen http://www.buydisplay.com/default/7-inch-lcd-module-capacitive-touch-screen-panel-i2c-spi-serial.
I have configured the screen for SPI and after a bit of struggle I managed to get the screen to work by using AdaFruits library for the RA8875 chip. Now I would like to access the SD card slot built in on the screens PCB, but I just can't get that to work! I use SPI for communicating with the SD card slot and has connected the MISO, MOSI and SCLK to it, the same as the screen uses, the screen has SS at pin 10 and SD card slot uses pin 4. As what I understand this is the way to hook up SPI devices. The screen does work in this configuration but not the sd card. I have double checked the wiring, I'm using a fully functional SD card, I have measured the voltage to the SD SD card slot but all these things are fine.  So I wonder if you guys have any suggestions or experiences with similar stuff? Also is this the way to wire up SPI devices, and does the native arduino SD library support DUE?

Thanks in advance!

WesBrooks

#1
Jun 20, 2014, 01:41 pm Last Edit: Jun 20, 2014, 03:17 pm by WesBrooks Reason: 1
Have you got anywhere with this? I think I'm suffering a similar problem with the little Arduino TFT/SD shield on my Due.

I can make a program run fine that just uses the screen, or I can make something that runs fine just using the SD card. Put both together and it all goes to pot.

I've found this post which may be something to do with it but yet to digest the information and figure it out for myself!

http://forums.adafruit.com/viewtopic.php?f=47&t=37775

I've tried forcing the chip select pins before calling the TFT and SD functions and this didn't help. Also tried using the SPCR technique in the above post and SPCR is not defined.

WesBrooks

Think I maybe making progress...

#include <TFT.h>
...on my machine calls the header for \Arduino\libraries\TFT\src\TFT.cpp
...which calls the header for \Arduino\libraries\TFT\src\utility\Adafruit_ST7735.cpp

This link discusses the SPI on Due
http://arduino.cc/en/Reference/DueExtendedSPI
...and explains that the SPI library can look after chip select (probably why my attempt at manual chip select failed) and once assigned the general IO calls on the pin will not work. It says when using the SPI library directly you call SPI.begin(chip_select_pin_number) and it will deal with it. The Adafruit library only has a call to SPI.begin() without specifying a pin.

I've added two SPI.begin(cs_pin) calls, one for the TFT chip select pin and the other for the SD before I initialise the TFT and SD in the setup part of my scetch and it seems to be behaving better, although not faultlessly yet...

WesBrooks

Adding the SPI.begin(cs_pin) fixed it for me.

So from:

########## CODE ###########
const int tft_cs_pin = 53;
const int tft_dc_pin   = 51;
const int tft_rst_pin  = 50;
const int tft_sd_pin = 52;
unsigned int sd_ok = LOW;

TFT TFTscreen = TFT(tft_cs_pin, tft_dc_pin, tft_rst_pin);

void setup() {
 if (SD.begin(tft_sd_pin)) sd_ok = HIGH;
 else sd_ok = false;
 TFTscreen.begin();
 [code snipped!]
}

###################

...to:

########## CODE ###########

const int tft_cs_pin = 53;
const int tft_dc_pin   = 51;
const int tft_rst_pin  = 50;
const int tft_sd_pin = 52;
unsigned int sd_ok = LOW;

TFT TFTscreen = TFT(tft_cs_pin, tft_dc_pin, tft_rst_pin);

void setup() {
 SPI.begin(tft_sd_pin);
 SPI.begin(tft_cs_pin);
 if (SD.begin(tft_sd_pin)) sd_ok = HIGH;
 else sd_ok = false;
 TFTscreen.begin();
 [more code!]
}

#########################

Go Up