Pinging DS3231 to skip possible error

Greetings everyone!

I have a project that uses the DS3231 RTC and I know that if I disconnect the module, my program won't even get past the RTC's constructor and will stay there until I connect it, which is logical. However, I would like to skip that "hanging" if the RTC has an error or something, so my program can continue without it.

Something like error catching. So I used the Wire library to do this job, but with no success so far. I also use the wonderful DS3231 library from Mr. Karlsen.

In the small part of the code I wrote below, I have the module connected, but I still want to check if everything's fine, like pinging the device.

void Graphics::InitializeRTC() const
{
	Wire.beginTransmission(104);
	byte connection = Wire.endTransmission();

	myGLCD.setColor(255, 255, 255);
	myGLCD.setBackColor(0, 0, 0);
	myGLCD.setFont(SmallFont);
	if (connection1 == 0)
	{
		myGLCD.print("CLOCK IS THERE", CENTER, 150);
	}
	else
	{
		myGLCD.print("NO CLOCK", CENTER, 150);
		return;
	}

    rtc.begin();
	
    currentTemperature = rtc.getTemp();
    currentDate = rtc.getDateStr();
    currentClock = rtc.getTimeStr();
    timeString = rtc.getTimeStr();
    currentHours = timeString.substring(0, 2);
    currentMinutes = timeString.substring(3, 5);
    currentSeconds = timeString.substring(6, 8);
}

So I transmit at address 104 which is 0x68 of the RTC module. But the answer I receive is always != 0 and therefore I always get the message "NO CLOCK", even though the clock is up and running. Is there any other way to ping the device so I can catch any errors and prevent my program from getting stuck? Thank you for your time.

Try adding external pullup resistors (say 4.7k) to the i2c connections so the lines are pulled up even if the rtc is missing.

6v6gt:
Try adding external pullup resistors (say 4.7k) to the i2c connections so the lines are pulled up even if the rtc is missing.

Same result unfortunately. I'm using a MEGA board and the right pins (20 & 21). I guess that it has to be a code problem...but no solution comes to mind...

The thing is, if I use the I2C scanner code, it gets a response from the clock, even if I use the scanner in the program I'm running.

SauROnmiKE:
I guess that it has to be a code problem...but no solution comes to mind...

Well that's embarrassing...I don't often use the Wire library and I didn't call Wire.begin();
You learn by your mistakes...thank you for your time.