1.28" Round Display with SD Card on Nano BLE

Thread Starter

John A Bonilla

Joined Mar 11, 2017
77
Hi Everyone,

I am trying to use the SPI to work with two devices:
- 1.28" 240x240 Display
- SD Card Reader
I have been able to use both of them individually, however the example code does not provide any instruction on wiring the SD card, only the Display. If anyone can help me parse through this and figure out how to properly wire this up, I would greatly appreciate it!
 

Attachments

Irving

Joined Jan 30, 2016
2,422
OK this is a little tricky to work out because your SPI bus calls are all hidden away inside the GFX library, the FILE library and the BUS library (which I believe is a wrapper for the underlying SPI bus)

Basically you have to configure and wire the SPI devices to use the same pins for SCLK, MOSI and MISO, but different CS (chip select) pins (also called SS). So gfx.begin() and SD.begin() tell each library which pin to use to select the device but both will (should!) use the common underlying SPI bus pins. As far as I can tell, for the Nano the following pins are predefined/used:

Nano 33 BLE implements the SPI on digital pins 11, 12, and 13

* Arduino Nano, Micro and more: TFT_CS: 9, TFT_DC: 8, TFT_RST: 7, TFT_BL: 6

For the SD card it seems there isn't a specific for the Nano so the default SD.h settings are used:


#else
if (!SD.begin())
#endif
{
Serial.println(F("ERROR: File System Mount Failed!"));
gfx->println(F("ERROR: File System Mount Failed!"));
}
else ...


So in SD.h it defines the default SS pin for the SD card which on the Nano is pin 10.

So, in the configuration you have, both TFT and SD card should be wired to SPI on 11, 12, 13, the TFT CS to pin 9 and the SD card SS to pin 10.
 

Thread Starter

John A Bonilla

Joined Mar 11, 2017
77
OK this is a little tricky to work out because your SPI bus calls are all hidden away inside the GFX library, the FILE library and the BUS library (which I believe is a wrapper for the underlying SPI bus)

Basically you have to configure and wire the SPI devices to use the same pins for SCLK, MOSI and MISO, but different CS (chip select) pins (also called SS). So gfx.begin() and SD.begin() tell each library which pin to use to select the device but both will (should!) use the common underlying SPI bus pins. As far as I can tell, for the Nano the following pins are predefined/used:

Nano 33 BLE implements the SPI on digital pins 11, 12, and 13

* Arduino Nano, Micro and more: TFT_CS: 9, TFT_DC: 8, TFT_RST: 7, TFT_BL: 6

For the SD card it seems there isn't a specific for the Nano so the default SD.h settings are used:


#else
if (!SD.begin())
#endif
{
Serial.println(F("ERROR: File System Mount Failed!"));
gfx->println(F("ERROR: File System Mount Failed!"));
}
else ...


So in SD.h it defines the default SS pin for the SD card which on the Nano is pin 10.

So, in the configuration you have, both TFT and SD card should be wired to SPI on 11, 12, 13, the TFT CS to pin 9 and the SD card SS to pin 10.
Hi, thank you for the response! While I was able to get them to work one at a time, for some reason they refuse to work together. I have tried using the CS Pin for the SD Card as you had mentioned, but that did not work. I also tried setting my own pin in the SD.begin() function with no luck. I am at a loss right now if you have any other ideas it would be very helpful!
 

Irving

Joined Jan 30, 2016
2,422
The problem here is that the GFX library initialises the underlying SPI using a different library/configuration - I'm thinking the NRFXSPI() configuration is incompatible with the default SPI configuration set/required by the SPI.h/SD.h includes.. Try changing the databus library from NRFXSPI() to HWSPI() keeping only the first 2 parameters.. This seems to work on a Nano - in the sense I see what appears to be a valid device initialisation request for both devices (see below, though I dont have either device to hand). I don't have a Nano BLE 33 to try out the original code, though it compiles for a BLE but the original code won't compile, or fit, on a standard Nano!

Sorry I can't help further. Suggest you contact MoonOnOurNation who seems to be quite active on github for his input.

Yellow = CS for GFX, Purple = SS for SD, Blue = SCLK 8MHz for GFX, 1MHz for SD.
1637084375362.png
 
Top