Go Down

Topic: using sd card on 3.5" TFT LCD shield with due (Read 1 time) previous topic - next topic

shyam_limaye

I recently purchased a 3.5" TFT LCD shield (Red PCB) meant for Mega. The seller claimed that it works with due. Well, the display works OK if we initialize as
UTFT myGLCD(CTE32HR,38,39,40,41); or UTFT myGLCD(ILI9481,38,39,40,41);
However the SD card does not work because the SPI pins of Mega and due are different. In case of Mega, pins 50,51,52 are connected to SPI header and pin 53 is used as SS. In case of Due, SPI header is has separate port pins.
We can make it work if we use software SPI and use the same pins as Mega. The file Sd2card.h in William Greiman's SD library (utilities folder) does indeed provide a way to use software SPI. However the library is written for Mega. We need some #defines to make it compatible with due.

We can modify the file as follows.
// Shyam Limaye: added following lines

//#define USE_SPI_LIB
#define SOFTWARE_SPI
#define cli noInterrupts
#define sei interrupts
#define fastDigitalWrite digitalWrite
#define fastDigitalRead digitalRead
#define SPI2X 1
#define SPR1 1
#define SPR0 1

The pin definitions are added as follows.

// Shyam Limaye: added following lines

;
uint8_t const SD_CHIP_SELECT_PIN = 53;//10;
/** SPI Master Out Slave In pin */
uint8_t const SPI_MOSI_PIN = 51;//11;
/** SPI Master In Slave Out pin */
uint8_t const SPI_MISO_PIN = 50;//12;
/** SPI Clock pin */
uint8_t const SPI_SCK_PIN = 52;//13;
#endif  // SOFTWARE_SPI

 
We also need to comment out function setSckRate in sd2card.cpp.

The modified files sd2card.cpp and sd2card.h are enclosed here. To use these files, copy the SD folder to libraries folder in your sketch folder(ducuments/Arduino) and replace the above files in utilities folder. In the application sketch, replace #include <SD.h> with #include "SD.h". Use pin 53 for chip select. Example sketches are also enclosed.
Shyam Limaye

Go Up