Custom pins numbers for SD card's SPI bus: how to setup CS, MOSI, SCK, MISO?

Good day! my 34-pin ILI9341 screen has XPT2046 touch controller and SD card slot. It's SPI bus pins - MOSI, MISO, SCK - are shared between XPT2046 and SD, and sadly they conflict with each other: XPT2046 touch freezes if I init a SD card :frowning:

At the moment, the only solution seems to be a hardware: just connect a separate SD card board to the unused Arduino data pins and set up its' own 2nd SPI separately! This way XPT2046 and a dedicated SD could use the different SPI at the same time.

Please tell, how to setup the custom CS, MOSI, SCK, MISO pins for a dedicated SPI of SD card? (while preserving the original SPI for touch) All the examples I could find online, only have a custom CS pin - but can't find any MOSI/SCK/MISO settings anywhere

Which Arduino board are you using?

pert:
Which Arduino board are you using?

Arduino Mega2560 together with this ILI9341 screen and 34-pin shield; also, SD card dedicated board.

Your 34-pin header from another thread shows XPT2046, SD and Font chip all on the same SPI bus.
The photo shows that the Font chip U3 is unmounted
Everything will be working at 3.3V

Does your Adapter Shield have anything printed on the pcb? i.e. to identify the header pins.

I suspect that the SPI pins have either been routed to digital 2-7 or to 50-53.
I would be 100% confident that the TFT is wired to 22-37 for the data bus. And 38-41 for the control pins.

If you have a DMM you can trace to and from the buffer chips.

David.

david_prentice:
Does your Adapter Shield have anything printed on the pcb? i.e. to identify the header pins.

Nothing printed, but it may be possible to identify the pins with a multimeter - will try to get one.

david_prentice:
I suspect that the SPI pins have either been routed to digital 2-7 or to 50-53.
I would be 100% confident that the TFT is wired to 22-37 for the data bus. And 38-41 for the control pins.

Seeing that " #define SDssPin 53 // SD card CS pin " has worked for SD card init at Rudi_i LEDStick project I've tested (if a touch is disabled), yes this Adapter Shield seems to be using 50-53 pins for a hardware SPI.

After I've modified SD library to properly use a MEGA_SOFT_SPI software SPI for 10,11,12,13 pins - following the instructions at MEGA_SOFT_SPI set as 1 leads to failure in compiling (SD-library, IDE 1.6.x) · Issue #3556 · arduino/Arduino · GitHub - now I could successfully use both XPT2046 touch and SD card at the same time! :slight_smile: However, this is possible only because now they are separated: XPT2046 touch uses a hardware SPI while SD card uses a software SPI at the totally different set of pins: 10-13.

@david_prentice, thank you very much for your kind help! :wink: Maybe a bit later - when I'll get the necessary tools like an oscilloscope - I could investigate why there's a conflict between a touch and onboard SD. Meanwhile I'm attaching two archives: library-1.8.11-modded with a modded SD and URTouch libraries (touch mirror fix), and LEDStick_TFT_v1.2 - this example from Rudi_i was quite convenient to use as a test project and I've even improved it slightly.

Anyone could copy these modded libraries to their Arduino dir, just make sure to change your software SPI pins at your ./SD/src/utility/Sd2Card.h file, lines 97-107, like I had to do because accidentally switched MISO with SCK while soldering. The current settings:

#else // SOFTWARE_SPI
// define software SPI pins so Mega can use unmodified GPS Shield
/** SPI chip select pin /
uint8_t const SD_CHIP_SELECT_PIN = 10;
/
* SPI Master Out Slave In pin /
uint8_t const SPI_MOSI_PIN = 11;
/
* SPI Master In Slave Out pin /
uint8_t const SPI_MISO_PIN = 13; // 12;
/
* SPI Clock pin */
uint8_t const SPI_SCK_PIN = 12; // 13;
#endif // SOFTWARE_SPI

LEDStick_TFT_v1.2.zip (4.7 KB)

libraries-1.8.11-modded.zip (486 KB)

1 Like