Hi,
I have a ST7735 TFT with an SD card reader connected to an Arduino Nano on the same SPI bus.
But even thought I use two Chip Select pins to avoid conflicts, I cannot get both devices to function at the same time and don’t understand, why.
When I initialize the display first and then call sd.begin(…), the display goes blank (white backlight). Before that, the display works fine, and after having the SD initialized, this one works too, but not the display anymore.
Libraries used (both up to date):
Minimal code example that reproduces the bug:
#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SdFat.h>
#include <sdios.h>
#include <SPI.h>
// Pins
#define DISPLAY_CS 10
#define DISPLAY_DC 8
#define SD_CS 4
Adafruit_ST7735 _tft{DISPLAY_CS, DISPLAY_DC, -1};
SdFat32 _sd;
void setup()
{
// Deselect all SPI devices before initialization
pinMode(DISPLAY_CS, OUTPUT);
pinMode(SD_CS, OUTPUT);
digitalWrite(DISPLAY_CS, HIGH);
digitalWrite(SD_CS, HIGH);
Serial.begin(115200);
// Init display
_tft.initR(INITR_BLACKTAB);
_tft.setSPISpeed(1000000UL * 50); // Make sure the SPI speed is always the same
// Print something
_tft.fillScreen(ST77XX_BLACK);
_tft.setTextColor(ST77XX_WHITE);
_tft.setTextSize(3);
_tft.print(F("FOO")); // <--- Is displayed.
// Just a test, doesnt make a difference.
digitalWrite(DISPLAY_CS, HIGH);
digitalWrite(SD_CS, HIGH);
delay(2000);
// Init SD
if (!_sd.begin(SD_CS, 1000000UL * 50)) // <--- TFT goes blank (white backlight)
_sd.initErrorHalt(&Serial);
// This hack works, but that's ugly and the TFT still flickers.
//_tft.initR(INITR_BLACKTAB);
// Print again
_tft.fillScreen(ST77XX_BLACK);
_tft.print(F("BAR")); // <--- Still blank, not displayed.
Serial.println("I'm alive!"); // Code didn't crash.
}
void loop() {}
I think that the sd.begin() causes the display to receive some wrong data that causes it to go blank. But I don’t undestand, why this can happen, because it’s unselected, when sd.begin is called.
When I remove the sd from the slot, this issue doesn’t occur and the display stays on.
Do you have an idea, what could be causing this behaviour?
Thanks in advance!