DS3231 and Mcufriend 3.5" tft

I am using the following two modules:

Mcufriend 3.5" TFT (Hooked directly on top of an Uno)
DS3231

The issue I have seems be a strange one - the display only shows the text when I have commented the following line:

 dt = clock.getDateTime();

As soon as it’s uncommented the display goes all white and won’t display anything

I tried putting the line elsewhere in loop but I still get the same >:( …

/*
/*
  DS3231: Real-Time Clock. Simple example
  Read more: www.jarzebski.pl/arduino/komponenty/zegar-czasu-rzeczywistego-rtc-ds3231.html
  GIT: https://github.com/jarzebski/Arduino-DS3231
  Web: http://www.jarzebski.pl
  (c) 2014 by Korneliusz Jarzebski
*/
#include <SPI.h>               // spi interface library for TFT
#include <Adafruit_GFX.h>      // tft display hardware-specific library
#include <MCUFRIEND_kbv.h>     // tft display hardware-specific library
 MCUFRIEND_kbv tft;
#include <Wire.h>
#include <DS3231.h>

 
#include "Sodaq_DS3231.h" //Available in regular IDE Libraries section
DS3231 clock;
RTCDateTime dt;
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
//   D0 connects to digital pin 8  (Notice these are
//   D1 connects to digital pin 9   NOT in order!)
//   D2 connects to digital pin 2
//   D3 connects to digital pin 3
//   D4 connects to digital pin 4
//   D5 connects to digital pin 5
//   D6 connects to digital pin 6
//   D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).

// Assign human-readable names to some common 16-bit color values:
#define LTBLUE    0xB6DF
#define LTTEAL    0xBF5F
#define LTGREEN   0xBFF7
#define LTCYAN    0xC7FF
#define LTRED     0xFD34
#define LTMAGENTA 0xFD5F
#define LTYELLOW  0xFFF8
#define LTORANGE  0xFE73
#define LTPINK    0xFDDF
#define LTPURPLE  0xCCFF
#define LTGREY    0xE71C

#define BLUE      0x001F
#define TEAL      0x0438
#define GREEN     0x07E0
#define CYAN      0x07FF
#define RED       0xF800
#define MAGENTA   0xF81F
#define YELLOW    0xFFE0
#define ORANGE    0xFC00
#define PINK      0xF81F
#define PURPLE    0x8010
#define GREY      0xC618
#define WHITE     0xFFFF
#define BLACK     0x0000

#define DKBLUE    0x000D
#define DKTEAL    0x020C
#define DKGREEN   0x03E0
#define DKCYAN    0x03EF
#define DKRED     0x6000
#define DKMAGENTA 0x8008
#define DKYELLOW  0x8400
#define DKORANGE  0x8200
#define DKPINK    0x9009
#define DKPURPLE  0x4010
#define DKGREY    0x4A49
  int cursorx=0;                 // cursor positioning x coordinate
  int cursory=0;                 // cursor positioning y coordinate
  double x, y;

boolean display7 = true;
void setup()
{
   uint16_t g_identifier;
  Serial.begin(9600);

  // Initialize DS3231
  Serial.println("Initialize DS3231");;
  clock.begin();

  // Set sketch compiling time
  clock.setDateTime(__DATE__, __TIME__);
  
   g_identifier = 0x9481;  // this if for the 3.5 inch display ILI9341 controller
   tft.begin(g_identifier);

}

void loop()
{

  tft.setRotation(3);

  // For leading zero look to DS3231_dateformat example
  
//  dt = clock.getDateTime(); //get the current date-time

  tft.fillScreen(BLACK);
  tft.setCursor(0,0);
  tft.setTextColor(WHITE);  tft.setTextSize(2);
  tft.print("Raw data: ");
  tft.print(dt.year);   tft.print("-");
  tft.print(dt.month);  tft.print("-");
  tft.print(dt.day);    tft.print(" ");
  tft.print(dt.hour);   tft.print(":");
  tft.print(dt.minute); tft.print(":");
  tft.print(dt.second); tft.println("");

  delay(1000);
}

The DS3231 is I2C which can be using A4 and A5. Which Arduino are you using?

I'm using an uno r3 and don't believe it's a connection issue as the board has multiple sca and scl pins.

If you meant sda and scl Pins then I agree with you that the R3 has two of each. That doesn't mean anything more than you could easily attach two different wires to the same pin of the ATMEGA328P chip which is the processor used in the R3.

In the ATMEGA, analog A4 and SDA mean the same thing. A5 and SCL mean the same thing.

What concerns me is that you are defining :

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

and then later using the wire library to send commands to the DS3231 via I2C. The way I see it, reading/writing to/from the I2C bus is rapidly writing 0 and 1 to what you have defined and presumably attached to the LCD to cause a reset.

Thus, in my humble opinion, as you stated, as soon as you use the I2C bus (dt = clock.getDateTime();), "the display goes all white and won't display anything" because you have reset the LCD by using the I2C bus.

If you disconnect that LCD_RESET from A4, I bet that using the DS3231 will no longer cause the Display to blank.

The problem is well described in post #3.
Here is the display in your description:

and indeed the screen reset is physically connected to A4 which is required for the I2C bus.

Look at #3 here Pin conflict with TFT and I2C comms - Displays - Arduino Forum but read the whole thread before cutting pins. Maybe also search for similar threads.

Karma added. Thank you all for the response but I think I'm better off with a better display or just taking out ds3231 out of the equation. Disconnecting LCD_RST from A4 didn't seem to do anything but it was worth a try.

Re-routeing the LCD_RESET pin away from A4 should be fine. Make sure that you call Wire.begin() after tft.begin(). The library is still going to wiggle A4 (which it thinks is connected to LCD_RESET pin) when it first starts up.

The alternative is to use an Arduino with separate I2C pins. Or use an RTC with SPI interface.

David.